require 'test/unit' require 'passiveldap' require 'tests/user.rb' # tests instance methods class Test_PassiveLDAP_Instance < Test::Unit::TestCase # tests distinguished name changeability def test_dn_change a = TestUser.new(12345) a.save! a = TestUser.new(12345) assert_raise(PassiveLDAP::DistinguishedNameException) { a.dn = "otherdn" } a.destroy a = TestUser.new(12345) assert_nothing_raised { a.dn = "otherdn" } end # tests old attribute getter method def test_get_old_attribute a = TestUser.new(12345) a.mail = "old@mail.com" a.save! a = TestUser.new(12345) a.mail = "new@mail.hu" assert_equal("old@mail.com",a.get_old_attribute(:mail)) assert_equal("new@mail.hu",a.mail) a.destroy end # tests attributes method def test_attributes a = TestUser.new(12345) a.destroy unless a.new_record? # cleared the record a = TestUser.new(12345) assert_equal({:id => 12345},a.attributes) end # tests attributes= method def test_attributes_set a = TestUser.new(12345) a.attributes= {:mail => "a@b.com", :other_mailbox => ["aa@bb.com"]} assert_equal("a@b.com",a.mail) assert_equal(["aa@bb.com"],a.other_mailbox) end # tests reload method def test_reload a = TestUser.new(12345) a.destroy unless a.new_record? a = TestUser.new(12345) a.other_mailbox = [ "one@two.com", "three@four.hu" ] a.mail = "first@second.com" a.save! a = TestUser.new(12345) assert_equal("first@second.com",a.mail) assert_equal([ "one@two.com", "three@four.hu" ].sort,a.other_mailbox.sort) a.other_mailbox = [ "one@two.com" ] a.mail = "second@first.com" assert_equal("second@first.com",a.mail) assert_equal([ "one@two.com"],a.other_mailbox) a.reload(:oldattr => true) assert_equal("second@first.com",a.mail) assert_equal([ "one@two.com"],a.other_mailbox) a.reload() assert_equal("first@second.com",a.mail) assert_equal([ "one@two.com", "three@four.hu" ].sort,a.other_mailbox.sort) a.destroy end # tests update_attribute* methods def test_updates a = TestUser.new(12345) a.destroy unless a.new_record? a = TestUser.new(12345) a.save! a.update_attribute(:mail,"mail@mail.com") assert_equal("mail@mail.com",a.mail) b = TestUser.new(12345) assert_equal("mail@mail.com",b.mail) b.destroy a = TestUser.new(12345) a.save! a.update_attributes(:mail => "mail@mail.com", :other_mailbox => ["other@other.com"]) assert_equal("mail@mail.com",a.mail) assert_equal(["other@other.com"],a.other_mailbox) b = TestUser.new(12345) assert_equal("mail@mail.com",b.mail) assert_equal(["other@other.com"],b.other_mailbox) b.destroy end end