treequel 1.4.4 → 1.5.0pre445

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,7 +30,14 @@ describe Treequel::Model::ObjectClass do
30
30
  setup_logging( :fatal )
31
31
  end
32
32
 
33
+ before( :each ) do
34
+ @conn = mock( "ldap connection object" )
35
+ @directory = get_fixtured_directory( @conn )
36
+ Treequel::Model.directory = @directory
37
+ end
38
+
33
39
  after( :each ) do
40
+ Treequel::Model.directory = nil
34
41
  Treequel::Model.objectclass_registry.clear
35
42
  Treequel::Model.base_registry.clear
36
43
  end
@@ -167,16 +174,73 @@ describe Treequel::Model::ObjectClass do
167
174
  Treequel::Model.base_registry['ou=people,dc=acme,dc=com'].should_not include( mixin )
168
175
  MyModel.base_registry['ou=people,dc=acme,dc=com'].should include( mixin )
169
176
  end
177
+
178
+ it "re-registers bases that have already been declared when declaring a " +
179
+ "new model class" do
180
+ class MyModel < Treequel::Model; end
181
+
182
+ mixin = Module.new do
183
+ extend Treequel::Model::ObjectClass
184
+ model_bases 'ou=people,dc=acme,dc=com', 'ou=notpeople,dc=acme,dc=com'
185
+ model_class MyModel
186
+ end
187
+
188
+ Treequel::Model.base_registry['ou=people,dc=acme,dc=com'].should_not include( mixin )
189
+ MyModel.base_registry['ou=people,dc=acme,dc=com'].should include( mixin )
190
+ end
191
+
192
+ it "uses the directory associated with its model_class instead of Treequel::Model's if " +
193
+ "its model_class is set when creating a search Branchset" do
194
+ conn = mock( "ldap connection object" )
195
+ directory = get_fixtured_directory( conn )
196
+
197
+ class MyModel < Treequel::Model; end
198
+ MyModel.directory = directory
199
+
200
+ mixin = Module.new do
201
+ extend Treequel::Model::ObjectClass
202
+ model_objectclasses :inetOrgPerson
203
+ model_class MyModel
204
+ end
205
+
206
+ result = mixin.search
207
+
208
+ result.should be_a( Treequel::Branchset )
209
+ result.branch.directory.should == directory
210
+ end
211
+
212
+ it "delegates Branchset methods through the Branchset returned by its #search method" do
213
+ mixin = Module.new do
214
+ extend Treequel::Model::ObjectClass
215
+ model_objectclasses :inetOrgPerson
216
+ end
217
+
218
+ mixin.filter( :mail ).should be_a( Treequel::Branchset )
219
+ end
220
+
221
+ it "delegates Branchset Enumerable methods through the Branchset returned by its " +
222
+ "#search method" do
223
+
224
+ end
225
+
170
226
  end
171
227
 
172
228
  context "model instantiation" do
173
229
 
174
- before( :each ) do
175
- @conn = mock( "ldap connection object" )
176
- @directory = get_fixtured_directory( @conn )
230
+ it "can instantiate a new model object with its declared objectClasses" do
231
+ mixin = Module.new do
232
+ extend Treequel::Model::ObjectClass
233
+ model_objectclasses :inetOrgPerson
234
+ end
235
+
236
+ result = mixin.create( TEST_PERSON_DN )
237
+ result.should be_a( Treequel::Model )
238
+ result[:objectClass].should include( 'inetOrgPerson' )
239
+ result[TEST_PERSON_DN_ATTR].should == [ TEST_PERSON_DN_VALUE ]
177
240
  end
178
241
 
179
- it "can instantiate a new model object with its declared objectClasses" do
242
+ it "can instantiate a new model object with its declared objectClasses in a directory " +
243
+ "other than the one associated with its model_class" do
180
244
  mixin = Module.new do
181
245
  extend Treequel::Model::ObjectClass
182
246
  model_objectclasses :inetOrgPerson
@@ -194,7 +258,7 @@ describe Treequel::Model::ObjectClass do
194
258
  model_objectclasses :inetOrgPerson
195
259
  end
196
260
 
197
- result = mixin.create( @directory, TEST_PERSON_DN,
261
+ result = mixin.create( TEST_PERSON_DN,
198
262
  TEST_PERSON_DN_ATTR => [TEST_PERSON_DN_VALUE] )
199
263
  result.should be_a( Treequel::Model )
200
264
  result[:objectClass].should include( 'inetOrgPerson' )
@@ -208,7 +272,7 @@ describe Treequel::Model::ObjectClass do
208
272
  model_objectclasses :inetOrgPerson
209
273
  end
210
274
 
211
- result = mixin.create( @directory, TEST_PERSON_DN,
275
+ result = mixin.create( TEST_PERSON_DN,
212
276
  :objectClass => [:person, :inetOrgPerson] )
213
277
  result.should be_a( Treequel::Model )
214
278
  result[:objectClass].should have( 2 ).members
@@ -223,7 +287,7 @@ describe Treequel::Model::ObjectClass do
223
287
  model_objectclasses :ipHost, :ieee802Device, :device
224
288
  end
225
289
 
226
- result = mixin.create( @directory, TEST_HOST_MULTIVALUE_DN )
290
+ result = mixin.create( TEST_HOST_MULTIVALUE_DN )
227
291
  result.should be_a( Treequel::Model )
228
292
  result[:objectClass].should have( 3 ).members
229
293
  result[:objectClass].should include( 'ipHost', 'ieee802Device', 'device' )
@@ -236,6 +300,10 @@ describe Treequel::Model::ObjectClass do
236
300
  context "module that has one required objectClass declared" do
237
301
 
238
302
  before( :each ) do
303
+ @conn = mock( "ldap connection object" )
304
+ @directory = get_fixtured_directory( @conn )
305
+ Treequel::Model.directory = @directory
306
+
239
307
  @mixin = Module.new do
240
308
  extend Treequel::Model::ObjectClass
241
309
  model_objectclasses :inetOrgPerson
@@ -257,16 +325,26 @@ describe Treequel::Model::ObjectClass do
257
325
  should_not include( @mixin )
258
326
  end
259
327
 
260
- it "can set up a search for applicable entries given a Treequel::Directory to " +
261
- "search" do
262
- directory = mock( "Treequel directory", :registered_controls => [] )
263
- directory.should_receive( :base_dn ).and_return( TEST_BASE_DN )
328
+ it "can create a Branchset that will search for applicable entries" do
329
+ result = @mixin.search
330
+
331
+ result.should be_a( Treequel::Branchset )
332
+ result.base_dn.should == TEST_BASE_DN
333
+ result.filter.to_s.should == '(objectClass=inetOrgPerson)'
334
+ result.branch.directory.should == @directory
335
+ end
336
+
337
+ it "can create a Branchset that will search for applicable entries in a Directory other " +
338
+ "than the one set for Treequel::Model" do
339
+ conn = mock( "second ldap connection object" )
340
+ directory = get_fixtured_directory( conn )
264
341
 
265
342
  result = @mixin.search( directory )
266
343
 
267
344
  result.should be_a( Treequel::Branchset )
268
345
  result.base_dn.should == TEST_BASE_DN
269
346
  result.filter.to_s.should == '(objectClass=inetOrgPerson)'
347
+ result.branch.directory.should == directory
270
348
  end
271
349
 
272
350
  end
@@ -297,16 +375,26 @@ describe Treequel::Model::ObjectClass do
297
375
  should_not include( @mixin )
298
376
  end
299
377
 
300
- it "can set up a search for applicable entries given a Treequel::Directory to " +
301
- "search" do
302
- directory = mock( "Treequel directory", :registered_controls => [] )
303
- directory.should_receive( :base_dn ).and_return( TEST_BASE_DN )
378
+ it "can create a Branchset that will search for applicable entries" do
379
+ result = @mixin.search
380
+
381
+ result.should be_a( Treequel::Branchset )
382
+ result.base_dn.should == TEST_BASE_DN
383
+ result.filter.to_s.should == '(&(objectClass=device)(objectClass=ipHost))'
384
+ result.branch.directory.should == @directory
385
+ end
386
+
387
+ it "can create a Branchset that will search for applicable entries in a Directory other " +
388
+ "than the one set for Treequel::Model" do
389
+ conn = mock( "second ldap connection object" )
390
+ directory = get_fixtured_directory( conn )
304
391
 
305
392
  result = @mixin.search( directory )
306
393
 
307
394
  result.should be_a( Treequel::Branchset )
308
395
  result.base_dn.should == TEST_BASE_DN
309
396
  result.filter.to_s.should == '(&(objectClass=device)(objectClass=ipHost))'
397
+ result.branch.directory.should == directory
310
398
  end
311
399
 
312
400
  end
@@ -336,15 +424,26 @@ describe Treequel::Model::ObjectClass do
336
424
  should_not include( @mixin )
337
425
  end
338
426
 
339
- it "can set up a search for applicable entries given a Treequel::Directory to " +
340
- "search" do
341
- directory = stub( "Treequel directory", :registered_controls => [] )
427
+ it "can create a Branchset that will search for applicable entries" do
428
+ result = @mixin.search
429
+
430
+ result.should be_a( Treequel::Branchset )
431
+ result.base_dn.should == TEST_PEOPLE_DN
432
+ result.filter.to_s.should == '(objectClass=*)'
433
+ result.branch.directory.should == @directory
434
+ end
435
+
436
+ it "can create a Branchset that will search for applicable entries in a Directory other " +
437
+ "than the one set for Treequel::Model" do
438
+ conn = mock( "second ldap connection object" )
439
+ directory = get_fixtured_directory( conn )
342
440
 
343
441
  result = @mixin.search( directory )
344
442
 
345
443
  result.should be_a( Treequel::Branchset )
346
444
  result.base_dn.should == TEST_PEOPLE_DN
347
445
  result.filter.to_s.should == '(objectClass=*)'
446
+ result.branch.directory.should == directory
348
447
  end
349
448
 
350
449
  end
@@ -376,17 +475,32 @@ describe Treequel::Model::ObjectClass do
376
475
  should_not include( @mixin )
377
476
  end
378
477
 
379
- it "can set up a search for applicable entries given a Treequel::Directory to " +
380
- "search" do
381
- directory = stub( "Treequel directory", :registered_controls => [] )
478
+ it "can create a BranchCollection that will search for applicable entries" do
479
+ result = @mixin.search
480
+
481
+ result.should be_a( Treequel::BranchCollection )
482
+ result.base_dns.should have( 2 ).members
483
+ result.base_dns.should include( TEST_HOSTS_DN, TEST_SUBHOSTS_DN )
484
+ result.branchsets.each do |brset|
485
+ brset.filter_string.should == '(objectClass=*)'
486
+ brset.branch.directory.should == @directory
487
+ end
488
+ end
489
+
490
+ it "can create a BranchCollection that will search for applicable entries in a Directory " +
491
+ " other than the one set for Treequel::Model" do
492
+ conn = mock( "second ldap connection object" )
493
+ directory = get_fixtured_directory( conn )
382
494
 
383
495
  result = @mixin.search( directory )
384
496
 
385
497
  result.should be_a( Treequel::BranchCollection )
386
498
  result.base_dns.should have( 2 ).members
387
499
  result.base_dns.should include( TEST_HOSTS_DN, TEST_SUBHOSTS_DN )
388
- result.branchsets.all? {|brset| brset.filter_string == '(objectClass=*)' }.
389
- should be_true()
500
+ result.branchsets.each do |brset|
501
+ brset.filter_string.should == '(objectClass=*)'
502
+ brset.branch.directory.should == directory
503
+ end
390
504
  end
391
505
 
392
506
  end
@@ -22,11 +22,13 @@ require 'treequel/model'
22
22
  describe Treequel::Model do
23
23
 
24
24
  before( :all ) do
25
+ GC.disable
25
26
  setup_logging( :fatal )
26
27
  end
27
28
 
28
29
  after( :all ) do
29
30
  reset_logging()
31
+ GC.enable
30
32
  end
31
33
 
32
34
  before( :each ) do
@@ -41,9 +43,22 @@ describe Treequel::Model do
41
43
  after( :each ) do
42
44
  Treequel::Model.objectclass_registry.clear
43
45
  Treequel::Model.base_registry.clear
46
+ Treequel::Model.directory = nil
44
47
  end
45
48
 
46
49
 
50
+ it "allows a Treequel::Directory object to be set as the default directory to use for searches" do
51
+ Treequel::Model.directory = @directory
52
+ @directory.results_class.should == Treequel::Model
53
+ end
54
+
55
+ it "can return a Treequel::Directory object configured to use the system directory if " +
56
+ "none has been set" do
57
+ Treequel.should_receive( :directory_from_config ).and_return( @directory )
58
+ Treequel::Model.directory.should == @directory
59
+ @directory.results_class.should == Treequel::Model
60
+ end
61
+
47
62
  it "knows which mixins should be applied for a single objectClass" do
48
63
  mixin = Module.new
49
64
  mixin.should_receive( :model_objectclasses ).at_least( :once ).
@@ -295,37 +310,8 @@ describe Treequel::Model do
295
310
 
296
311
  describe "objects loaded from entries" do
297
312
 
298
- before( :all ) do
299
- @entry = {
300
- 'dn' => ['uid=slappy,ou=people,dc=acme,dc=com'],
301
- 'uid' => ['slappy'],
302
- 'cn' => ['Slappy the Frog'],
303
- 'givenName' => ['Slappy'],
304
- 'sn' => ['Frog'],
305
- 'l' => ['a forest in England'],
306
- 'title' => ['Forest Fire Prevention Advocate'],
307
- 'displayName' => ['Slappy the Frog'],
308
- 'logonTime' => ['1293167318'],
309
- 'uidNumber' => ['1121'],
310
- 'gidNumber' => ['200'],
311
- 'homeDirectory' => ['/u/j/jrandom'],
312
- 'description' => [
313
- 'Smokey the Bear is much more intense in person.',
314
- 'Alright.'
315
- ],
316
- 'objectClass' => %w[
317
- top
318
- person
319
- organizationalPerson
320
- inetOrgPerson
321
- posixAccount
322
- shadowAccount
323
- apple-user
324
- ],
325
- }
326
- end
327
-
328
313
  before( :each ) do
314
+ @entry = TEST_PERSON_ENTRY.dup
329
315
  @obj = Treequel::Model.new_from_entry( @entry, @directory )
330
316
  end
331
317
 
@@ -523,7 +509,7 @@ describe Treequel::Model do
523
509
  it "reverts the attribute if its #revert method is called" do
524
510
  @conn.should_receive( :search_ext2 ).
525
511
  with( @entry['dn'].first, LDAP::LDAP_SCOPE_BASE, "(objectClass=*)" ).
526
- and_return([ @entry ])
512
+ and_return([ @entry.dup ])
527
513
 
528
514
  @obj.revert
529
515
 
@@ -533,8 +519,8 @@ describe Treequel::Model do
533
519
 
534
520
  it "updates the modified attribute when saved" do
535
521
  @conn.should_receive( :modify ).
536
- with( "uid=slappy,ou=people,dc=acme,dc=com",
537
- [ldap_mod_delete(:uid, 'slappy'), ldap_mod_add(:uid, 'slippy')] )
522
+ with( TEST_PERSON_DN,
523
+ [ ldap_mod_delete(:uid, 'slappy'), ldap_mod_add(:uid, 'slippy') ] )
538
524
  @obj.save
539
525
  end
540
526
 
@@ -636,7 +622,7 @@ describe Treequel::Model do
636
622
  it "reverts all of the attributes if its #revert method is called" do
637
623
  @conn.should_receive( :search_ext2 ).
638
624
  with( @entry['dn'].first, LDAP::LDAP_SCOPE_BASE, "(objectClass=*)" ).
639
- and_return([ @entry ])
625
+ and_return([ @entry.dup ])
640
626
 
641
627
  @obj.revert
642
628
 
metadata CHANGED
@@ -1,13 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treequel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 1923832739
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 4
9
- - 4
10
- version: 1.4.4
8
+ - 5
9
+ - 0
10
+ - pre
11
+ - 445
12
+ version: 1.5.0pre445
11
13
  platform: ruby
12
14
  authors:
13
15
  - Michael Granger
@@ -36,7 +38,7 @@ cert_chain:
36
38
  cmlhXe46pZNJgWKbxZah85jIjx95hR8vOI+NAM5iH9kOqK13DrxacTKPhqj5PjwF
37
39
  -----END CERTIFICATE-----
38
40
 
39
- date: 2011-02-10 00:00:00 -08:00
41
+ date: 2011-02-22 00:00:00 -08:00
40
42
  default_executable:
41
43
  dependencies:
42
44
  - !ruby/object:Gem::Dependency
@@ -47,12 +49,11 @@ dependencies:
47
49
  requirements:
48
50
  - - ~>
49
51
  - !ruby/object:Gem::Version
50
- hash: 23
52
+ hash: 13
51
53
  segments:
52
54
  - 1
53
55
  - 1
54
- - 2
55
- version: 1.1.2
56
+ version: "1.1"
56
57
  type: :runtime
57
58
  version_requirements: *id001
58
59
  - !ruby/object:Gem::Dependency
@@ -63,12 +64,11 @@ dependencies:
63
64
  requirements:
64
65
  - - ~>
65
66
  - !ruby/object:Gem::Version
66
- hash: 45
67
+ hash: 25
67
68
  segments:
68
69
  - 0
69
70
  - 9
70
- - 11
71
- version: 0.9.11
71
+ version: "0.9"
72
72
  type: :runtime
73
73
  version_requirements: *id002
74
74
  - !ruby/object:Gem::Dependency
@@ -127,12 +127,11 @@ dependencies:
127
127
  requirements:
128
128
  - - ~>
129
129
  - !ruby/object:Gem::Version
130
- hash: 17
130
+ hash: 13
131
131
  segments:
132
132
  - 0
133
133
  - 3
134
- - 1
135
- version: 0.3.1
134
+ version: "0.3"
136
135
  type: :development
137
136
  version_requirements: *id006
138
137
  - !ruby/object:Gem::Dependency
@@ -143,12 +142,11 @@ dependencies:
143
142
  requirements:
144
143
  - - ~>
145
144
  - !ruby/object:Gem::Version
146
- hash: 55
145
+ hash: 25
147
146
  segments:
148
147
  - 0
149
148
  - 9
150
- - 6
151
- version: 0.9.6
149
+ version: "0.9"
152
150
  type: :development
153
151
  version_requirements: *id007
154
152
  - !ruby/object:Gem::Dependency
@@ -159,12 +157,11 @@ dependencies:
159
157
  requirements:
160
158
  - - ~>
161
159
  - !ruby/object:Gem::Version
162
- hash: 25
160
+ hash: 9
163
161
  segments:
164
162
  - 0
165
163
  - 1
166
- - 1
167
- version: 0.1.1
164
+ version: "0.1"
168
165
  type: :development
169
166
  version_requirements: *id008
170
167
  - !ruby/object:Gem::Dependency
@@ -175,46 +172,59 @@ dependencies:
175
172
  requirements:
176
173
  - - ~>
177
174
  - !ruby/object:Gem::Version
178
- hash: 31
175
+ hash: 11
179
176
  segments:
180
177
  - 2
181
178
  - 4
182
- - 0
183
- version: 2.4.0
179
+ version: "2.4"
184
180
  type: :development
185
181
  version_requirements: *id009
186
182
  - !ruby/object:Gem::Dependency
187
- name: sysexits
183
+ name: sequel
188
184
  prerelease: false
189
185
  requirement: &id010 !ruby/object:Gem::Requirement
190
186
  none: false
191
187
  requirements:
192
188
  - - ~>
193
189
  - !ruby/object:Gem::Version
194
- hash: 19
190
+ hash: 47
191
+ segments:
192
+ - 3
193
+ - 20
194
+ version: "3.20"
195
+ type: :development
196
+ version_requirements: *id010
197
+ - !ruby/object:Gem::Dependency
198
+ name: sysexits
199
+ prerelease: false
200
+ requirement: &id011 !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ~>
204
+ - !ruby/object:Gem::Version
205
+ hash: 15
195
206
  segments:
196
207
  - 1
197
208
  - 0
198
- - 2
199
- version: 1.0.2
209
+ version: "1.0"
200
210
  type: :development
201
- version_requirements: *id010
211
+ version_requirements: *id011
202
212
  - !ruby/object:Gem::Dependency
203
213
  name: hoe
204
214
  prerelease: false
205
- requirement: &id011 !ruby/object:Gem::Requirement
215
+ requirement: &id012 !ruby/object:Gem::Requirement
206
216
  none: false
207
217
  requirements:
208
218
  - - ">="
209
219
  - !ruby/object:Gem::Version
210
- hash: 41
220
+ hash: 43
211
221
  segments:
212
222
  - 2
213
223
  - 9
214
- - 1
215
- version: 2.9.1
224
+ - 0
225
+ version: 2.9.0
216
226
  type: :development
217
- version_requirements: *id011
227
+ version_requirements: *id012
218
228
  description: |-
219
229
  Treequel is an LDAP toolkit for Ruby. It is intended to allow quick, easy
220
230
  access to LDAP directories in a manner consistent with LDAP's hierarchical,
@@ -312,7 +322,7 @@ post_install_message: |-
312
322
  If you want to use the included 'treequel' LDAP shell, you'll need to install
313
323
  the following libraries as well:
314
324
 
315
- - termios
325
+ - ruby-termios
316
326
  - ruby-terminfo
317
327
  - columnize
318
328
  - sysexits
@@ -350,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
360
  requirements: []
351
361
 
352
362
  rubyforge_project: treequel
353
- rubygems_version: 1.4.2
363
+ rubygems_version: 1.5.2
354
364
  signing_key:
355
365
  specification_version: 3
356
366
  summary: Treequel is an LDAP toolkit for Ruby