activeldap 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGES +648 -567
  2. data/README +53 -48
  3. data/Rakefile +25 -53
  4. data/TODO +2 -0
  5. data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
  6. data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
  7. data/examples/al-admin/app/controllers/application_controller.rb +1 -1
  8. data/examples/al-admin/app/views/_entry/_attributes_information.html.erb +7 -1
  9. data/examples/al-admin/app/views/users/_attributes_update_form.html.erb +13 -1
  10. data/examples/al-admin/config/environment.rb +2 -3
  11. data/lib/active_ldap.rb +103 -98
  12. data/lib/active_ldap/association/belongs_to_many.rb +7 -7
  13. data/lib/active_ldap/association/has_many.rb +4 -4
  14. data/lib/active_ldap/associations.rb +29 -5
  15. data/lib/active_ldap/attributes.rb +5 -1
  16. data/lib/active_ldap/base.rb +17 -13
  17. data/lib/active_ldap/configuration.rb +3 -4
  18. data/lib/active_ldap/connection.rb +3 -3
  19. data/lib/active_ldap/get_text/parser.rb +4 -2
  20. data/lib/active_ldap/helper.rb +59 -0
  21. data/lib/active_ldap/operations.rb +15 -10
  22. data/lib/active_ldap/xml.rb +22 -30
  23. data/po/en/active-ldap.po +221 -154
  24. data/po/ja/active-ldap.po +237 -178
  25. data/test-unit/History.txt +26 -0
  26. data/test-unit/Manifest.txt +1 -1
  27. data/test-unit/README.txt +1 -0
  28. data/test-unit/Rakefile +6 -1
  29. data/test-unit/lib/test/unit/autorunner.rb +6 -0
  30. data/test-unit/lib/test/unit/testcase.rb +101 -36
  31. data/test-unit/test/{test_testcase.rb → test-testcase.rb} +30 -1
  32. data/test-unit/test/test_assertions.rb +1 -1
  33. data/test/al-test-utils.rb +3 -1
  34. data/test/test_associations.rb +75 -6
  35. data/test/test_base.rb +45 -3
  36. metadata +75 -45
  37. data/examples/al-admin/config/initializers/gettext.rb +0 -15
@@ -1,3 +1,29 @@
1
+ === 2.0.3 / 2009-07-17
2
+
3
+ * 6 major enhancements
4
+ * add assert_predicate.
5
+ * add assert_not_predicate.
6
+ * [#24210] assert_kind_of supports an array of classes or modules.
7
+ [Daniel Berger]
8
+ * assert_instance_of supports an array of classes or modules.
9
+ * add --default-priority option.
10
+ * [#26627] add --order option. [Daniel Berger]
11
+
12
+ * 4 minor enhancements
13
+ * use yellow foreground + black background for error.
14
+ * don't show diff for long string.
15
+ * accept "*term-color" TERM environment as colorizable terminal.
16
+ (e.g. Apple's Terminal)
17
+ * [#26268] add a workaround for test-spec's after_all. [Angelo Lakra]
18
+
19
+ * 1 bug fix
20
+ * [#23586] re-support ruby 1.9.1. [Diego Pettenò]
21
+
22
+ * Thanks
23
+ * Diego Pettenò
24
+ * Daniel Berger
25
+ * Angelo Lakra
26
+
1
27
  === 2.0.2 / 2008-12-21
2
28
 
3
29
  * 2 major enhancements
@@ -66,10 +66,10 @@ test/test-notification.rb
66
66
  test/test-omission.rb
67
67
  test/test-pending.rb
68
68
  test/test-priority.rb
69
+ test/test-testcase.rb
69
70
  test/test_assertions.rb
70
71
  test/test_error.rb
71
72
  test/test_failure.rb
72
- test/test_testcase.rb
73
73
  test/test_testresult.rb
74
74
  test/test_testsuite.rb
75
75
  test/testunit-test-util.rb
@@ -49,3 +49,4 @@ This software is distributed under the same terms as ruby.
49
49
  * Erik Hollensbe: Suggestions.
50
50
  * Bill Lear: A suggestion.
51
51
  * Diego Pettenò: A bug report.
52
+ * Angelo Lakra: A bug report.
@@ -1,12 +1,17 @@
1
1
  # -*- ruby -*-
2
2
 
3
3
  require 'rubygems'
4
+ gem 'rdoc'
4
5
  require 'hoe'
5
6
  require './lib/test/unit/version.rb'
6
7
 
8
+ ENV["NODOT"] = "yes"
9
+
7
10
  version = Test::Unit::VERSION
8
11
  ENV["VERSION"] = version
9
- Hoe.new('test-unit', version) do |p|
12
+ Hoe.spec('test-unit') do |p|
13
+ Hoe::Test::SUPPORTED_TEST_FRAMEWORKS[:testunit2] = "test/run-test.rb"
14
+ p.version = version
10
15
  p.developer('Kouhei Sutou', 'kou@cozmixng.org')
11
16
  p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
12
17
 
@@ -227,6 +227,12 @@ module Test
227
227
  load_config(file)
228
228
  end
229
229
 
230
+ o.on("--order=ORDER", TestCase::AVAILABLE_ORDERS,
231
+ "Run tests in a test case in ORDER order.",
232
+ "(#{keyword_display(TestCase::AVAILABLE_ORDERS)})") do |order|
233
+ TestCase.test_order = order
234
+ end
235
+
230
236
  ADDITIONAL_OPTIONS.each do |option_builder|
231
237
  option_builder.call(self, o)
232
238
  end
@@ -1,7 +1,9 @@
1
1
  #--
2
2
  #
3
3
  # Author:: Nathaniel Talbott.
4
- # Copyright:: Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
4
+ # Copyright::
5
+ # * Copyright (c) 2000-2003 Nathaniel Talbott. All rights reserved.
6
+ # * Copyright (c) 2008-2009 Kouhei Sutou <tt><kou@clear-code.com></tt>
5
7
  # License:: Ruby license.
6
8
 
7
9
  require 'test/unit/attribute'
@@ -60,14 +62,14 @@ module Test
60
62
  # end
61
63
  #
62
64
  # Here is a call order:
63
- # * startup
64
- # * setup
65
- # * test_my_method1
66
- # * teardown
67
- # * setup
68
- # * test_my_method2
69
- # * teardown
70
- # * shutdown
65
+ # * startup
66
+ # * setup
67
+ # * test_my_method1
68
+ # * teardown
69
+ # * setup
70
+ # * test_my_method2
71
+ # * teardown
72
+ # * shutdown
71
73
  class TestCase
72
74
  include Attribute
73
75
  include Fixture
@@ -81,24 +83,29 @@ module Test
81
83
  include Assertions
82
84
  include Util::BacktraceFilter
83
85
 
84
- STARTED = name + "::STARTED"
85
- FINISHED = name + "::FINISHED"
86
+ STARTED = name + "::STARTED" # :nodoc:
87
+ FINISHED = name + "::FINISHED" # :nodoc:
86
88
 
87
- DESCENDANTS = []
89
+ DESCENDANTS = [] # :nodoc:
90
+ AVAILABLE_ORDERS = [:alphabetic, :random, :defined] # :nodoc:
88
91
 
89
92
  class << self
90
- def inherited(sub_class)
93
+ def inherited(sub_class) # :nodoc:
91
94
  DESCENDANTS << sub_class
92
95
  end
93
96
 
97
+ @@added_methods = []
98
+ def method_added(name) # :nodoc:
99
+ super
100
+ @@added_methods << name.to_s
101
+ end
102
+
94
103
  # Rolls up all of the test* methods in the fixture into
95
104
  # one suite, creating a new instance of the fixture for
96
105
  # each method.
97
106
  def suite
98
- method_names = public_instance_methods(true).collect {|name| name.to_s}
99
- tests = method_names.delete_if {|method_name| method_name !~ /^test./}
100
107
  suite = TestSuite.new(name, self)
101
- tests.sort.each do |test|
108
+ collect_test_names.each do |test|
102
109
  catch(:invalid_test) do
103
110
  suite << new(test)
104
111
  end
@@ -137,11 +144,11 @@ module Test
137
144
  # end
138
145
  #
139
146
  # Here is a call order:
140
- # * startup
141
- # * setup
142
- # * test_my_class1 (or test_my_class2)
143
- # * setup
144
- # * test_my_class2 (or test_my_class1)
147
+ # * startup
148
+ # * setup
149
+ # * test_my_class1 (or test_my_class2)
150
+ # * setup
151
+ # * test_my_class2 (or test_my_class1)
145
152
  #
146
153
  # Note that you should not assume test order. Tests
147
154
  # should be worked in any order.
@@ -173,16 +180,74 @@ module Test
173
180
  # end
174
181
  #
175
182
  # Here is a call order:
176
- # * test_my_class1 (or test_my_class2)
177
- # * teardown
178
- # * test_my_class2 (or test_my_class1)
179
- # * teardown
180
- # * shutdown
183
+ # * test_my_class1 (or test_my_class2)
184
+ # * teardown
185
+ # * test_my_class2 (or test_my_class1)
186
+ # * teardown
187
+ # * shutdown
181
188
  #
182
189
  # Note that you should not assume test order. Tests
183
190
  # should be worked in any order.
184
191
  def shutdown
185
192
  end
193
+
194
+ @@test_order = AVAILABLE_ORDERS.first
195
+
196
+ # Returns the current test order. This returns
197
+ # +:alphabetic+ by default.
198
+ def test_order
199
+ @@test_order
200
+ end
201
+
202
+ # Sets the current test order.
203
+ #
204
+ # Here are the available _order_:
205
+ # [:alphabetic]
206
+ # Default. Tests are sorted in alphabetic order.
207
+ # [:random]
208
+ # Tests are sorted in random order.
209
+ # [:defined]
210
+ # Tests are sorted in defined order.
211
+ def test_order=(order)
212
+ @@test_order = order
213
+ end
214
+
215
+ # :stopdoc:
216
+ private
217
+ def collect_test_names
218
+ method_names = public_instance_methods(true).collect do |name|
219
+ name.to_s
220
+ end
221
+ test_names = method_names.find_all do |method_name|
222
+ method_name =~ /^test./
223
+ end
224
+ send("sort_test_names_in_#{test_order}_order", test_names)
225
+ end
226
+
227
+ def sort_test_names_in_alphabetic_order(test_names)
228
+ test_names.sort
229
+ end
230
+
231
+ def sort_test_names_in_random_order(test_names)
232
+ test_names.sort_by {rand(test_names.size)}
233
+ end
234
+
235
+ def sort_test_names_in_defined_order(test_names)
236
+ test_names.sort do |test1, test2|
237
+ test1_defined_order = @@added_methods.index(test1)
238
+ test2_defined_order = @@added_methods.index(test2)
239
+ if test1_defined_order and test2_defined_order
240
+ test1_defined_order <=> test2_defined_order
241
+ elsif test1_defined_order
242
+ 1
243
+ elsif test2_defined_order
244
+ -1
245
+ else
246
+ test1 <=> test2
247
+ end
248
+ end
249
+ end
250
+ # :startdoc:
186
251
  end
187
252
 
188
253
  attr_reader :method_name
@@ -225,7 +290,7 @@ module Test
225
290
  result.add_run
226
291
  yield(FINISHED, name)
227
292
  ensure
228
- @_result = nil
293
+ # @_result = nil # For test-spec's after_all :<
229
294
  end
230
295
  end
231
296
 
@@ -255,10 +320,10 @@ module Test
255
320
  # end
256
321
  #
257
322
  # Here is a call order:
258
- # * setup
259
- # * my_setup1
260
- # * my_setup2
261
- # * test_my_class
323
+ # * setup
324
+ # * my_setup1
325
+ # * my_setup2
326
+ # * test_my_class
262
327
  def setup
263
328
  end
264
329
 
@@ -288,13 +353,13 @@ module Test
288
353
  # end
289
354
  #
290
355
  # Here is a call order:
291
- # * test_my_class
292
- # * my_teardown2
293
- # * my_teardown1
294
- # * teardown
356
+ # * test_my_class
357
+ # * my_teardown2
358
+ # * my_teardown1
359
+ # * teardown
295
360
  def teardown
296
361
  end
297
-
362
+
298
363
  def default_test
299
364
  flunk("No tests were specified")
300
365
  end
@@ -6,7 +6,7 @@ require 'test/unit'
6
6
 
7
7
  module Test
8
8
  module Unit
9
- class TC_TestCase < TestCase
9
+ class TestTestCase < TestCase
10
10
  def test_creation
11
11
  tc = Class.new(TestCase) do
12
12
  def test_with_arguments(arg1, arg2)
@@ -468,11 +468,40 @@ module Test
468
468
  end
469
469
  end
470
470
 
471
+ def test_defined_order
472
+ keep_test_order do
473
+ test_case = Class.new(Test::Unit::TestCase) do
474
+ def test_z
475
+ end
476
+
477
+ def test_1
478
+ end
479
+
480
+ def test_a
481
+ end
482
+ end
483
+
484
+ assert_equal(["test_1", "test_a", "test_z"],
485
+ test_case.suite.tests.collect {|test| test.method_name})
486
+
487
+ test_case.test_order = :defined
488
+ assert_equal(["test_z", "test_1", "test_a"],
489
+ test_case.suite.tests.collect {|test| test.method_name})
490
+ end
491
+ end
492
+
471
493
  private
472
494
  def check(message, passed)
473
495
  add_assertion
474
496
  raise AssertionFailedError.new(message) unless passed
475
497
  end
498
+
499
+ def keep_test_order
500
+ order = TestCase.test_order
501
+ yield
502
+ ensure
503
+ TestCase.test_order = order
504
+ end
476
505
  end
477
506
  end
478
507
  end
@@ -428,7 +428,7 @@ EOM
428
428
 
429
429
  different_error_class = Class.new(StandardError)
430
430
  message = <<-EOM
431
- <\#<Class:0x[a-f\\d]+>\\("Error"\\)> exception expected but was
431
+ <\#<Class:[xa-f\\d]+>\\("Error"\\)> exception expected but was
432
432
  Class: <RuntimeError>
433
433
  Message: <"Error">
434
434
  EOM
@@ -58,7 +58,9 @@ module AlTestUtils
58
58
  unless File.exist?(@config_file)
59
59
  raise "config file for testing doesn't exist: #{@config_file}"
60
60
  end
61
- config = YAML.load(ERB.new(File.read(@config_file)).result)
61
+ erb = ERB.new(File.read(@config_file))
62
+ erb.filename = @config_file
63
+ config = YAML.load(erb.result)
62
64
  _adapter = adapter
63
65
  config.each do |key, value|
64
66
  value[:adapter] = _adapter if _adapter
@@ -4,6 +4,59 @@ class TestAssociations < Test::Unit::TestCase
4
4
  include AlTestUtils
5
5
 
6
6
  priority :must
7
+ def test_has_many_delete_required_attribute
8
+ make_temporary_group do |group|
9
+ make_temporary_user do |user,|
10
+ user.primary_group = group
11
+ assert_raise(ActiveLdap::RequiredAttributeMissed) do
12
+ group.primary_members.delete(user)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ priority :normal
19
+ def test_to_xml
20
+ make_temporary_user do |user,|
21
+ make_temporary_group do |group1|
22
+ make_temporary_group do |group2|
23
+ user.groups = [group1, group2]
24
+ assert_equal(<<-EOX, user.groups.to_xml(:root => "groups"))
25
+ <?xml version="1.0" encoding="UTF-8"?>
26
+ <groups type="array">
27
+ <group>
28
+ <dn>#{group1.dn}</dn>
29
+ <cns type="array">
30
+ <cn>#{group1.cn}</cn>
31
+ </cns>
32
+ <gidNumber>#{group1.gid_number}</gidNumber>
33
+ <memberUids type="array">
34
+ <memberUid>#{user.cn}</memberUid>
35
+ </memberUids>
36
+ <objectClasses type="array">
37
+ <objectClass>posixGroup</objectClass>
38
+ </objectClasses>
39
+ </group>
40
+ <group>
41
+ <dn>#{group2.dn}</dn>
42
+ <cns type="array">
43
+ <cn>#{group2.cn}</cn>
44
+ </cns>
45
+ <gidNumber>#{group2.gid_number}</gidNumber>
46
+ <memberUids type="array">
47
+ <memberUid>#{user.cn}</memberUid>
48
+ </memberUids>
49
+ <objectClasses type="array">
50
+ <objectClass>posixGroup</objectClass>
51
+ </objectClasses>
52
+ </group>
53
+ </groups>
54
+ EOX
55
+ end
56
+ end
57
+ end
58
+ end
59
+
7
60
  def test_belongs_to_with_invalid_dn_attribute_value
8
61
  make_temporary_user do |user,|
9
62
  make_temporary_group do |group|
@@ -16,12 +69,28 @@ class TestAssociations < Test::Unit::TestCase
16
69
  end
17
70
  end
18
71
 
19
- priority :normal
72
+ def test_belongs_to_foreign_key_before_1_1_0
73
+ ActiveSupport::Deprecation.silence do
74
+ @group_class.belongs_to :related_users, :many => "seeAlso",
75
+ :foreign_key => "dn"
76
+ end
77
+ @group_class.set_associated_class(:related_users, @user_class)
78
+ make_temporary_user do |user,|
79
+ make_temporary_group do |group|
80
+ user.see_also = group.dn
81
+ user.save!
82
+
83
+ group = @group_class.find(group.id)
84
+ assert_equal([user.dn], group.related_users.collect(&:dn))
85
+ end
86
+ end
87
+ end
88
+
20
89
  def test_has_many_wrap_with_nonexistent_entry
21
90
  @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
22
91
  @user_class.set_associated_class(:references, @group_class)
23
92
  @group_class.belongs_to :related_users, :many => "seeAlso",
24
- :foreign_key => "dn"
93
+ :primary_key => "dn"
25
94
  @group_class.set_associated_class(:related_users, @user_class)
26
95
  make_temporary_user do |user,|
27
96
  make_temporary_group do |group1|
@@ -49,7 +118,7 @@ class TestAssociations < Test::Unit::TestCase
49
118
  @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
50
119
  @user_class.set_associated_class(:references, @group_class)
51
120
  @group_class.belongs_to :related_users, :many => "seeAlso",
52
- :foreign_key => "dn"
121
+ :primary_key => "dn"
53
122
  @group_class.set_associated_class(:related_users, @user_class)
54
123
  make_temporary_user do |user,|
55
124
  make_temporary_group do |group1|
@@ -87,7 +156,7 @@ class TestAssociations < Test::Unit::TestCase
87
156
  @user_class.has_many :references, :wrap => "seeAlso", :primary_key => "dn"
88
157
  @user_class.set_associated_class(:references, @group_class)
89
158
  @group_class.belongs_to :related_users, :many => "seeAlso",
90
- :foreign_key => "dn"
159
+ :primary_key => "dn"
91
160
  @group_class.set_associated_class(:related_users, @user_class)
92
161
  make_temporary_group do |group|
93
162
  make_temporary_user do |user1,|
@@ -125,7 +194,7 @@ class TestAssociations < Test::Unit::TestCase
125
194
  end
126
195
 
127
196
  def test_belongs_to_many_with_dn_key
128
- @user_class.belongs_to :dn_groups, :many => "memberUid", :foreign_key => "dn"
197
+ @user_class.belongs_to :dn_groups, :many => "memberUid", :primary_key => "dn"
129
198
  @user_class.set_associated_class(:dn_groups, @group_class)
130
199
  @group_class.has_many :dn_members, :wrap => "memberUid", :primary_key => "dn"
131
200
  @group_class.set_associated_class(:dn_members, @user_class)
@@ -292,8 +361,8 @@ class TestAssociations < Test::Unit::TestCase
292
361
  group_class.has_many :members, :class => @user_class, :wrap => "memberUid",
293
362
  :extend => mod
294
363
  group_class.has_many :primary_members, :class => @user_class,
295
- :foreign_key => "gidNumber",
296
364
  :primary_key => "gidNumber",
365
+ :foreign_key => "gidNumber",
297
366
  :extend => mod
298
367
  end
299
368
  end