treequel 1.0.1 → 1.0.4

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 (73) hide show
  1. data/ChangeLog +176 -14
  2. data/LICENSE +1 -1
  3. data/Rakefile +61 -45
  4. data/Rakefile.local +20 -0
  5. data/bin/treequel +502 -269
  6. data/examples/ldap-rack-auth.rb +2 -0
  7. data/lib/treequel.rb +221 -18
  8. data/lib/treequel/branch.rb +410 -201
  9. data/lib/treequel/branchcollection.rb +25 -13
  10. data/lib/treequel/branchset.rb +42 -40
  11. data/lib/treequel/constants.rb +233 -3
  12. data/lib/treequel/control.rb +95 -0
  13. data/lib/treequel/controls/contentsync.rb +138 -0
  14. data/lib/treequel/controls/pagedresults.rb +162 -0
  15. data/lib/treequel/controls/sortedresults.rb +216 -0
  16. data/lib/treequel/directory.rb +212 -65
  17. data/lib/treequel/exceptions.rb +11 -12
  18. data/lib/treequel/filter.rb +1 -12
  19. data/lib/treequel/mixins.rb +83 -47
  20. data/lib/treequel/monkeypatches.rb +29 -0
  21. data/lib/treequel/schema.rb +23 -19
  22. data/lib/treequel/schema/attributetype.rb +33 -3
  23. data/lib/treequel/schema/ldapsyntax.rb +0 -11
  24. data/lib/treequel/schema/matchingrule.rb +0 -11
  25. data/lib/treequel/schema/matchingruleuse.rb +0 -11
  26. data/lib/treequel/schema/objectclass.rb +36 -10
  27. data/lib/treequel/schema/table.rb +159 -0
  28. data/lib/treequel/sequel_integration.rb +7 -7
  29. data/lib/treequel/utils.rb +4 -66
  30. data/rake/documentation.rb +89 -0
  31. data/rake/helpers.rb +375 -307
  32. data/rake/hg.rb +16 -2
  33. data/rake/manual.rb +11 -6
  34. data/rake/packaging.rb +20 -35
  35. data/rake/publishing.rb +22 -62
  36. data/spec/lib/constants.rb +20 -0
  37. data/spec/lib/control_behavior.rb +44 -0
  38. data/spec/lib/matchers.rb +51 -0
  39. data/spec/treequel/branch_spec.rb +88 -29
  40. data/spec/treequel/branchcollection_spec.rb +24 -1
  41. data/spec/treequel/branchset_spec.rb +123 -51
  42. data/spec/treequel/control_spec.rb +48 -0
  43. data/spec/treequel/controls/contentsync_spec.rb +38 -0
  44. data/spec/treequel/controls/pagedresults_spec.rb +138 -0
  45. data/spec/treequel/controls/sortedresults_spec.rb +171 -0
  46. data/spec/treequel/directory_spec.rb +186 -16
  47. data/spec/treequel/mixins_spec.rb +42 -3
  48. data/spec/treequel/schema/attributetype_spec.rb +22 -20
  49. data/spec/treequel/schema/objectclass_spec.rb +67 -46
  50. data/spec/treequel/schema/table_spec.rb +134 -0
  51. data/spec/treequel_spec.rb +277 -15
  52. metadata +89 -108
  53. data/bin/treequel.orig +0 -963
  54. data/examples/ldap-monitor.rb +0 -143
  55. data/examples/ldap-monitor/public/css/master.css +0 -328
  56. data/examples/ldap-monitor/public/images/card_small.png +0 -0
  57. data/examples/ldap-monitor/public/images/chain_small.png +0 -0
  58. data/examples/ldap-monitor/public/images/globe_small.png +0 -0
  59. data/examples/ldap-monitor/public/images/globe_small_green.png +0 -0
  60. data/examples/ldap-monitor/public/images/plug.png +0 -0
  61. data/examples/ldap-monitor/public/images/shadows/large-30-down.png +0 -0
  62. data/examples/ldap-monitor/public/images/tick.png +0 -0
  63. data/examples/ldap-monitor/public/images/tick_circle.png +0 -0
  64. data/examples/ldap-monitor/public/images/treequel-favicon.png +0 -0
  65. data/examples/ldap-monitor/views/backends.erb +0 -41
  66. data/examples/ldap-monitor/views/connections.erb +0 -74
  67. data/examples/ldap-monitor/views/databases.erb +0 -39
  68. data/examples/ldap-monitor/views/dump_subsystem.erb +0 -14
  69. data/examples/ldap-monitor/views/index.erb +0 -14
  70. data/examples/ldap-monitor/views/layout.erb +0 -35
  71. data/examples/ldap-monitor/views/listeners.erb +0 -30
  72. data/rake/rdoc.rb +0 -30
  73. data/rake/win32.rb +0 -190
@@ -34,7 +34,7 @@ describe Treequel::BranchCollection do
34
34
  include Treequel::SpecHelpers
35
35
 
36
36
  before( :all ) do
37
- setup_logging( :debug )
37
+ setup_logging( :fatal )
38
38
  end
39
39
 
40
40
  after( :all ) do
@@ -105,6 +105,20 @@ describe Treequel::BranchCollection do
105
105
  @collection = Treequel::BranchCollection.new( @branchset1, @branchset2 )
106
106
  end
107
107
 
108
+ it "knows that it is empty if all of its branchsets are empty" do
109
+ @branchset1.should_receive( :empty? ).and_return( true )
110
+ @branchset2.should_receive( :empty? ).and_return( true )
111
+
112
+ @collection.should be_empty()
113
+ end
114
+
115
+ it "knows that it is not empty if one of its branchsets has matching entries" do
116
+ @branchset1.should_receive( :empty? ).and_return( true )
117
+ @branchset2.should_receive( :empty? ).and_return( false )
118
+
119
+ @collection.should_not be_empty()
120
+ end
121
+
108
122
  it "fetches all of the results from each of its branchsets if asked for all results" do
109
123
  @branchset1.should_receive( :each ).and_yield( :bs1_stuff )
110
124
  @branchset2.should_receive( :each ).and_yield( :bs2_stuff )
@@ -186,6 +200,15 @@ describe Treequel::BranchCollection do
186
200
  filtered_collection.should include( filtered_branchset1, filtered_branchset2 )
187
201
  end
188
202
 
203
+ it "raises a reasonable exception if one of its delegates returns a non-branchset" do
204
+ filter = Treequel::Filter.new
205
+ @branchset1.stub!( :filter ).and_return( filter )
206
+
207
+ expect {
208
+ @collection.filter
209
+ }.to raise_exception( ArgumentError, /0 for 1/ )
210
+ end
211
+
189
212
  # it "can create a clone of itself with ordered branchsets" do
190
213
  # ordered_branchset1 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
191
214
  # ordered_branchset2 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
@@ -9,20 +9,13 @@ BEGIN {
9
9
  $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
10
10
  }
11
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
12
+ require 'spec'
13
+ require 'spec/lib/constants'
14
+ require 'spec/lib/helpers'
25
15
 
16
+ require 'treequel/branchset'
17
+ require 'treequel/branchcollection'
18
+ require 'treequel/control'
26
19
 
27
20
  include Treequel::TestConstants
28
21
  include Treequel::Constants
@@ -34,14 +27,17 @@ include Treequel::Constants
34
27
  describe Treequel::Branchset do
35
28
  include Treequel::SpecHelpers
36
29
 
30
+ # Make the specs read more clearly
37
31
  class << self
38
32
  alias_method :they, :it
39
33
  end
40
34
 
41
35
  DEFAULT_PARAMS = {
42
- :limit => 0,
43
- :selectattrs => [],
44
- :timeout => 0,
36
+ :limit => 0,
37
+ :selectattrs => [],
38
+ :timeout => 0,
39
+ :client_controls => [],
40
+ :server_controls => [],
45
41
  }
46
42
 
47
43
  before( :all ) do
@@ -53,8 +49,9 @@ describe Treequel::Branchset do
53
49
  end
54
50
 
55
51
  before( :each ) do
56
- @directory = mock( "treequel directory ")
52
+ @directory = mock( "treequel directory ", :registered_controls => [] )
57
53
  @branch = mock( "treequel branch", :dn => 'thedn' )
54
+ @branch.stub!( :directory ).and_return( @directory )
58
55
  @params = DEFAULT_PARAMS.dup
59
56
  end
60
57
 
@@ -67,15 +64,35 @@ describe Treequel::Branchset do
67
64
  they "are Enumerable" do
68
65
  resultbranch = mock( "Result Branch" )
69
66
 
70
- @branch.should_receive( :directory ).and_return( @directory )
71
- @directory.should_receive( :search ).
72
- with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
67
+ @branch.should_receive( :search ).
68
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
73
69
  and_yield( resultbranch )
74
70
  resultbranch.should_receive( :dn ).and_return( :its_dn )
75
71
 
76
72
  @branchset.all? {|b| b.dn }
77
73
  end
78
74
 
75
+ #
76
+ # #empty?
77
+ #
78
+ they "know that they are empty if they don't match at least one entry" do
79
+ params = @params.merge( :limit => 1 )
80
+ @branch.should_receive( :search ).
81
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, params ).
82
+ and_return( [] )
83
+
84
+ @branchset.should be_empty()
85
+ end
86
+
87
+ they "know that they are empty if they match at least one entry" do
88
+ params = @params.merge( :limit => 1 )
89
+ @branch.should_receive( :search ).
90
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, params ).
91
+ and_return( [:a_branch] )
92
+
93
+ @branchset.should_not be_empty()
94
+ end
95
+
79
96
  #
80
97
  # #map
81
98
  #
@@ -83,9 +100,8 @@ describe Treequel::Branchset do
83
100
  resultbranch = mock( "Result Branch" )
84
101
  resultbranch2 = mock( "Result Branch 2" )
85
102
 
86
- @branch.should_receive( :directory ).and_return( @directory )
87
- @directory.should_receive( :search ).
88
- with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
103
+ @branch.should_receive( :search ).
104
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
89
105
  and_yield( resultbranch ).and_yield( resultbranch2 )
90
106
  resultbranch.should_receive( :[] ).with( :cn ).and_return([ :first_cn ])
91
107
  resultbranch2.should_receive( :[] ).with( :cn ).and_return([ :second_cn ])
@@ -101,9 +117,8 @@ describe Treequel::Branchset do
101
117
  resultbranch = mock( "Result Branch" )
102
118
  resultbranch2 = mock( "Result Branch 2" )
103
119
 
104
- @branch.should_receive( :directory ).and_return( @directory )
105
- @directory.should_receive( :search ).
106
- with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
120
+ @branch.should_receive( :search ).
121
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
107
122
  and_yield( resultbranch ).and_yield( resultbranch2 )
108
123
 
109
124
  resultbranch.should_receive( :[] ).with( :email ).
@@ -124,9 +139,8 @@ describe Treequel::Branchset do
124
139
  resultbranch = mock( "Result Branch" )
125
140
  resultbranch2 = mock( "Result Branch 2" )
126
141
 
127
- @branch.should_receive( :directory ).and_return( @directory )
128
- @directory.should_receive( :search ).
129
- with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
142
+ @branch.should_receive( :search ).
143
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
130
144
  and_yield( resultbranch ).and_yield( resultbranch2 )
131
145
 
132
146
  resultbranch.should_receive( :[] ).with( :email ).
@@ -143,6 +157,33 @@ describe Treequel::Branchset do
143
157
  :second_email => :second_cn,
144
158
  }
145
159
  end
160
+
161
+ #
162
+ # #+
163
+ #
164
+ they "can be combined into a BranchCollection by adding them together" do
165
+ other_branch = mock( "second treequel branch", :dn => 'theotherdn' )
166
+ other_branch.stub!( :directory ).and_return( @directory )
167
+ other_branchset = Treequel::Branchset.new( other_branch )
168
+
169
+ result = @branchset + other_branchset
170
+ result.should be_a( Treequel::BranchCollection )
171
+ result.branchsets.should have( 2 ).members
172
+ result.branchsets.should include( @branchset, other_branchset )
173
+ end
174
+
175
+ they "can be combined with a Branch into a BranchCollection by adding it" do
176
+ other_branch = mock( "second treequel branch", :dn => 'theotherdn' )
177
+ other_branch.stub!( :directory ).and_return( @directory )
178
+
179
+ result = @branchset + other_branch
180
+ result.should be_a( Treequel::BranchCollection )
181
+ result.branchsets.should have( 2 ).members
182
+ result.branchsets.should include( @branchset )
183
+ result.branchsets.select {|bs| bs != @branchset }.
184
+ first.branch.should == other_branch
185
+ end
186
+
146
187
  end
147
188
 
148
189
  describe "instance with no filter, options, or scope set" do
@@ -170,9 +211,8 @@ describe Treequel::Branchset do
170
211
 
171
212
 
172
213
  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 ).
214
+ @branch.should_receive( :search ).
215
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
176
216
  and_yield( :matching_branches )
177
217
 
178
218
  @branchset.all.should == [ :matching_branches ]
@@ -180,10 +220,9 @@ describe Treequel::Branchset do
180
220
 
181
221
  it "performs a search using the default filter, scope, and a limit of 1 when the first " +
182
222
  "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) ).
223
+ params = @params.merge( :limit => 1 )
224
+ @branch.should_receive( :search ).
225
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, params ).
187
226
  and_return( [:first_matching_branch, :other_branches] )
188
227
 
189
228
  @branchset.first.should == :first_matching_branch
@@ -222,9 +261,8 @@ describe Treequel::Branchset do
222
261
 
223
262
  it "uses its scope setting as the scope to use when searching" do
224
263
  @branchset.options[:scope] = :onelevel
225
- @branch.should_receive( :directory ).and_return( @directory )
226
- @directory.should_receive( :search ).
227
- with( @branch, :onelevel, @branchset.filter, @params ).
264
+ @branch.should_receive( :search ).
265
+ with( :onelevel, @branchset.filter, @params ).
228
266
  and_yield( :matching_branches )
229
267
 
230
268
  @branchset.all.should == [:matching_branches]
@@ -251,9 +289,8 @@ describe Treequel::Branchset do
251
289
 
252
290
  it "uses its selection as the list of attributes to fetch when searching" do
253
291
  @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,
292
+ @branch.should_receive( :search ).
293
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
257
294
  @params.merge(:selectattrs => ['l', 'cn', 'uid']) ).
258
295
  and_yield( :matching_branches )
259
296
 
@@ -277,9 +314,8 @@ describe Treequel::Branchset do
277
314
 
278
315
  it "uses its timeout as the timeout values when searching" do
279
316
  @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,
317
+ @branch.should_receive( :search ).
318
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
283
319
  @params.merge(:timeout => 5.375) ).
284
320
  and_yield( :matching_branches )
285
321
 
@@ -337,9 +373,8 @@ describe Treequel::Branchset do
337
373
 
338
374
  it "uses its limit as the limit when searching" do
339
375
  @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,
376
+ @branch.should_receive( :search ).
377
+ with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
343
378
  @params.merge(:limit => 8) ).
344
379
  and_yield( :matching_branches )
345
380
 
@@ -371,9 +406,8 @@ describe Treequel::Branchset do
371
406
  end
372
407
 
373
408
  it "performs a search using the default filter and scope when all records are requested" do
374
- @branch.should_receive( :directory ).and_return( @directory )
375
- @directory.should_receive( :search ).
376
- with( @branch, :onelevel, @branchset.filter, @params ).
409
+ @branch.should_receive( :search ).
410
+ with( :onelevel, @branchset.filter, @params ).
377
411
  and_yield( :matching_branches )
378
412
 
379
413
  @branchset.all.should == [:matching_branches]
@@ -381,6 +415,44 @@ describe Treequel::Branchset do
381
415
 
382
416
  end
383
417
 
418
+ describe "created for a directory with registered controls" do
419
+
420
+ before( :all ) do
421
+ @control = Module.new {
422
+ include Treequel::Control
423
+ OID = '3.1.4.1.5.926'
424
+
425
+ def yep; end
426
+ def get_client_controls; [:client_control]; end
427
+ def get_server_controls; [:server_control]; end
428
+ }
429
+ end
430
+
431
+ before( :each ) do
432
+ @directory.stub!( :registered_controls ).and_return([ @control ])
433
+ end
434
+
435
+ it "extends instances of itself with any controls registered with its Branch's Directory" do
436
+ set = Treequel::Branchset.new( @branch )
437
+ set.should respond_to( :yep )
438
+ end
439
+
440
+ it "appends client controls to search arguments" do
441
+ resultbranch = mock( "Result Branch" )
442
+ set = Treequel::Branchset.new( @branch )
443
+
444
+ @params[:server_controls] = [:server_control]
445
+ @params[:client_controls] = [:client_control]
446
+
447
+ @branch.should_receive( :search ).
448
+ with( Treequel::Branchset::DEFAULT_SCOPE, set.filter, @params ).
449
+ and_yield( resultbranch )
450
+
451
+ set.all.should == [ resultbranch ]
452
+ end
453
+
454
+ end
455
+
384
456
  end
385
457
 
386
458
 
@@ -0,0 +1,48 @@
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
+ require 'spec'
13
+ require 'spec/lib/constants'
14
+ require 'spec/lib/helpers'
15
+
16
+ require 'treequel'
17
+ require 'treequel/control'
18
+
19
+ include Treequel::TestConstants
20
+ include Treequel::Constants
21
+
22
+ #####################################################################
23
+ ### C O N T E X T S
24
+ #####################################################################
25
+ module TestControl
26
+ OID = 'an OID'
27
+ include Treequel::Control
28
+ end
29
+
30
+ describe Treequel::Control do
31
+ include Treequel::SpecHelpers
32
+
33
+ before( :each ) do
34
+ @testclass = Class.new
35
+ @obj = @testclass.new
36
+ @obj.extend( TestControl )
37
+ end
38
+
39
+ it "provides a empty client control list by default" do
40
+ @obj.get_client_controls.should == []
41
+ end
42
+
43
+ it "provides a empty server control list by default" do
44
+ @obj.get_server_controls.should == []
45
+ end
46
+ end
47
+
48
+ # vim: set nosta noet ts=4 sw=4:
@@ -0,0 +1,38 @@
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
+ require 'spec'
13
+ require 'spec/lib/constants'
14
+ require 'spec/lib/helpers'
15
+ require 'spec/lib/control_behavior'
16
+
17
+ require 'treequel'
18
+ require 'treequel/controls/contentsync'
19
+
20
+ include Treequel::TestConstants
21
+ include Treequel::Constants
22
+
23
+ #####################################################################
24
+ ### C O N T E X T S
25
+ #####################################################################
26
+ describe Treequel::ContentSyncControl do
27
+ include Treequel::SpecHelpers
28
+
29
+ before( :each ) do
30
+ # Used by the shared behavior
31
+ @control = Treequel::ContentSyncControl
32
+ end
33
+
34
+ it_should_behave_like "A Treequel::Control"
35
+
36
+ end
37
+
38
+ # vim: set nosta noet ts=4 sw=4:
@@ -0,0 +1,138 @@
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
+ require 'spec'
13
+ require 'spec/lib/constants'
14
+ require 'spec/lib/helpers'
15
+ require 'spec/lib/control_behavior'
16
+
17
+ require 'treequel'
18
+ require 'treequel/controls/pagedresults'
19
+
20
+ include Treequel::TestConstants
21
+ include Treequel::Constants
22
+
23
+ #####################################################################
24
+ ### C O N T E X T S
25
+ #####################################################################
26
+ describe Treequel::PagedResultsControl do
27
+ include Treequel::SpecHelpers
28
+
29
+ before( :all ) do
30
+ setup_logging( :fatal )
31
+ end
32
+
33
+ before( :each ) do
34
+ # Used by the shared behavior
35
+ @control = Treequel::PagedResultsControl
36
+ @branch = mock( "Branch", :dn => 'cn=example,dc=acme,dc=com' )
37
+ @directory = mock( "Directory" )
38
+
39
+ @branch.stub!( :directory ).and_return( @directory )
40
+ @directory.stub!( :registered_controls ).and_return([ Treequel::PagedResultsControl ])
41
+ @branchset = Treequel::Branchset.new( @branch )
42
+ end
43
+
44
+ after( :all ) do
45
+ reset_logging()
46
+ end
47
+
48
+
49
+ it_should_behave_like "A Treequel::Control"
50
+
51
+
52
+ it "adds a paged_results_setsize attribute to extended branchsets" do
53
+ @branchset.should respond_to( :paged_results_setsize )
54
+ end
55
+
56
+ it "adds a paged_results_cookie attribute to extended branchsets" do
57
+ @branchset.should respond_to( :paged_results_cookie )
58
+ end
59
+
60
+ it "can add paging of a specific size to a Branchset via the #with_paged_results mutator" do
61
+ @branchset.with_paged_results( 17 ).paged_results_setsize.should == 17
62
+ end
63
+
64
+ it "can create an unpaged Branchset from a paged one by passing nil to #with_paged_results" do
65
+ paged_branchset = @branchset.with_paged_results( 25 )
66
+ paged_branchset.with_paged_results( nil ).paged_results_setsize.should == nil
67
+ end
68
+
69
+ it "can create an unpaged Branchset from a paged one by passing 0 to #with_paged_results" do
70
+ paged_branchset = @branchset.with_paged_results( 25 )
71
+ paged_branchset.with_paged_results( 0 ).paged_results_setsize.should == nil
72
+ end
73
+
74
+ it "can create an unpaged Branchset from a paged one via the #without_paging mutator" do
75
+ paged_branchset = @branchset.with_paged_results( 25 )
76
+ paged_branchset.without_paging.paged_results_setsize.should == nil
77
+ end
78
+
79
+ it "can remove any existing paging from a Branchset via the #without_paging! imperative method" do
80
+ paged_branchset = @branchset.with_paged_results( 25 )
81
+ paged_branchset.without_paging!
82
+ paged_branchset.paged_results_setsize.should == nil
83
+ end
84
+
85
+ it "injects the correct server-control structure into the search when iterating" do
86
+ oid = Treequel::PagedResultsControl::OID
87
+ expected_asn1_string = "0\005\002\001\031\004\000"
88
+ expected_control = LDAP::Control.new( oid, expected_asn1_string, true )
89
+
90
+ resultbranch = mock( "Paged result branch" )
91
+ resultcontrol = mock( "Paged result control" )
92
+
93
+ @branch.should_receive( :search ).with( :subtree,
94
+ instance_of(Treequel::Filter),
95
+ {
96
+ :limit => 0,
97
+ :selectattrs => [],
98
+ :timeout => 0,
99
+ :server_controls => [ expected_control ],
100
+ :client_controls => []
101
+ }
102
+ ).and_yield( resultbranch )
103
+
104
+ resultbranch.should_receive( :controls ).and_return([ resultcontrol ])
105
+ resultcontrol.should_receive( :oid ).
106
+ and_return( Treequel::PagedResultsControl::OID )
107
+ resultcontrol.should_receive( :decode ).and_return([ 25, "cookievalue" ])
108
+
109
+ @branchset.with_paged_results( 25 ).each do |*args|
110
+ args.should == [ resultbranch ]
111
+ end
112
+ end
113
+
114
+ it "doesn't add a paging control if no set size has been set" do
115
+ resultbranch = mock( "Result branch" )
116
+
117
+ @branch.should_receive( :search ).with( :subtree,
118
+ instance_of(Treequel::Filter),
119
+ {
120
+ :limit => 0,
121
+ :selectattrs => [],
122
+ :timeout => 0,
123
+ :server_controls => [],
124
+ :client_controls => []
125
+ }
126
+ ).and_yield( resultbranch )
127
+
128
+ resultbranch.should_receive( :controls ).and_return( [] )
129
+
130
+ @branchset.without_paging.each do |*args|
131
+ args.should == [ resultbranch ]
132
+ end
133
+ end
134
+
135
+
136
+ end
137
+
138
+ # vim: set nosta noet ts=4 sw=4: