require 'test/unit' require 'passiveldap' require 'tests/user.rb' # tests class methods class Test_PassiveLDAP_Class < Test::Unit::TestCase # tests count method def test_count count = TestUser.count a = TestUser.new(12345) a.save! assert_equal(count+1,TestUser.count) a.destroy end # tests column_names method def test_column_names assert_equal(%w{id common_name surname mail other_mailbox}.sort,TestUser.column_names.sort) # test twice because of caching assert_equal(%w{id common_name surname mail other_mailbox}.sort,TestUser.column_names.sort) # test columns and columns_hash assert_equal(:integer,TestUser.columns_hash["id"].type) assert_equal(:string,TestUser.columns_hash["common_name"].type) assert_equal(:text,TestUser.columns_hash["other_mailbox"].type) end # tests exists? method def test_exists? a = TestUser.new(12345) a.save! assert(TestUser.exists?(12345), "User should exist") assert(TestUser.exists?(Net::LDAP::Filter.eq("uidnumber","12345")), "User should exist") a.destroy assert(!TestUser.exists?(12345), "User shouldn't exist") assert(!TestUser.exists?(Net::LDAP::Filter.eq("uidnumber","12345")), "User shouldn't exist") end # tests create def test_create TestUser.create(:id => 12345, :mail => "mail@mail.com") a = TestUser.new(12345) assert_equal("mail@mail.com",a.mail) a.destroy a = TestUser.create([{:id => 12345, :mail => "mail@mail.com"},{:id => 12346, :mail => "other@other.com"}]) assert_equal("mail@mail.com",a[0].mail) assert_equal("other@other.com",a[1].mail) a[0] = TestUser.new(12345) a[1] = TestUser.new(12346) assert_equal("mail@mail.com",a[0].mail) assert_equal("other@other.com",a[1].mail) a[0].destroy a[1].destroy end # tests delete def test_delete TestUser.create(:id => 12345) assert(TestUser.exists?(12345), "User should exist") TestUser.delete(12345) assert(!TestUser.exists?(12345), "User shouldn't exist") end # tests update def test_update TestUser.create([{:id => 12345},{:id=>12346}]) a = TestUser.update(12345, :mail => "other@mail.com") assert_equal("other@mail.com",a.mail) a = TestUser.update([12345,12346],[{:mail => "1@2.com"},{:mail => "2@1.com"}]) assert_equal("1@2.com",a[0].mail) assert_equal("2@1.com",a[1].mail) a[0].destroy a[1].destroy end end