require 'test/unit' require 'passiveldap' require 'tests/user.rb' # tests whether ActiveRecord::Validation integration works # # also tests some advanced PassiveLDAP mechanism, like array_separators, or # type conversions class Test_PassiveLDAP_Validation < Test::Unit::TestCase # tests validations def test_validated_user a = ValidatedUser.new(12345) a.destroy unless a.new_record? assert_raise(ActiveRecord::RecordInvalid) { a.save! } a.mail = "abcd" a.description = "Hi!" assert_raise(ActiveRecord::RecordInvalid) { a.save! } a.mail = "ab@bc.de" assert_nothing_raised { a.save! } a.other_mailbox = "one@mail.com\ntwo@mail.com" assert_nothing_raised { a.save! } a.other_mailbox = "notanemail\ntwo@gmail.com" assert_raise(ActiveRecord::RecordInvalid) { a.save! } a.destroy end # tests array_separator def test_array_separator a = ValidatedUser.new(12345) a.other_mailbox = "one@mail.com\ntwo@mail.com" assert_equal(["one@mail.com","two@mail.com"].sort,a.get_attribute(:other_mailbox).sort) a.set_attribute(:other_mailbox,["ab@cd.ef","gh@ij.kl"]) assert((a.other_mailbox == "ab@cd.ef\ngh@ij.kl") || (a.other_mailbox == "gh@ij.kl\nab@cd.ef"),"Array to string conversion unsuccesful!") end def test_type_conversion a = ValidatedUser.new(12345) a.givenname = "Mr. Doe" assert_equal("Doe",a.get_attribute(:givenname)) a.set_attribute(:givenname, "Joe") assert_equal("Mr. Joe",a.givenname) end end