[activeldap-commit] [ruby-activeldap] r1102 committed - * accept not only foreign class but also DN attribute value...

codesite-noreply at google.com codesite-noreply at google.com
Sat Sep 26 08:49:07 EDT 2009


Revision: 1102
Author: koutou
Date: Sat Sep 26 05:48:03 2009
Log: * accept not only foreign class but also DN attribute value
   on belongs_to(:many) assignment.

http://code.google.com/p/ruby-activeldap/source/detail?r=1102

Modified:
  /trunk/lib/active_ldap/association/belongs_to_many.rb
  /trunk/test/test_associations.rb

=======================================
--- /trunk/lib/active_ldap/association/belongs_to_many.rb	Sun Aug 16  
00:41:04 2009
+++ /trunk/lib/active_ldap/association/belongs_to_many.rb	Sat Sep 26  
05:48:03 2009
@@ -5,6 +5,8 @@
      class BelongsToMany < Collection
        private
        def insert_entry(entry)
+        _foreign_class = foreign_class
+        entry = _foreign_class.find(entry) unless  
entry.is_a?(_foreign_class)
          old_value = entry[@options[:many], true]
          primary_key_name = @options[:primary_key_name]
          if primary_key_name == "dn"
@@ -21,7 +23,9 @@
        end

        def delete_entries(entries)
+          _foreign_class = foreign_class
          entries.each do |entry|
+          entry = _foreign_class.find(entry) unless  
entry.is_a?(_foreign_class)
            old_value = entry[@options[:many], true]
            primary_key_name = @options[:primary_key_name]
            if primary_key_name == "dn"
=======================================
--- /trunk/test/test_associations.rb	Sun Aug 16 00:41:04 2009
+++ /trunk/test/test_associations.rb	Sat Sep 26 05:48:03 2009
@@ -4,6 +4,28 @@
    include AlTestUtils

    priority :must
+  def test_belongs_to_add_with_string
+    make_temporary_user do |user,|
+      make_temporary_group do |group1|
+        make_temporary_group do |group2|
+          assert_equal([[], []],
+                       [group1.members.collect(&:cn),
+                        group2.members.collect(&:cn)])
+
+          user.groups = [group1.cn, group2.cn]
+          user.save!
+
+          group1.reload
+          group2.reload
+          assert_equal([[user.cn], [user.cn]],
+                       [group1.members.collect(&:cn),
+                        group2.members.collect(&:cn)])
+        end
+      end
+    end
+  end
+
+  priority :normal
    def test_has_many_delete_required_attribute
      make_temporary_group do |group|
        make_temporary_user do |user,|
@@ -15,7 +37,6 @@
      end
    end

-  priority :normal
    def test_to_xml
      make_temporary_user do |user,|
        make_temporary_group do |group1|


More information about the ruby-activeldap-commit mailing list