test/test_base.rb in activeldap-0.10.0 vs test/test_base.rb in activeldap-1.0.0
- old
+ new
@@ -1,12 +1,44 @@
# -*- coding: utf-8 -*-
+
require 'al-test-utils'
class TestBase < Test::Unit::TestCase
include AlTestUtils
priority :must
+ def test_save_with_changes
+ make_temporary_user do |user, password|
+ user.cn += "!!!"
+ assert_true(detect_modify(user) {user.save})
+ end
+ end
+
+ def test_save_without_changes
+ make_temporary_user do |user, password|
+ assert_false(detect_modify(user) {user.save})
+ end
+ end
+
+ priority :normal
+ def test_normalize_dn_attribute
+ make_ou("Ous")
+ ou_class = Class.new(ActiveLdap::Base)
+ ou_class.ldap_mapping(:dn_attribute => "OU",
+ :prefix => "ou=OUS",
+ :classes => ["top", "organizationalUnit"])
+ ou_class.new("ou1").save!
+ ou_class.new("ou2").save!
+
+ ou1 = ou_class.find("ou1")
+ assert_equal("ou1", ou1.ou)
+ assert_equal("ou=ou1,#{ou_class.base}", ou1.dn)
+ ou2 = ou_class.find("ou2")
+ assert_equal("ou2", ou2.ou)
+ assert_equal("ou=ou2,#{ou_class.base}", ou2.dn)
+ end
+
def test_excluded_classes
mapping = {:classes => ["person"]}
person_class = Class.new(@user_class)
person_class.ldap_mapping(mapping)
@@ -34,11 +66,10 @@
no_simple_person_class.find(:all).collect(&:dn).sort)
end
end
end
- priority :normal
def test_new_with_dn
cn = "XXX"
dn = "cn=#{cn},#{@user_class.base}"
user = @user_class.new(ActiveLdap::DN.parse(dn))
assert_equal(cn, user.cn)
@@ -457,10 +488,20 @@
end
end
end
end
+ def test_ldap_mapping_symbol_dn_attribute
+ ou_class = Class.new(ActiveLdap::Base)
+ ou_class.ldap_mapping(:dn_attribute => :ou,
+ :prefix => "",
+ :classes => ["top", "organizationalUnit"])
+ assert_equal(["ou=Groups,#{current_configuration['base']}",
+ "ou=Users,#{current_configuration['base']}"],
+ ou_class.find(:all).collect(&:dn).sort)
+ end
+
def test_ldap_mapping_validation
ou_class = Class.new(ActiveLdap::Base)
assert_raises(ArgumentError) do
ou_class.ldap_mapping :dnattr => "ou"
end
@@ -591,7 +632,28 @@
:cn => new_cn2}])
assert_equal(new_sns, [new_user.sn, new_user2.sn])
assert_equal(new_cn2, new_user2.cn)
end
end
+ end
+
+ private
+ def detect_modify(object)
+ modify_called = false
+ singleton_class = class << object; self; end
+ singleton_class.send(:define_method, :modify_entry) do |*args|
+ dn, attributes, options = args
+ options ||= {}
+ modify_detector = Object.new
+ modify_detector.instance_variable_set("@called", false)
+ def modify_detector.modify(dn, entries, options)
+ @called = true
+ end
+ options[:connection] = modify_detector
+ result = super(dn, attributes, options)
+ modify_called = modify_detector.instance_variable_get("@called")
+ result
+ end
+ yield
+ modify_called
end
end