Sha256: e447b9e31a3c231d2eb8b0d2568557624db21b8979cb324bb44aed88f3fbd0f5

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
passiveldap-0.1 tests/tc_validate.rb