treequel 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/ChangeLog +354 -0
  2. data/LICENSE +27 -0
  3. data/README +66 -0
  4. data/Rakefile +345 -0
  5. data/Rakefile.local +43 -0
  6. data/bin/treeirb +14 -0
  7. data/bin/treequel +229 -0
  8. data/examples/company-directory.rb +112 -0
  9. data/examples/ldap-monitor.rb +143 -0
  10. data/examples/ldap-monitor/public/css/master.css +328 -0
  11. data/examples/ldap-monitor/public/images/card_small.png +0 -0
  12. data/examples/ldap-monitor/public/images/chain_small.png +0 -0
  13. data/examples/ldap-monitor/public/images/globe_small.png +0 -0
  14. data/examples/ldap-monitor/public/images/globe_small_green.png +0 -0
  15. data/examples/ldap-monitor/public/images/plug.png +0 -0
  16. data/examples/ldap-monitor/public/images/shadows/large-30-down.png +0 -0
  17. data/examples/ldap-monitor/public/images/tick.png +0 -0
  18. data/examples/ldap-monitor/public/images/tick_circle.png +0 -0
  19. data/examples/ldap-monitor/public/images/treequel-favicon.png +0 -0
  20. data/examples/ldap-monitor/views/backends.erb +41 -0
  21. data/examples/ldap-monitor/views/connections.erb +74 -0
  22. data/examples/ldap-monitor/views/databases.erb +39 -0
  23. data/examples/ldap-monitor/views/dump_subsystem.erb +14 -0
  24. data/examples/ldap-monitor/views/index.erb +14 -0
  25. data/examples/ldap-monitor/views/layout.erb +35 -0
  26. data/examples/ldap-monitor/views/listeners.erb +30 -0
  27. data/examples/ldap_state.rb +62 -0
  28. data/lib/treequel.rb +145 -0
  29. data/lib/treequel/branch.rb +589 -0
  30. data/lib/treequel/branchcollection.rb +204 -0
  31. data/lib/treequel/branchset.rb +360 -0
  32. data/lib/treequel/constants.rb +604 -0
  33. data/lib/treequel/directory.rb +541 -0
  34. data/lib/treequel/exceptions.rb +32 -0
  35. data/lib/treequel/filter.rb +704 -0
  36. data/lib/treequel/mixins.rb +325 -0
  37. data/lib/treequel/schema.rb +245 -0
  38. data/lib/treequel/schema/attributetype.rb +252 -0
  39. data/lib/treequel/schema/ldapsyntax.rb +96 -0
  40. data/lib/treequel/schema/matchingrule.rb +124 -0
  41. data/lib/treequel/schema/matchingruleuse.rb +124 -0
  42. data/lib/treequel/schema/objectclass.rb +289 -0
  43. data/lib/treequel/sequel_integration.rb +26 -0
  44. data/lib/treequel/utils.rb +169 -0
  45. data/rake/191_compat.rb +26 -0
  46. data/rake/dependencies.rb +76 -0
  47. data/rake/helpers.rb +434 -0
  48. data/rake/hg.rb +261 -0
  49. data/rake/manual.rb +782 -0
  50. data/rake/packaging.rb +135 -0
  51. data/rake/publishing.rb +318 -0
  52. data/rake/rdoc.rb +30 -0
  53. data/rake/style.rb +62 -0
  54. data/rake/svn.rb +668 -0
  55. data/rake/testing.rb +187 -0
  56. data/rake/verifytask.rb +64 -0
  57. data/rake/win32.rb +190 -0
  58. data/spec/lib/constants.rb +93 -0
  59. data/spec/lib/helpers.rb +100 -0
  60. data/spec/treequel/branch_spec.rb +569 -0
  61. data/spec/treequel/branchcollection_spec.rb +213 -0
  62. data/spec/treequel/branchset_spec.rb +376 -0
  63. data/spec/treequel/directory_spec.rb +487 -0
  64. data/spec/treequel/filter_spec.rb +482 -0
  65. data/spec/treequel/mixins_spec.rb +330 -0
  66. data/spec/treequel/schema/attributetype_spec.rb +237 -0
  67. data/spec/treequel/schema/ldapsyntax_spec.rb +83 -0
  68. data/spec/treequel/schema/matchingrule_spec.rb +158 -0
  69. data/spec/treequel/schema/matchingruleuse_spec.rb +137 -0
  70. data/spec/treequel/schema/objectclass_spec.rb +262 -0
  71. data/spec/treequel/schema_spec.rb +118 -0
  72. data/spec/treequel/utils_spec.rb +49 -0
  73. data/spec/treequel_spec.rb +179 -0
  74. metadata +169 -0
@@ -0,0 +1,213 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
10
+ }
11
+
12
+ begin
13
+ require 'spec'
14
+ require 'spec/lib/constants'
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'treequel/branchcollection'
18
+ rescue LoadError
19
+ unless Object.const_defined?( :Gem )
20
+ require 'rubygems'
21
+ retry
22
+ end
23
+ raise
24
+ end
25
+
26
+
27
+ include Treequel::TestConstants
28
+
29
+ #####################################################################
30
+ ### C O N T E X T S
31
+ #####################################################################
32
+
33
+ describe Treequel::BranchCollection do
34
+ include Treequel::SpecHelpers
35
+
36
+ before( :all ) do
37
+ setup_logging( :debug )
38
+ end
39
+
40
+ after( :all ) do
41
+ reset_logging()
42
+ end
43
+
44
+ before( :each ) do
45
+ @directory = mock( "treequel directory ")
46
+ end
47
+
48
+ it "can be instantiated without any branchsets" do
49
+ collection = Treequel::BranchCollection.new
50
+ collection.all.should == []
51
+ end
52
+
53
+ it "can be instantiated with one or more branchsets" do
54
+ branchset1 = stub( "branchset 1", :dn => 'cn=example1,dc=acme,dc=com', :each => 1 )
55
+ branchset2 = stub( "branchset 2", :dn => 'cn=example2,dc=acme,dc=com', :each => 1 )
56
+
57
+ collection = Treequel::BranchCollection.new( branchset1, branchset2 )
58
+
59
+ collection.branchsets.should include( branchset1, branchset2 )
60
+ end
61
+
62
+ it "wraps any object that doesn't have an #each in a Branchset" do
63
+ non_branchset1 = stub( "non-branchset 1" )
64
+ non_branchset2 = stub( "non-branchset 2" )
65
+ branchset1 = stub( "branchset 1", :dn => 'cn=example1,dc=acme,dc=com' )
66
+ branchset2 = stub( "branchset 2", :dn => 'cn=example2,dc=acme,dc=com' )
67
+
68
+ Treequel::Branchset.should_receive( :new ).with( non_branchset1 ).
69
+ and_return( branchset1 )
70
+ Treequel::Branchset.should_receive( :new ).with( non_branchset2 ).
71
+ and_return( branchset2 )
72
+
73
+ collection = Treequel::BranchCollection.new( non_branchset1, non_branchset2 )
74
+
75
+ collection.branchsets.should include( branchset1, branchset2 )
76
+ end
77
+
78
+ it "allows new Branchsets to be appended to it" do
79
+ branchset1 = mock( "branchset 1" )
80
+ branchset2 = mock( "branchset 2" )
81
+
82
+ collection = Treequel::BranchCollection.new
83
+ collection << branchset1 << branchset2
84
+
85
+ collection.should include( branchset1, branchset2 )
86
+ end
87
+
88
+ it "allows new Branches to be appended to it" do
89
+ branch1 = mock( "branch 1", :branchset => :branchset1 )
90
+ branch2 = mock( "branch 2", :branchset => :branchset2 )
91
+
92
+ collection = Treequel::BranchCollection.new
93
+ collection << branch1 << branch2
94
+
95
+ collection.should include( :branchset1, :branchset2 )
96
+ end
97
+
98
+
99
+ describe "instance with two Branchsets" do
100
+
101
+ before( :each ) do
102
+ @branchset1 = mock( "branchset 1", :dn => 'cn=example1,dc=acme,dc=com', :each => 1 )
103
+ @branchset2 = mock( "branchset 2", :dn => 'cn=example2,dc=acme,dc=com', :each => 1 )
104
+
105
+ @collection = Treequel::BranchCollection.new( @branchset1, @branchset2 )
106
+ end
107
+
108
+ it "fetches all of the results from each of its branchsets if asked for all results" do
109
+ @branchset1.should_receive( :each ).and_yield( :bs1_stuff )
110
+ @branchset2.should_receive( :each ).and_yield( :bs2_stuff )
111
+
112
+ @collection.all.should == [ :bs1_stuff, :bs2_stuff ]
113
+ end
114
+
115
+ it "fetches the first Branch returned by any of its branchsets when asked" do
116
+ @branchset1.should_receive( :first ).and_return( nil )
117
+ @branchset2.should_receive( :first ).and_return( :a_branch )
118
+
119
+ @collection.first.should == :a_branch
120
+ end
121
+
122
+ it "returns a clone of itself with an additional Branchset if a Branchset is added to it" do
123
+ branchset3 = mock( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
124
+ new_collection = @collection + branchset3
125
+
126
+ new_collection.should be_an_instance_of( Treequel::BranchCollection )
127
+ new_collection.should include( @branchset1, @branchset2, branchset3 )
128
+ end
129
+
130
+ it "returns a clone of itself with an additional Branchset if a Branch is added to it" do
131
+ branchset3 = mock( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
132
+ branch3 = mock( "branch 3", :branchset => branchset3 )
133
+ new_collection = @collection + branch3
134
+
135
+ new_collection.should be_an_instance_of( Treequel::BranchCollection )
136
+ new_collection.should include( @branchset1, @branchset2, branchset3 )
137
+ end
138
+
139
+ it "returns a clone of itself with both collections' Branchsets if a BranchCollection is " +
140
+ "added to it" do
141
+ branchset3 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
142
+ branchset4 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
143
+ other_collection = Treequel::BranchCollection.new( branchset3, branchset4 )
144
+
145
+ new_collection = @collection + other_collection
146
+
147
+ new_collection.should be_an_instance_of( Treequel::BranchCollection )
148
+ new_collection.should include( @branchset1, @branchset2, branchset3, branchset4 )
149
+ end
150
+
151
+ it "returns a new BranchCollection with the union of Branchsets if it is ORed with " +
152
+ "another BranchCollection" do
153
+ branchset3 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
154
+ branchset4 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
155
+ other_collection = Treequel::BranchCollection.new( branchset3, branchset4 )
156
+
157
+ new_collection = @collection | other_collection
158
+
159
+ new_collection.should be_an_instance_of( Treequel::BranchCollection )
160
+ new_collection.should include( @branchset1, @branchset2, branchset3, branchset4 )
161
+ end
162
+
163
+ it "returns a new BranchCollection with the intersection of Branchsets if it is ANDed with " +
164
+ "another BranchCollection" do
165
+ branchset3 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
166
+ branchset4 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
167
+ other_collection = Treequel::BranchCollection.new( @branchset2, branchset3, branchset4 )
168
+ @collection << branchset4
169
+
170
+ new_collection = @collection & other_collection
171
+
172
+ new_collection.should be_an_instance_of( Treequel::BranchCollection )
173
+ new_collection.should include( @branchset2, branchset4 )
174
+ end
175
+
176
+ it "can create a clone of itself with filtered branchsets" do
177
+ filtered_branchset1 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
178
+ filtered_branchset2 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
179
+ @branchset1.should_receive( :filter ).with( :cn => 'chunkalicious' ).
180
+ and_return( filtered_branchset1 )
181
+ @branchset2.should_receive( :filter ).with( :cn => 'chunkalicious' ).
182
+ and_return( filtered_branchset2 )
183
+
184
+ filtered_collection = @collection.filter( :cn => 'chunkalicious' )
185
+ filtered_collection.should_not be_equal( @collection )
186
+ filtered_collection.should include( filtered_branchset1, filtered_branchset2 )
187
+ end
188
+
189
+ # it "can create a clone of itself with ordered branchsets" do
190
+ # ordered_branchset1 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
191
+ # ordered_branchset2 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
192
+ # @branchset1.should_receive( :order ).with( :cn ).
193
+ # and_return( ordered_branchset1 )
194
+ # @branchset2.should_receive( :order ).with( :cn ).
195
+ # and_return( ordered_branchset2 )
196
+ #
197
+ # ordered_collection = @collection.order( :cn )
198
+ # ordered_collection.should_not be_equal( @collection )
199
+ # ordered_collection.should include( ordered_branchset1, ordered_branchset2 )
200
+ # end
201
+ #
202
+ it "can return the base DNs of all of its branchsets" do
203
+ @branchset1.should_receive( :base_dn ).and_return( :branchset1_basedn )
204
+ @branchset2.should_receive( :base_dn ).and_return( :branchset2_basedn )
205
+ @collection.base_dns.should == [ :branchset1_basedn, :branchset2_basedn ]
206
+ end
207
+
208
+ end
209
+
210
+ end
211
+
212
+
213
+ # vim: set nosta noet ts=4 sw=4:
@@ -0,0 +1,376 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ BEGIN {
4
+ require 'pathname'
5
+ basedir = Pathname.new( __FILE__ ).dirname.parent.parent
6
+
7
+ libdir = basedir + "lib"
8
+
9
+ $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
10
+ }
11
+
12
+ begin
13
+ require 'spec'
14
+ require 'spec/lib/constants'
15
+ require 'spec/lib/helpers'
16
+
17
+ require 'treequel/branchset'
18
+ rescue LoadError
19
+ unless Object.const_defined?( :Gem )
20
+ require 'rubygems'
21
+ retry
22
+ end
23
+ raise
24
+ end
25
+
26
+
27
+ include Treequel::TestConstants
28
+ include Treequel::Constants
29
+
30
+ #####################################################################
31
+ ### C O N T E X T S
32
+ #####################################################################
33
+
34
+ describe Treequel::Branchset do
35
+ include Treequel::SpecHelpers
36
+
37
+ class << self
38
+ alias_method :they, :it
39
+ end
40
+
41
+ DEFAULT_PARAMS = {
42
+ :limit => 0,
43
+ :selectattrs => [],
44
+ :timeout => 0,
45
+ }
46
+
47
+ before( :all ) do
48
+ setup_logging( :fatal )
49
+ end
50
+
51
+ after( :all ) do
52
+ reset_logging()
53
+ end
54
+
55
+ before( :each ) do
56
+ @directory = mock( "treequel directory ")
57
+ @branch = mock( "treequel branch", :dn => 'thedn' )
58
+ @params = DEFAULT_PARAMS.dup
59
+ end
60
+
61
+
62
+ describe "instances" do
63
+ before( :each ) do
64
+ @branchset = Treequel::Branchset.new( @branch )
65
+ end
66
+
67
+ they "are Enumerable" do
68
+ resultbranch = mock( "Result Branch" )
69
+
70
+ @branch.should_receive( :directory ).and_return( @directory )
71
+ @directory.should_receive( :search ).
72
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
73
+ and_yield( resultbranch )
74
+ resultbranch.should_receive( :dn ).and_return( :its_dn )
75
+
76
+ @branchset.all? {|b| b.dn }
77
+ end
78
+
79
+ #
80
+ # #map
81
+ #
82
+ they "can be mapped into an Array of attribute values" do
83
+ resultbranch = mock( "Result Branch" )
84
+ resultbranch2 = mock( "Result Branch 2" )
85
+
86
+ @branch.should_receive( :directory ).and_return( @directory )
87
+ @directory.should_receive( :search ).
88
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
89
+ and_yield( resultbranch ).and_yield( resultbranch2 )
90
+ resultbranch.should_receive( :[] ).with( :cn ).and_return([ :first_cn ])
91
+ resultbranch2.should_receive( :[] ).with( :cn ).and_return([ :second_cn ])
92
+
93
+ @branchset.map( :cn ).should == [[:first_cn], [:second_cn]]
94
+ end
95
+
96
+
97
+ #
98
+ # #to_hash
99
+ #
100
+ they "can be mapped into a Hash of entries keyed by one of their attributes" do
101
+ resultbranch = mock( "Result Branch" )
102
+ resultbranch2 = mock( "Result Branch 2" )
103
+
104
+ @branch.should_receive( :directory ).and_return( @directory )
105
+ @directory.should_receive( :search ).
106
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
107
+ and_yield( resultbranch ).and_yield( resultbranch2 )
108
+
109
+ resultbranch.should_receive( :[] ).with( :email ).
110
+ and_return([ :first_email ])
111
+ resultbranch.should_receive( :entry ).and_return( :entry1 )
112
+ resultbranch2.should_receive( :[] ).with( :email ).
113
+ and_return([ :second_email, :second_second_email ])
114
+ resultbranch2.should_receive( :entry ).and_return( :entry2 )
115
+
116
+ @branchset.to_hash( :email ).should == {
117
+ :first_email => :entry1,
118
+ :second_email => :entry2,
119
+ }
120
+ end
121
+
122
+
123
+ they "can be mapped into a Hash of tuples using two attributes" do
124
+ resultbranch = mock( "Result Branch" )
125
+ resultbranch2 = mock( "Result Branch 2" )
126
+
127
+ @branch.should_receive( :directory ).and_return( @directory )
128
+ @directory.should_receive( :search ).
129
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
130
+ and_yield( resultbranch ).and_yield( resultbranch2 )
131
+
132
+ resultbranch.should_receive( :[] ).with( :email ).
133
+ and_return([ :first_email ])
134
+ resultbranch.should_receive( :[] ).with( :cn ).
135
+ and_return([ :first_cn ])
136
+ resultbranch2.should_receive( :[] ).with( :email ).
137
+ and_return([ :second_email, :second_second_email ])
138
+ resultbranch2.should_receive( :[] ).with( :cn ).
139
+ and_return([ :second_cn, :second_second_cn ])
140
+
141
+ @branchset.to_hash( :email, :cn ).should == {
142
+ :first_email => :first_cn,
143
+ :second_email => :second_cn,
144
+ }
145
+ end
146
+ end
147
+
148
+ describe "instance with no filter, options, or scope set" do
149
+
150
+ before( :each ) do
151
+ @branchset = Treequel::Branchset.new( @branch )
152
+ end
153
+
154
+ it "can clone itself with merged options" do
155
+ newset = @branchset.clone( :scope => :one )
156
+ newset.should be_a( Treequel::Branchset )
157
+ newset.should_not equal( @branchset )
158
+ newset.options.should_not equal( @branchset.options )
159
+ newset.scope.should == :one
160
+ end
161
+
162
+
163
+ #
164
+ # #filter
165
+ #
166
+
167
+ it "generates a valid filter string" do
168
+ @branchset.filter_string.should == '(objectClass=*)'
169
+ end
170
+
171
+
172
+ it "performs a search using the default filter and scope when all records are requested" do
173
+ @branch.should_receive( :directory ).and_return( @directory )
174
+ @directory.should_receive( :search ).
175
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
176
+ and_yield( :matching_branches )
177
+
178
+ @branchset.all.should == [ :matching_branches ]
179
+ end
180
+
181
+ it "performs a search using the default filter, scope, and a limit of 1 when the first " +
182
+ "record is requested" do
183
+ @branch.should_receive( :directory ).and_return( @directory )
184
+ @directory.should_receive( :search ).
185
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
186
+ @params.merge(:limit => 1) ).
187
+ and_return( [:first_matching_branch, :other_branches] )
188
+
189
+ @branchset.first.should == :first_matching_branch
190
+ end
191
+
192
+ it "creates a new branchset cloned from itself with the specified filter" do
193
+ newset = @branchset.filter( :clothing, 'pants' )
194
+ newset.filter_string.should == '(clothing=pants)'
195
+ end
196
+
197
+ #
198
+ # #scope
199
+ #
200
+
201
+ it "provides a reader for its scope" do
202
+ @branchset.scope.should == :subtree
203
+ end
204
+
205
+ it "can return the DN of its base" do
206
+ @branch.should_receive( :dn ).and_return( :foo )
207
+ @branchset.base_dn.should == :foo
208
+ end
209
+
210
+ it "can create a new branchset cloned from itself with a different scope" do
211
+ newset = @branchset.scope( :onelevel )
212
+ newset.should be_a( Treequel::Branchset )
213
+ newset.should_not equal( @branchset )
214
+ newset.options.should_not equal( @branchset.options )
215
+ newset.scope.should == :onelevel
216
+ end
217
+
218
+ it "can create a new branchset cloned from itself with a different string scope" do
219
+ newset = @branchset.scope( 'sub' )
220
+ newset.scope.should == :sub
221
+ end
222
+
223
+ it "uses its scope setting as the scope to use when searching" do
224
+ @branchset.options[:scope] = :onelevel
225
+ @branch.should_receive( :directory ).and_return( @directory )
226
+ @directory.should_receive( :search ).
227
+ with( @branch, :onelevel, @branchset.filter, @params ).
228
+ and_yield( :matching_branches )
229
+
230
+ @branchset.all.should == [:matching_branches]
231
+ end
232
+
233
+ #
234
+ # #select
235
+ #
236
+ it "can create a new branchset cloned from itself with an attribute selection" do
237
+ newset = @branchset.select( :l, :lastName, :disabled )
238
+ newset.select.should == [ 'l', 'lastName', 'disabled' ]
239
+ end
240
+
241
+ it "can create a new branchset cloned from itself with all attributes selected" do
242
+ newset = @branchset.select_all
243
+ newset.select.should == []
244
+ end
245
+
246
+ it "can create a new branchset cloned from itself with additional attributes selected" do
247
+ @branchset.options[:select] = [ :l, :cn, :uid ]
248
+ newset = @branchset.select_more( :firstName, :uid, :lastName )
249
+ newset.select.should == [ 'l', 'cn', 'uid', 'firstName', 'lastName' ]
250
+ end
251
+
252
+ it "uses its selection as the list of attributes to fetch when searching" do
253
+ @branchset.options[:select] = [ :l, :cn, :uid ]
254
+ @branch.should_receive( :directory ).and_return( @directory )
255
+ @directory.should_receive( :search ).
256
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
257
+ @params.merge(:selectattrs => ['l', 'cn', 'uid']) ).
258
+ and_yield( :matching_branches )
259
+
260
+ @branchset.all.should == [:matching_branches]
261
+ end
262
+
263
+ #
264
+ # #timeout
265
+ #
266
+
267
+ it "can create a new branchset cloned from itself with a timeout" do
268
+ newset = @branchset.timeout( 30 )
269
+ newset.timeout.should == 30.0
270
+ end
271
+
272
+ it "can create a new branchset cloned from itself without a timeout" do
273
+ @branchset.options[:timeout] = 5.375
274
+ newset = @branchset.without_timeout
275
+ newset.timeout.should == 0
276
+ end
277
+
278
+ it "uses its timeout as the timeout values when searching" do
279
+ @branchset.options[:timeout] = 5.375
280
+ @branch.should_receive( :directory ).and_return( @directory )
281
+ @directory.should_receive( :search ).
282
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
283
+ @params.merge(:timeout => 5.375) ).
284
+ and_yield( :matching_branches )
285
+
286
+ @branchset.all.should == [:matching_branches]
287
+ end
288
+
289
+ #
290
+ # #order
291
+ #
292
+
293
+ # it "can create a new branchset cloned from itself with a sort-order attribute" do
294
+ # newset = @branchset.order( :uid )
295
+ # newset.order.should == :uid
296
+ # end
297
+ #
298
+ # it "converts a string sort-order attribute to a Symbol" do
299
+ # newset = @branchset.order( 'uid' )
300
+ # newset.order.should == :uid
301
+ # end
302
+ #
303
+ # it "can set a sorting function instead of an attribute" do
304
+ # newset = @branchset.order {|branch| branch.uid }
305
+ # newset.order.should be_a( Proc )
306
+ # end
307
+ #
308
+ # it "can create a new branchset cloned from itself without a sort-order attribute" do
309
+ # @branchset.options[:order] = :uid
310
+ # newset = @branchset.order( nil )
311
+ # newset.order.should == nil
312
+ # end
313
+ #
314
+ # it "uses its order attribute list when searching" do
315
+ # @branchset.options[:order] = [ :uid ]
316
+ # @branch.should_receive( :directory ).and_return( @directory )
317
+ # @directory.should_receive( :search ).
318
+ # with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
319
+ # @params.merge(:sortby => ['uid']) ).
320
+ # and_yield( :matching_branches )
321
+ #
322
+ # @branchset.all.should == [:matching_branches]
323
+ # end
324
+
325
+ #
326
+ # #limit
327
+ #
328
+ it "can create a new branchset cloned from itself with a limit attribute" do
329
+ newset = @branchset.limit( 5 )
330
+ newset.limit.should == 5
331
+ end
332
+
333
+ it "can create a new branchset cloned from itself without a limit" do
334
+ newset = @branchset.without_limit
335
+ newset.limit.should == 0
336
+ end
337
+
338
+ it "uses its limit as the limit when searching" do
339
+ @branchset.options[:limit] = 8
340
+ @branch.should_receive( :directory ).and_return( @directory )
341
+ @directory.should_receive( :search ).
342
+ with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
343
+ @params.merge(:limit => 8) ).
344
+ and_yield( :matching_branches )
345
+
346
+ @branchset.all.should == [:matching_branches]
347
+ end
348
+
349
+ end
350
+
351
+ describe "instance with no filter, and scope set to 'onelevel'" do
352
+
353
+ before( :each ) do
354
+ @branchset = Treequel::Branchset.new( @branch, :scope => :onelevel )
355
+ end
356
+
357
+
358
+ it "generates a valid filter string" do
359
+ @branchset.filter_string.should == '(objectClass=*)'
360
+ end
361
+
362
+ it "performs a search using the default filter and scope when all records are requested" do
363
+ @branch.should_receive( :directory ).and_return( @directory )
364
+ @directory.should_receive( :search ).
365
+ with( @branch, :onelevel, @branchset.filter, @params ).
366
+ and_yield( :matching_branches )
367
+
368
+ @branchset.all.should == [:matching_branches]
369
+ end
370
+
371
+ end
372
+
373
+ end
374
+
375
+
376
+ # vim: set nosta noet ts=4 sw=4: