treequel 1.11.0 → 1.12.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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +135 -12
- data/{History.rdoc → History.md} +46 -34
- data/Manifest.txt +6 -5
- data/{README.rdoc → README.md} +58 -44
- data/Rakefile +40 -18
- data/examples/ldap-rack-auth.rb +1 -1
- data/examples/ldap_state.rb +5 -5
- data/lib/treequel.rb +10 -9
- data/lib/treequel/behavior/control.rb +7 -8
- data/lib/treequel/branch.rb +29 -28
- data/lib/treequel/branchcollection.rb +8 -7
- data/lib/treequel/branchset.rb +22 -21
- data/lib/treequel/constants.rb +23 -24
- data/lib/treequel/control.rb +15 -15
- data/lib/treequel/controls/contentsync.rb +17 -16
- data/lib/treequel/controls/pagedresults.rb +13 -12
- data/lib/treequel/controls/sortedresults.rb +11 -10
- data/lib/treequel/directory.rb +35 -34
- data/lib/treequel/exceptions.rb +2 -1
- data/lib/treequel/filter.rb +10 -9
- data/lib/treequel/mixins.rb +4 -4
- data/lib/treequel/model.rb +23 -13
- data/lib/treequel/model/errors.rb +10 -9
- data/lib/treequel/model/objectclass.rb +9 -8
- data/lib/treequel/model/schemavalidations.rb +5 -4
- data/lib/treequel/monkeypatches.rb +5 -4
- data/lib/treequel/schema.rb +19 -18
- data/lib/treequel/schema/attributetype.rb +9 -8
- data/lib/treequel/schema/ldapsyntax.rb +2 -1
- data/lib/treequel/schema/matchingrule.rb +2 -1
- data/lib/treequel/schema/matchingruleuse.rb +2 -1
- data/lib/treequel/schema/objectclass.rb +23 -22
- data/lib/treequel/schema/table.rb +3 -2
- data/lib/treequel/sequel_integration.rb +2 -1
- data/lib/treequel/utils.rb +183 -0
- data/misc/ruby-ldap-controlsfix.patch +50 -0
- data/spec/{lib/constants.rb → spec_constants.rb} +7 -6
- data/spec/{lib/helpers.rb → spec_helpers.rb} +31 -53
- data/spec/treequel/branch_spec.rb +196 -223
- data/spec/treequel/branchcollection_spec.rb +73 -113
- data/spec/treequel/branchset_spec.rb +102 -161
- data/spec/treequel/control_spec.rb +5 -21
- data/spec/treequel/controls/contentsync_spec.rb +3 -17
- data/spec/treequel/controls/pagedresults_spec.rb +40 -62
- data/spec/treequel/controls/sortedresults_spec.rb +37 -59
- data/spec/treequel/directory_spec.rb +171 -190
- data/spec/treequel/filter_spec.rb +106 -131
- data/spec/treequel/mixins_spec.rb +47 -81
- data/spec/treequel/model/errors_spec.rb +11 -35
- data/spec/treequel/model/objectclass_spec.rb +99 -131
- data/spec/treequel/model/schemavalidations_spec.rb +36 -60
- data/spec/treequel/model_spec.rb +164 -167
- data/spec/treequel/monkeypatches_spec.rb +20 -41
- data/spec/treequel/schema/attributetype_spec.rb +84 -107
- data/spec/treequel/schema/ldapsyntax_spec.rb +10 -36
- data/spec/treequel/schema/matchingrule_spec.rb +23 -47
- data/spec/treequel/schema/matchingruleuse_spec.rb +18 -42
- data/spec/treequel/schema/objectclass_spec.rb +73 -94
- data/spec/treequel/schema/table_spec.rb +58 -86
- data/spec/treequel/schema_spec.rb +47 -59
- data/spec/treequel_spec.rb +131 -156
- metadata +68 -42
- metadata.gz.sig +0 -0
- data/spec/lib/matchers.rb +0 -55
|
@@ -1,213 +1,187 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
#encoding: utf-8
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
require 'pathname'
|
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
|
6
|
-
|
|
7
|
-
libdir = basedir + "lib"
|
|
8
|
-
|
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
require 'rspec'
|
|
14
|
-
|
|
15
|
-
require 'spec/lib/constants'
|
|
16
|
-
require 'spec/lib/helpers'
|
|
4
|
+
require_relative '../spec_helpers'
|
|
17
5
|
|
|
18
6
|
require 'treequel/branchcollection'
|
|
19
7
|
|
|
20
8
|
|
|
21
|
-
include Treequel::TestConstants
|
|
22
|
-
|
|
23
|
-
#####################################################################
|
|
24
|
-
### C O N T E X T S
|
|
25
|
-
#####################################################################
|
|
26
|
-
|
|
27
9
|
describe Treequel::BranchCollection do
|
|
28
10
|
include Treequel::SpecHelpers
|
|
29
11
|
|
|
30
|
-
before( :all ) do
|
|
31
|
-
setup_logging( :fatal )
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
after( :all ) do
|
|
35
|
-
reset_logging()
|
|
36
|
-
end
|
|
37
|
-
|
|
38
12
|
before( :each ) do
|
|
39
|
-
@directory =
|
|
13
|
+
@directory = double( "treequel directory", :registered_controls => [] )
|
|
40
14
|
end
|
|
41
15
|
|
|
42
16
|
it "can be instantiated without any branchsets" do
|
|
43
17
|
collection = Treequel::BranchCollection.new
|
|
44
|
-
collection.all.
|
|
18
|
+
expect( collection.all ).to eq( [] )
|
|
45
19
|
end
|
|
46
20
|
|
|
47
21
|
it "can be instantiated with one or more branchsets" do
|
|
48
|
-
branch1 =
|
|
22
|
+
branch1 = double( "branch for branchset 1", :directory => @directory )
|
|
49
23
|
branchset1 = Treequel::Branchset.new( branch1 )
|
|
50
|
-
branch2 =
|
|
24
|
+
branch2 = double( "branch for branchset 2", :directory => @directory )
|
|
51
25
|
branchset2 = Treequel::Branchset.new( branch2 )
|
|
52
26
|
|
|
53
27
|
collection = Treequel::BranchCollection.new( branchset1, branchset2 )
|
|
54
28
|
|
|
55
|
-
collection.branchsets.
|
|
29
|
+
expect( collection.branchsets ).to include( branchset1, branchset2 )
|
|
56
30
|
end
|
|
57
31
|
|
|
58
32
|
it "wraps any object that doesn't have an #each in a Branchset" do
|
|
59
|
-
branch1 =
|
|
33
|
+
branch1 = double( "branch for branchset 1", :directory => @directory )
|
|
60
34
|
branchset1 = Treequel::Branchset.new( branch1 )
|
|
61
|
-
branch2 =
|
|
35
|
+
branch2 = double( "branch for branchset 2", :directory => @directory )
|
|
62
36
|
branchset2 = Treequel::Branchset.new( branch2 )
|
|
63
37
|
|
|
64
|
-
Treequel::Branchset.
|
|
38
|
+
expect( Treequel::Branchset ).to receive( :new ).with( :non_branchset1 ).
|
|
65
39
|
and_return( branchset1 )
|
|
66
|
-
Treequel::Branchset.
|
|
40
|
+
expect( Treequel::Branchset ).to receive( :new ).with( :non_branchset2 ).
|
|
67
41
|
and_return( branchset2 )
|
|
68
42
|
|
|
69
43
|
collection = Treequel::BranchCollection.new( :non_branchset1, :non_branchset2 )
|
|
70
44
|
|
|
71
|
-
collection.branchsets.
|
|
45
|
+
expect( collection.branchsets ).to include( branchset1, branchset2 )
|
|
72
46
|
end
|
|
73
47
|
|
|
74
48
|
it "allows new Branchsets to be appended to it" do
|
|
75
|
-
branchset1 =
|
|
76
|
-
branchset2 =
|
|
49
|
+
branchset1 = double( "branchset 1" )
|
|
50
|
+
branchset2 = double( "branchset 2" )
|
|
77
51
|
|
|
78
52
|
collection = Treequel::BranchCollection.new
|
|
79
53
|
collection << branchset1 << branchset2
|
|
80
54
|
|
|
81
|
-
collection.
|
|
55
|
+
expect( collection ).to include( branchset1, branchset2 )
|
|
82
56
|
end
|
|
83
57
|
|
|
84
58
|
it "allows new Branches to be appended to it" do
|
|
85
|
-
branch1 =
|
|
86
|
-
branch2 =
|
|
59
|
+
branch1 = double( "branch 1", :branchset => :branchset1 )
|
|
60
|
+
branch2 = double( "branch 2", :branchset => :branchset2 )
|
|
87
61
|
|
|
88
62
|
collection = Treequel::BranchCollection.new
|
|
89
63
|
collection << branch1 << branch2
|
|
90
64
|
|
|
91
|
-
collection.
|
|
65
|
+
expect( collection ).to include( :branchset1, :branchset2 )
|
|
92
66
|
end
|
|
93
67
|
|
|
94
68
|
|
|
95
69
|
describe "instance with two Branchsets" do
|
|
96
70
|
|
|
97
71
|
before( :each ) do
|
|
98
|
-
# @branchset1 =
|
|
99
|
-
# @branchset2 =
|
|
100
|
-
@branch1 =
|
|
72
|
+
# @branchset1 = double( "branchset 1", :dn => 'cn=example1,dc=acme,dc=com', :each => 1 )
|
|
73
|
+
# @branchset2 = double( "branchset 2", :dn => 'cn=example2,dc=acme,dc=com', :each => 1 )
|
|
74
|
+
@branch1 = double( "branch1", :directory => @directory, :dn => '' )
|
|
101
75
|
@branchset1 = Treequel::Branchset.new( @branch1 )
|
|
102
76
|
|
|
103
|
-
@branch2 =
|
|
77
|
+
@branch2 = double( "branch2", :directory => @directory )
|
|
104
78
|
@branchset2 = Treequel::Branchset.new( @branch2 )
|
|
105
79
|
|
|
106
80
|
@collection = Treequel::BranchCollection.new( @branchset1, @branchset2 )
|
|
107
81
|
end
|
|
108
82
|
|
|
109
83
|
it "knows that it is empty if all of its branchsets are empty" do
|
|
110
|
-
@branchset1.
|
|
111
|
-
@branchset2.
|
|
84
|
+
expect( @branchset1 ).to receive( :empty? ).and_return( true )
|
|
85
|
+
expect( @branchset2 ).to receive( :empty? ).and_return( true )
|
|
112
86
|
|
|
113
|
-
@collection.
|
|
87
|
+
expect( @collection ).to be_empty()
|
|
114
88
|
end
|
|
115
89
|
|
|
116
90
|
it "knows that it is not empty if one of its branchsets has matching entries" do
|
|
117
|
-
@branchset1.
|
|
118
|
-
@branchset2.
|
|
91
|
+
expect( @branchset1 ).to receive( :empty? ).and_return( true )
|
|
92
|
+
expect( @branchset2 ).to receive( :empty? ).and_return( false )
|
|
119
93
|
|
|
120
|
-
@collection.
|
|
94
|
+
expect( @collection ).to_not be_empty()
|
|
121
95
|
end
|
|
122
96
|
|
|
123
97
|
it "fetches all of the results from each of its branchsets if asked for all results" do
|
|
124
|
-
@branchset1.
|
|
125
|
-
@branchset2.
|
|
98
|
+
expect( @branchset1 ).to receive( :each ).and_yield( :bs1_stuff )
|
|
99
|
+
expect( @branchset2 ).to receive( :each ).and_yield( :bs2_stuff )
|
|
126
100
|
|
|
127
|
-
@collection.all.
|
|
101
|
+
expect( @collection.all ).to eq( [ :bs1_stuff, :bs2_stuff ] )
|
|
128
102
|
end
|
|
129
103
|
|
|
130
104
|
it "fetches the first Branch returned by any of its branchsets when asked" do
|
|
131
|
-
@branchset1.
|
|
132
|
-
@branchset2.
|
|
105
|
+
expect( @branchset1 ).to receive( :first ).and_return( nil )
|
|
106
|
+
expect( @branchset2 ).to receive( :first ).and_return( :a_branch )
|
|
133
107
|
|
|
134
|
-
@collection.first.
|
|
108
|
+
expect( @collection.first ).to eq( :a_branch )
|
|
135
109
|
end
|
|
136
110
|
|
|
137
111
|
it "returns a clone of itself with an additional Branchset if a Branchset is added to it" do
|
|
138
|
-
branch3 =
|
|
112
|
+
branch3 = double( "branch 3", :directory => @directory )
|
|
139
113
|
branchset3 = Treequel::Branchset.new( branch3 )
|
|
140
114
|
|
|
141
115
|
new_collection = @collection + branchset3
|
|
142
116
|
|
|
143
|
-
new_collection.
|
|
144
|
-
new_collection.
|
|
117
|
+
expect( new_collection ).to be_an_instance_of( Treequel::BranchCollection )
|
|
118
|
+
expect( new_collection ).to include( @branchset1, @branchset2, branchset3 )
|
|
145
119
|
end
|
|
146
120
|
|
|
147
121
|
it "returns all of the results from each of its branchsets plus the added branch if a " +
|
|
148
122
|
"Branch is added to it" do
|
|
149
|
-
@branchset1.
|
|
150
|
-
@branchset2.
|
|
151
|
-
added_branch =
|
|
152
|
-
added_branch.
|
|
123
|
+
expect( @branchset1 ).to receive( :each ).and_yield( :bs1_stuff )
|
|
124
|
+
expect( @branchset2 ).to receive( :each ).and_yield( :bs2_stuff )
|
|
125
|
+
added_branch = double( "added branch", :directory => @directory )
|
|
126
|
+
expect( added_branch ).to receive( :to_ary ).and_return( [added_branch] )
|
|
153
127
|
|
|
154
128
|
results = @collection + added_branch
|
|
155
129
|
|
|
156
|
-
results.
|
|
157
|
-
results.
|
|
130
|
+
expect( results.length ).to eq( 3 )
|
|
131
|
+
expect( results ).to include( :bs1_stuff, :bs2_stuff, added_branch )
|
|
158
132
|
end
|
|
159
133
|
|
|
160
134
|
it "returns all of the results from each of its branchsets minus the subtracted branch " +
|
|
161
135
|
"if a Branch is subtracted from it" do
|
|
162
|
-
results_branch1 =
|
|
163
|
-
results_branch2 =
|
|
164
|
-
subtracted_branch =
|
|
136
|
+
results_branch1 = double( "results branch 1", :dn => TEST_PERSON_DN )
|
|
137
|
+
results_branch2 = double( "results branch 2", :dn => TEST_PERSON2_DN )
|
|
138
|
+
subtracted_branch = double( "subtracted branch", :dn => TEST_PERSON_DN )
|
|
165
139
|
|
|
166
|
-
@branchset1.
|
|
167
|
-
@branchset2.
|
|
140
|
+
expect( @branchset1 ).to receive( :each ).and_yield( results_branch1 )
|
|
141
|
+
expect( @branchset2 ).to receive( :each ).and_yield( results_branch2 )
|
|
168
142
|
|
|
169
143
|
results = @collection - subtracted_branch
|
|
170
144
|
|
|
171
|
-
results.
|
|
172
|
-
results.
|
|
173
|
-
results.
|
|
145
|
+
expect( results.length ).to eq( 1 )
|
|
146
|
+
expect( results ).to_not include( subtracted_branch )
|
|
147
|
+
expect( results ).to_not include( results_branch1 )
|
|
174
148
|
end
|
|
175
149
|
|
|
176
150
|
it "returns a clone of itself with both collections' Branchsets if a BranchCollection is " +
|
|
177
151
|
"added to it" do
|
|
178
|
-
branch3 =
|
|
152
|
+
branch3 = double( "branch for branchset 3", :directory => @directory )
|
|
179
153
|
branchset3 = Treequel::Branchset.new( branch3 )
|
|
180
|
-
branch4 =
|
|
154
|
+
branch4 = double( "branch for branchset 4", :directory => @directory )
|
|
181
155
|
branchset4 = Treequel::Branchset.new( branch4 )
|
|
182
156
|
|
|
183
157
|
other_collection = Treequel::BranchCollection.new( branchset3, branchset4 )
|
|
184
158
|
|
|
185
159
|
new_collection = @collection + other_collection
|
|
186
160
|
|
|
187
|
-
new_collection.
|
|
188
|
-
new_collection.
|
|
161
|
+
expect( new_collection ).to be_an_instance_of( Treequel::BranchCollection )
|
|
162
|
+
expect( new_collection ).to include( @branchset1, @branchset2, branchset3, branchset4 )
|
|
189
163
|
end
|
|
190
164
|
|
|
191
165
|
it "returns a new BranchCollection with the union of Branchsets if it is ORed with " +
|
|
192
166
|
"another BranchCollection" do
|
|
193
|
-
branch3 =
|
|
167
|
+
branch3 = double( "branch for branchset 3", :directory => @directory )
|
|
194
168
|
branchset3 = Treequel::Branchset.new( branch3 )
|
|
195
|
-
branch4 =
|
|
169
|
+
branch4 = double( "branch for branchset 4", :directory => @directory )
|
|
196
170
|
branchset4 = Treequel::Branchset.new( branch4 )
|
|
197
171
|
|
|
198
172
|
other_collection = Treequel::BranchCollection.new( branchset3, branchset4 )
|
|
199
173
|
|
|
200
174
|
new_collection = @collection | other_collection
|
|
201
175
|
|
|
202
|
-
new_collection.
|
|
203
|
-
new_collection.
|
|
176
|
+
expect( new_collection ).to be_an_instance_of( Treequel::BranchCollection )
|
|
177
|
+
expect( new_collection ).to include( @branchset1, @branchset2, branchset3, branchset4 )
|
|
204
178
|
end
|
|
205
179
|
|
|
206
180
|
it "returns a new BranchCollection with the intersection of Branchsets if it is ANDed with " +
|
|
207
181
|
"another BranchCollection" do
|
|
208
|
-
branch3 =
|
|
182
|
+
branch3 = double( "branch for branchset 3", :directory => @directory )
|
|
209
183
|
branchset3 = Treequel::Branchset.new( branch3 )
|
|
210
|
-
branch4 =
|
|
184
|
+
branch4 = double( "branch for branchset 4", :directory => @directory )
|
|
211
185
|
branchset4 = Treequel::Branchset.new( branch4 )
|
|
212
186
|
|
|
213
187
|
other_collection = Treequel::BranchCollection.new( @branchset2, branchset3, branchset4 )
|
|
@@ -215,52 +189,38 @@ describe Treequel::BranchCollection do
|
|
|
215
189
|
|
|
216
190
|
new_collection = @collection & other_collection
|
|
217
191
|
|
|
218
|
-
new_collection.
|
|
219
|
-
new_collection.
|
|
192
|
+
expect( new_collection ).to be_an_instance_of( Treequel::BranchCollection )
|
|
193
|
+
expect( new_collection ).to include( @branchset2, branchset4 )
|
|
220
194
|
end
|
|
221
195
|
|
|
222
196
|
it "can create a clone of itself with filtered branchsets" do
|
|
223
|
-
branch3 =
|
|
197
|
+
branch3 = double( "branch for branchset 3", :directory => @directory )
|
|
224
198
|
filtered_branchset1 = Treequel::Branchset.new( branch3 )
|
|
225
|
-
branch4 =
|
|
199
|
+
branch4 = double( "branch for branchset 4", :directory => @directory )
|
|
226
200
|
filtered_branchset2 = Treequel::Branchset.new( branch4 )
|
|
227
201
|
|
|
228
|
-
@branchset1.
|
|
202
|
+
expect( @branchset1 ).to receive( :filter ).with( :cn => 'chunkalicious' ).
|
|
229
203
|
and_return( filtered_branchset1 )
|
|
230
|
-
@branchset2.
|
|
204
|
+
expect( @branchset2 ).to receive( :filter ).with( :cn => 'chunkalicious' ).
|
|
231
205
|
and_return( filtered_branchset2 )
|
|
232
206
|
|
|
233
207
|
filtered_collection = @collection.filter( :cn => 'chunkalicious' )
|
|
234
|
-
filtered_collection.
|
|
235
|
-
filtered_collection.
|
|
208
|
+
expect( filtered_collection ).to_not be_equal( @collection )
|
|
209
|
+
expect( filtered_collection ).to include( filtered_branchset1, filtered_branchset2 )
|
|
236
210
|
end
|
|
237
211
|
|
|
238
212
|
it "raises a reasonable exception if one of its delegates returns a non-branchset" do
|
|
239
213
|
filter = Treequel::Filter.new
|
|
240
|
-
@branchset1.stub( :filter ).and_return( filter )
|
|
241
214
|
|
|
242
215
|
expect {
|
|
243
216
|
@collection.filter
|
|
244
217
|
}.to raise_exception( ArgumentError, /0 for 1/ )
|
|
245
218
|
end
|
|
246
219
|
|
|
247
|
-
# it "can create a clone of itself with ordered branchsets" do
|
|
248
|
-
# ordered_branchset1 = stub( "branchset 3", :dn => 'cn=example3,dc=acme,dc=com', :each => 1 )
|
|
249
|
-
# ordered_branchset2 = stub( "branchset 4", :dn => 'cn=example4,dc=acme,dc=com', :each => 1 )
|
|
250
|
-
# @branchset1.should_receive( :order ).with( :cn ).
|
|
251
|
-
# and_return( ordered_branchset1 )
|
|
252
|
-
# @branchset2.should_receive( :order ).with( :cn ).
|
|
253
|
-
# and_return( ordered_branchset2 )
|
|
254
|
-
#
|
|
255
|
-
# ordered_collection = @collection.order( :cn )
|
|
256
|
-
# ordered_collection.should_not be_equal( @collection )
|
|
257
|
-
# ordered_collection.should include( ordered_branchset1, ordered_branchset2 )
|
|
258
|
-
# end
|
|
259
|
-
#
|
|
260
220
|
it "can return the base DNs of all of its branchsets" do
|
|
261
|
-
@branchset1.
|
|
262
|
-
@branchset2.
|
|
263
|
-
@collection.base_dns.
|
|
221
|
+
expect( @branchset1 ).to receive( :base_dn ).and_return( :branchset1_basedn )
|
|
222
|
+
expect( @branchset2 ).to receive( :base_dn ).and_return( :branchset2_basedn )
|
|
223
|
+
expect( @collection.base_dns ).to eq( [ :branchset1_basedn, :branchset2_basedn ] )
|
|
264
224
|
end
|
|
265
225
|
|
|
266
226
|
end
|
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
#encoding: utf-8
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
require 'pathname'
|
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
|
6
|
-
|
|
7
|
-
libdir = basedir + "lib"
|
|
8
|
-
|
|
9
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
|
10
|
-
$LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
require 'rspec'
|
|
14
|
-
|
|
15
|
-
require 'spec/lib/constants'
|
|
16
|
-
require 'spec/lib/helpers'
|
|
4
|
+
require_relative '../spec_helpers'
|
|
17
5
|
|
|
18
6
|
require 'treequel/branchset'
|
|
19
7
|
require 'treequel/branchcollection'
|
|
20
8
|
require 'treequel/control'
|
|
21
9
|
|
|
22
10
|
|
|
23
|
-
#####################################################################
|
|
24
|
-
### C O N T E X T S
|
|
25
|
-
#####################################################################
|
|
26
|
-
|
|
27
11
|
describe Treequel::Branchset do
|
|
28
12
|
|
|
29
13
|
DEFAULT_PARAMS = {
|
|
@@ -35,14 +19,6 @@ describe Treequel::Branchset do
|
|
|
35
19
|
}
|
|
36
20
|
|
|
37
21
|
|
|
38
|
-
before( :all ) do
|
|
39
|
-
setup_logging( :fatal )
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
after( :all ) do
|
|
43
|
-
reset_logging()
|
|
44
|
-
end
|
|
45
|
-
|
|
46
22
|
before( :each ) do
|
|
47
23
|
@conn = double( "LDAP connection", :set_option => true, :bound? => false )
|
|
48
24
|
@directory = get_fixtured_directory( @conn )
|
|
@@ -57,51 +33,51 @@ describe Treequel::Branchset do
|
|
|
57
33
|
end
|
|
58
34
|
|
|
59
35
|
it "is Enumerable" do
|
|
60
|
-
@conn.
|
|
61
|
-
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
36
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
37
|
+
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
62
38
|
[], false, [], [], 0, 0, 0, "", nil ).
|
|
63
39
|
and_return([ TEST_HOSTS_ENTRY.dup ])
|
|
64
40
|
|
|
65
41
|
@branchset.all? {|b| b.dn }
|
|
66
42
|
end
|
|
67
43
|
|
|
68
|
-
#
|
|
44
|
+
#
|
|
69
45
|
# #empty?
|
|
70
|
-
#
|
|
46
|
+
#
|
|
71
47
|
it "is empty if it doesn't match at least one entry" do
|
|
72
|
-
@conn.
|
|
73
|
-
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
48
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
49
|
+
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
74
50
|
[], false, [], [], 0, 0, 1, "", nil ).
|
|
75
51
|
and_return([ ])
|
|
76
|
-
@branchset.
|
|
52
|
+
expect( @branchset ).to be_empty()
|
|
77
53
|
end
|
|
78
54
|
|
|
79
55
|
it "isn't empty if it matches at least one entry" do
|
|
80
|
-
@conn.
|
|
81
|
-
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
56
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
57
|
+
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
82
58
|
[], false, [], [], 0, 0, 1, "", nil ).
|
|
83
59
|
and_return([ TEST_HOSTS_ENTRY.dup ])
|
|
84
|
-
@branchset.
|
|
60
|
+
expect( @branchset ).to_not be_empty()
|
|
85
61
|
end
|
|
86
62
|
|
|
87
|
-
#
|
|
63
|
+
#
|
|
88
64
|
# #map
|
|
89
|
-
#
|
|
65
|
+
#
|
|
90
66
|
it "can be mapped into an Array of attribute values" do
|
|
91
|
-
@conn.
|
|
92
|
-
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
67
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
68
|
+
with( TEST_BASE_DN, LDAP::LDAP_SCOPE_SUBTREE, "(objectClass=*)",
|
|
93
69
|
[], false, [], [], 0, 0, 0, "", nil ).
|
|
94
70
|
and_return([ TEST_HOSTS_ENTRY.dup, TEST_PEOPLE_ENTRY.dup ])
|
|
95
71
|
|
|
96
|
-
@branchset.map( :ou ).
|
|
72
|
+
expect( @branchset.map( :ou ) ).to eq( [ ['Hosts'], ['People'] ] )
|
|
97
73
|
end
|
|
98
74
|
|
|
99
75
|
|
|
100
|
-
#
|
|
76
|
+
#
|
|
101
77
|
# #to_hash
|
|
102
|
-
#
|
|
78
|
+
#
|
|
103
79
|
it "can be mapped into a Hash of entries keyed by one of its attributes" do
|
|
104
|
-
@conn.
|
|
80
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
105
81
|
with( "dc=acme,dc=com", 2, "(objectClass=*)", [], false, [], [], 0, 0, 0, "", nil ).
|
|
106
82
|
and_return([ TEST_HOSTS_ENTRY.dup, TEST_PEOPLE_ENTRY.dup ])
|
|
107
83
|
|
|
@@ -110,22 +86,22 @@ describe Treequel::Branchset do
|
|
|
110
86
|
peoplehash = TEST_PEOPLE_ENTRY.dup
|
|
111
87
|
peoplehash.delete( 'dn' )
|
|
112
88
|
|
|
113
|
-
@branchset.to_hash( :ou ).
|
|
89
|
+
expect( @branchset.to_hash( :ou ) ).to eq({
|
|
114
90
|
'Hosts' => hosthash,
|
|
115
91
|
'People' => peoplehash,
|
|
116
|
-
}
|
|
92
|
+
})
|
|
117
93
|
end
|
|
118
94
|
|
|
119
95
|
|
|
120
96
|
it "can be mapped into a Hash of tuples using two attributes" do
|
|
121
|
-
@conn.
|
|
97
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
122
98
|
with( "dc=acme,dc=com", 2, "(objectClass=*)", [], false, [], [], 0, 0, 0, "", nil ).
|
|
123
99
|
and_return([ TEST_HOSTS_ENTRY.dup, TEST_PEOPLE_ENTRY.dup ])
|
|
124
100
|
|
|
125
|
-
@branchset.to_hash( :ou, :description ).
|
|
101
|
+
expect( @branchset.to_hash( :ou, :description ) ).to eq({
|
|
126
102
|
'Hosts' => TEST_HOSTS_ENTRY['description'].first,
|
|
127
103
|
'People' => TEST_PEOPLE_ENTRY['description'].first,
|
|
128
|
-
}
|
|
104
|
+
})
|
|
129
105
|
end
|
|
130
106
|
|
|
131
107
|
#
|
|
@@ -136,21 +112,21 @@ describe Treequel::Branchset do
|
|
|
136
112
|
other_branchset = Treequel::Branchset.new( other_branch )
|
|
137
113
|
|
|
138
114
|
result = @branchset + other_branchset
|
|
139
|
-
result.
|
|
140
|
-
result.branchsets.
|
|
141
|
-
result.branchsets.
|
|
115
|
+
expect( result ).to be_a( Treequel::BranchCollection )
|
|
116
|
+
expect( result.branchsets.length ).to eq( 2 )
|
|
117
|
+
expect( result.branchsets ).to include( @branchset, other_branchset )
|
|
142
118
|
end
|
|
143
119
|
|
|
144
120
|
it "returns the results of the search with the additional Branch if one is added to it" do
|
|
145
|
-
@conn.
|
|
121
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
146
122
|
with( "dc=acme,dc=com", 2, "(objectClass=*)", [], false, [], [], 0, 0, 0, "", nil ).
|
|
147
123
|
and_return([ TEST_HOSTS_ENTRY.dup, TEST_PEOPLE_ENTRY.dup ])
|
|
148
124
|
|
|
149
125
|
other_branch = @directory.ou( :netgroups )
|
|
150
126
|
|
|
151
127
|
result = @branchset + other_branch
|
|
152
|
-
result.
|
|
153
|
-
result.
|
|
128
|
+
expect( result.length ).to eq( 3 )
|
|
129
|
+
expect( result ).to include( other_branch )
|
|
154
130
|
end
|
|
155
131
|
|
|
156
132
|
#
|
|
@@ -160,13 +136,13 @@ describe Treequel::Branchset do
|
|
|
160
136
|
"subtracted from it" do
|
|
161
137
|
otherbranch = @directory.ou( :people )
|
|
162
138
|
|
|
163
|
-
@conn.
|
|
139
|
+
expect( @conn ).to receive( :search_ext2 ).
|
|
164
140
|
with( "dc=acme,dc=com", 2, "(objectClass=*)", [], false, [], [], 0, 0, 0, "", nil ).
|
|
165
141
|
and_return([ TEST_HOSTS_ENTRY.dup, TEST_PEOPLE_ENTRY.dup ])
|
|
166
142
|
|
|
167
143
|
result = @branchset - otherbranch
|
|
168
|
-
result.
|
|
169
|
-
result.
|
|
144
|
+
expect( result.length ).to eq( 1 )
|
|
145
|
+
expect( result ).to_not include( otherbranch )
|
|
170
146
|
end
|
|
171
147
|
|
|
172
148
|
end
|
|
@@ -179,53 +155,53 @@ describe Treequel::Branchset do
|
|
|
179
155
|
|
|
180
156
|
it "can clone itself with merged options" do
|
|
181
157
|
newset = @branchset.clone( :scope => :one )
|
|
182
|
-
newset.
|
|
183
|
-
newset.
|
|
184
|
-
newset.options.
|
|
185
|
-
newset.scope.
|
|
158
|
+
expect( newset ).to be_a( Treequel::Branchset )
|
|
159
|
+
expect( newset ).to_not equal( @branchset )
|
|
160
|
+
expect( newset.options ).to_not equal( @branchset.options )
|
|
161
|
+
expect( newset.scope ).to eq( :one )
|
|
186
162
|
end
|
|
187
163
|
|
|
188
164
|
|
|
189
|
-
#
|
|
165
|
+
#
|
|
190
166
|
# #filter
|
|
191
|
-
#
|
|
167
|
+
#
|
|
192
168
|
|
|
193
169
|
it "generates a valid filter string" do
|
|
194
|
-
@branchset.filter_string.
|
|
170
|
+
expect( @branchset.filter_string ).to eq( '(objectClass=*)' )
|
|
195
171
|
end
|
|
196
172
|
|
|
197
173
|
|
|
198
174
|
it "performs a search using the default filter and scope when all records are requested" do
|
|
199
|
-
@branch.
|
|
175
|
+
expect( @branch ).to receive( :search ).
|
|
200
176
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, @params ).
|
|
201
177
|
and_yield( :matching_branches )
|
|
202
178
|
|
|
203
|
-
@branchset.all.
|
|
179
|
+
expect( @branchset.all ).to eq( [ :matching_branches ] )
|
|
204
180
|
end
|
|
205
181
|
|
|
206
182
|
it "performs a search using the default filter, scope, and a limit of 1 when the first " +
|
|
207
183
|
"record is requested" do
|
|
208
184
|
params = @params.merge( :limit => 1 )
|
|
209
|
-
@branch.
|
|
185
|
+
expect( @branch ).to receive( :search ).
|
|
210
186
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, params ).
|
|
211
187
|
and_return( [:first_matching_branch, :other_branches] )
|
|
212
188
|
|
|
213
|
-
@branchset.first.
|
|
189
|
+
expect( @branchset.first ).to eq( :first_matching_branch )
|
|
214
190
|
end
|
|
215
191
|
|
|
216
192
|
it "performs a search using the default filter, scope, and a limit of 5 when the first " +
|
|
217
193
|
"five records are requested" do
|
|
218
194
|
params = @params.merge( :limit => 5 )
|
|
219
|
-
@branch.
|
|
195
|
+
expect( @branch ).to receive( :search ).
|
|
220
196
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter, params ).
|
|
221
197
|
and_return( [:branch1, :branch2, :branch3, :branch4, :branch5] )
|
|
222
198
|
|
|
223
|
-
@branchset.first( 5 ).
|
|
199
|
+
expect( @branchset.first( 5 ) ).to eq( [:branch1, :branch2, :branch3, :branch4, :branch5] )
|
|
224
200
|
end
|
|
225
201
|
|
|
226
202
|
it "creates a new branchset cloned from itself with the specified filter" do
|
|
227
203
|
newset = @branchset.filter( :clothing, 'pants' )
|
|
228
|
-
newset.filter_string.
|
|
204
|
+
expect( newset.filter_string ).to eq( '(clothing=pants)' )
|
|
229
205
|
end
|
|
230
206
|
|
|
231
207
|
#
|
|
@@ -237,7 +213,7 @@ describe Treequel::Branchset do
|
|
|
237
213
|
pantset = @branchset.filter( :clothing => 'pants' )
|
|
238
214
|
bothset = pantset.or( :clothing => 'shirt' )
|
|
239
215
|
|
|
240
|
-
bothset.filter_string.
|
|
216
|
+
expect( bothset.filter_string ).to eq( '(|(clothing=pants)(clothing=shirt))' )
|
|
241
217
|
end
|
|
242
218
|
|
|
243
219
|
it "raises an exception if #or is invoked without an existing filter" do
|
|
@@ -255,174 +231,139 @@ describe Treequel::Branchset do
|
|
|
255
231
|
pantset = @branchset.filter( :clothing => 'pants' )
|
|
256
232
|
notsmallset = pantset.not( :size => 'small' )
|
|
257
233
|
|
|
258
|
-
notsmallset.filter_string.
|
|
234
|
+
expect( notsmallset.filter_string ).to eq( '(&(clothing=pants)(!(size=small)))' )
|
|
259
235
|
end
|
|
260
236
|
|
|
261
237
|
|
|
262
|
-
#
|
|
238
|
+
#
|
|
263
239
|
# #scope
|
|
264
|
-
#
|
|
240
|
+
#
|
|
265
241
|
|
|
266
242
|
it "provides a reader for its scope" do
|
|
267
|
-
@branchset.scope.
|
|
243
|
+
expect( @branchset.scope ).to eq( :subtree )
|
|
268
244
|
end
|
|
269
245
|
|
|
270
246
|
it "can return the DN of its base" do
|
|
271
|
-
@branch.
|
|
272
|
-
@branchset.base_dn.
|
|
247
|
+
expect( @branch ).to receive( :dn ).and_return( :foo )
|
|
248
|
+
expect( @branchset.base_dn ).to eq( :foo )
|
|
273
249
|
end
|
|
274
250
|
|
|
275
251
|
it "can create a new branchset cloned from itself with a different scope" do
|
|
276
252
|
newset = @branchset.scope( :onelevel )
|
|
277
|
-
newset.
|
|
278
|
-
newset.
|
|
279
|
-
newset.options.
|
|
280
|
-
newset.scope.
|
|
253
|
+
expect( newset ).to be_a( Treequel::Branchset )
|
|
254
|
+
expect( newset ).to_not equal( @branchset )
|
|
255
|
+
expect( newset.options ).to_not equal( @branchset.options )
|
|
256
|
+
expect( newset.scope ).to eq( :onelevel )
|
|
281
257
|
end
|
|
282
258
|
|
|
283
259
|
it "can create a new branchset cloned from itself with a different string scope" do
|
|
284
260
|
newset = @branchset.scope( 'sub' )
|
|
285
|
-
newset.scope.
|
|
261
|
+
expect( newset.scope ).to eq( :sub )
|
|
286
262
|
end
|
|
287
263
|
|
|
288
264
|
it "uses its scope setting as the scope to use when searching" do
|
|
289
265
|
@branchset.options[:scope] = :onelevel
|
|
290
|
-
@branch.
|
|
266
|
+
expect( @branch ).to receive( :search ).
|
|
291
267
|
with( :onelevel, @branchset.filter, @params ).
|
|
292
268
|
and_yield( :matching_branches )
|
|
293
269
|
|
|
294
|
-
@branchset.all.
|
|
270
|
+
expect( @branchset.all ).to eq( [:matching_branches] )
|
|
295
271
|
end
|
|
296
272
|
|
|
297
|
-
#
|
|
273
|
+
#
|
|
298
274
|
# #select
|
|
299
|
-
#
|
|
275
|
+
#
|
|
300
276
|
it "can create a new branchset cloned from itself with an attribute selection" do
|
|
301
277
|
newset = @branchset.select( :l, :lastName, :disabled )
|
|
302
|
-
newset.select.
|
|
278
|
+
expect( newset.select ).to eq( [ 'l', 'lastName', 'disabled' ] )
|
|
303
279
|
end
|
|
304
280
|
|
|
305
281
|
it "can create a new branchset cloned from itself with all attributes selected" do
|
|
306
282
|
newset = @branchset.select_all
|
|
307
|
-
newset.select.
|
|
283
|
+
expect( newset.select ).to eq( [] )
|
|
308
284
|
end
|
|
309
285
|
|
|
310
286
|
it "can create a new branchset cloned from itself with additional attributes selected" do
|
|
311
287
|
@branchset.options[:select] = [ :l, :cn, :uid ]
|
|
312
288
|
newset = @branchset.select_more( :firstName, :uid, :lastName )
|
|
313
|
-
newset.select.
|
|
289
|
+
expect( newset.select ).to eq( [ 'l', 'cn', 'uid', 'firstName', 'lastName' ] )
|
|
314
290
|
end
|
|
315
291
|
|
|
316
292
|
it "adding attributes via #select_more should work even if there was no current " +
|
|
317
293
|
"attribute selection" do
|
|
318
294
|
newset = @branchset.select_more( :firstName, :uid, :lastName, :objectClass )
|
|
319
|
-
newset.select.
|
|
295
|
+
expect( newset.select ).to include( 'uid', 'firstName', 'lastName', 'objectClass' )
|
|
320
296
|
end
|
|
321
297
|
|
|
322
298
|
it "uses its selection as the list of attributes to fetch when searching" do
|
|
323
299
|
@branchset.options[:select] = [ :l, :cn, :uid ]
|
|
324
|
-
@branch.
|
|
300
|
+
expect( @branch ).to receive( :search ).
|
|
325
301
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
|
|
326
302
|
@params.merge(:selectattrs => ['l', 'cn', 'uid']) ).
|
|
327
303
|
and_yield( :matching_branches )
|
|
328
304
|
|
|
329
|
-
@branchset.all.
|
|
305
|
+
expect( @branchset.all ).to eq( [:matching_branches] )
|
|
330
306
|
end
|
|
331
307
|
|
|
332
|
-
#
|
|
308
|
+
#
|
|
333
309
|
# #timeout
|
|
334
|
-
#
|
|
310
|
+
#
|
|
335
311
|
|
|
336
312
|
it "can create a new branchset cloned from itself with a timeout" do
|
|
337
313
|
newset = @branchset.timeout( 30 )
|
|
338
|
-
newset.timeout.
|
|
314
|
+
expect( newset.timeout ).to eq( 30.0 )
|
|
339
315
|
end
|
|
340
316
|
|
|
341
317
|
it "can create a new branchset cloned from itself without a timeout" do
|
|
342
318
|
@branchset.options[:timeout] = 5.375
|
|
343
319
|
newset = @branchset.without_timeout
|
|
344
|
-
newset.timeout.
|
|
320
|
+
expect( newset.timeout ).to eq( 0 )
|
|
345
321
|
end
|
|
346
322
|
|
|
347
323
|
it "uses its timeout as the timeout values when searching" do
|
|
348
324
|
@branchset.options[:timeout] = 5.375
|
|
349
|
-
@branch.
|
|
325
|
+
expect( @branch ).to receive( :search ).
|
|
350
326
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
|
|
351
327
|
@params.merge(:timeout => 5.375) ).
|
|
352
328
|
and_yield( :matching_branches )
|
|
353
329
|
|
|
354
|
-
@branchset.all.
|
|
355
|
-
end
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
#
|
|
359
|
-
#
|
|
360
|
-
|
|
361
|
-
# it "can create a new branchset cloned from itself with a sort-order attribute" do
|
|
362
|
-
# newset = @branchset.order( :uid )
|
|
363
|
-
# newset.order.should == :uid
|
|
364
|
-
# end
|
|
365
|
-
#
|
|
366
|
-
# it "converts a string sort-order attribute to a Symbol" do
|
|
367
|
-
# newset = @branchset.order( 'uid' )
|
|
368
|
-
# newset.order.should == :uid
|
|
369
|
-
# end
|
|
370
|
-
#
|
|
371
|
-
# it "can set a sorting function instead of an attribute" do
|
|
372
|
-
# newset = @branchset.order {|branch| branch.uid }
|
|
373
|
-
# newset.order.should be_a( Proc )
|
|
374
|
-
# end
|
|
375
|
-
#
|
|
376
|
-
# it "can create a new branchset cloned from itself without a sort-order attribute" do
|
|
377
|
-
# @branchset.options[:order] = :uid
|
|
378
|
-
# newset = @branchset.order( nil )
|
|
379
|
-
# newset.order.should == nil
|
|
380
|
-
# end
|
|
381
|
-
#
|
|
382
|
-
# it "uses its order attribute list when searching" do
|
|
383
|
-
# @branchset.options[:order] = [ :uid ]
|
|
384
|
-
# @branch.should_receive( :directory ).and_return( @directory )
|
|
385
|
-
# @directory.should_receive( :search ).
|
|
386
|
-
# with( @branch, Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
|
|
387
|
-
# @params.merge(:sortby => ['uid']) ).
|
|
388
|
-
# and_yield( :matching_branches )
|
|
389
|
-
#
|
|
390
|
-
# @branchset.all.should == [:matching_branches]
|
|
391
|
-
# end
|
|
392
|
-
|
|
393
|
-
#
|
|
330
|
+
expect( @branchset.all ).to eq( [:matching_branches] )
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
#
|
|
394
335
|
# #limit
|
|
395
|
-
#
|
|
336
|
+
#
|
|
396
337
|
it "can create a new branchset cloned from itself with a limit attribute" do
|
|
397
338
|
newset = @branchset.limit( 5 )
|
|
398
|
-
newset.limit.
|
|
339
|
+
expect( newset.limit ).to eq( 5 )
|
|
399
340
|
end
|
|
400
341
|
|
|
401
342
|
it "can create a new branchset cloned from itself without a limit" do
|
|
402
343
|
newset = @branchset.without_limit
|
|
403
|
-
newset.limit.
|
|
344
|
+
expect( newset.limit ).to eq( 0 )
|
|
404
345
|
end
|
|
405
346
|
|
|
406
347
|
it "uses its limit as the limit when searching" do
|
|
407
348
|
@branchset.options[:limit] = 8
|
|
408
|
-
@branch.
|
|
349
|
+
expect( @branch ).to receive( :search ).
|
|
409
350
|
with( Treequel::Branchset::DEFAULT_SCOPE, @branchset.filter,
|
|
410
351
|
@params.merge(:limit => 8) ).
|
|
411
352
|
and_yield( :matching_branches )
|
|
412
353
|
|
|
413
|
-
@branchset.all.
|
|
354
|
+
expect( @branchset.all ).to eq( [:matching_branches] )
|
|
414
355
|
end
|
|
415
356
|
|
|
416
|
-
#
|
|
357
|
+
#
|
|
417
358
|
# #as
|
|
418
|
-
#
|
|
359
|
+
#
|
|
419
360
|
it "can create a new branchset cloned from itself that will return instances of a " +
|
|
420
361
|
"different branch class" do
|
|
421
362
|
subclass = Class.new( Treequel::Branch )
|
|
422
|
-
@branch.
|
|
423
|
-
@branch.
|
|
363
|
+
expect( @branch ).to receive( :directory ).and_return( :the_directory )
|
|
364
|
+
expect( @branch ).to receive( :dn ).at_least( :once ).and_return( TEST_HOSTS_DN )
|
|
424
365
|
newset = @branchset.as( subclass )
|
|
425
|
-
newset.branch.
|
|
366
|
+
expect( newset.branch ).to be_an_instance_of( subclass )
|
|
426
367
|
end
|
|
427
368
|
|
|
428
369
|
|
|
@@ -431,14 +372,14 @@ describe Treequel::Branchset do
|
|
|
431
372
|
#
|
|
432
373
|
it "can create a new branchset cloned from itself with a different base DN (String)" do
|
|
433
374
|
newset = @branchset.from( TEST_SUBHOSTS_DN )
|
|
434
|
-
newset.base_dn.
|
|
375
|
+
expect( newset.base_dn ).to eq( TEST_SUBHOSTS_DN )
|
|
435
376
|
end
|
|
436
377
|
|
|
437
378
|
it "can create a new branchset cloned from itself with a different base DN " +
|
|
438
379
|
"(Treequel::Branch)" do
|
|
439
380
|
branch = Treequel::Branch.new( @directory, TEST_SUBHOSTS_DN )
|
|
440
381
|
newset = @branchset.from( branch )
|
|
441
|
-
newset.base_dn.
|
|
382
|
+
expect( newset.base_dn ).to eq( TEST_SUBHOSTS_DN )
|
|
442
383
|
end
|
|
443
384
|
|
|
444
385
|
|
|
@@ -447,7 +388,7 @@ describe Treequel::Branchset do
|
|
|
447
388
|
#
|
|
448
389
|
it "can create a new branchset cloned from itself with operational attributes selected" do
|
|
449
390
|
newset = @branchset.with_operational_attributes
|
|
450
|
-
newset.options[:select].
|
|
391
|
+
expect( newset.options[:select] ).to include( :+ )
|
|
451
392
|
end
|
|
452
393
|
|
|
453
394
|
|
|
@@ -462,15 +403,15 @@ describe Treequel::Branchset do
|
|
|
462
403
|
|
|
463
404
|
|
|
464
405
|
it "generates a valid filter string" do
|
|
465
|
-
@branchset.filter_string.
|
|
406
|
+
expect( @branchset.filter_string ).to eq( '(objectClass=*)' )
|
|
466
407
|
end
|
|
467
408
|
|
|
468
409
|
it "performs a search using the default filter and scope when all records are requested" do
|
|
469
|
-
@branch.
|
|
410
|
+
expect( @branch ).to receive( :search ).
|
|
470
411
|
with( :onelevel, @branchset.filter, @params ).
|
|
471
412
|
and_yield( :matching_branches )
|
|
472
413
|
|
|
473
|
-
@branchset.all.
|
|
414
|
+
expect( @branchset.all ).to eq( [:matching_branches] )
|
|
474
415
|
end
|
|
475
416
|
|
|
476
417
|
end
|
|
@@ -489,7 +430,7 @@ describe Treequel::Branchset do
|
|
|
489
430
|
end
|
|
490
431
|
|
|
491
432
|
before( :each ) do
|
|
492
|
-
@directory.
|
|
433
|
+
allow( @directory ).to receive( :registered_controls ).and_return([ @control ])
|
|
493
434
|
end
|
|
494
435
|
|
|
495
436
|
after( :each ) do
|
|
@@ -498,21 +439,21 @@ describe Treequel::Branchset do
|
|
|
498
439
|
|
|
499
440
|
it "extends instances of itself with any controls registered with its Branch's Directory" do
|
|
500
441
|
set = Treequel::Branchset.new( @branch )
|
|
501
|
-
set.
|
|
442
|
+
expect( set ).to respond_to( :yep )
|
|
502
443
|
end
|
|
503
444
|
|
|
504
445
|
it "appends client controls to search arguments" do
|
|
505
|
-
resultbranch =
|
|
446
|
+
resultbranch = double( "Result Branch" )
|
|
506
447
|
set = Treequel::Branchset.new( @branch )
|
|
507
448
|
|
|
508
449
|
@params[:server_controls] = [:server_control]
|
|
509
450
|
@params[:client_controls] = [:client_control]
|
|
510
451
|
|
|
511
|
-
@branch.
|
|
452
|
+
expect( @branch ).to receive( :search ).
|
|
512
453
|
with( Treequel::Branchset::DEFAULT_SCOPE, set.filter, @params ).
|
|
513
454
|
and_yield( resultbranch )
|
|
514
455
|
|
|
515
|
-
set.all.
|
|
456
|
+
expect( set.all ).to eq( [ resultbranch ] )
|
|
516
457
|
end
|
|
517
458
|
|
|
518
459
|
end
|