require File.dirname(__FILE__) + '/../test_helper' # Set salt to 'change-me' because thats what the fixtures assume. # Domain.salt = 'change-me' class DomainTest < Test::Unit::TestCase fixtures :domains def setup @testdomain = Domain.find 1 @domains=@loaded_fixtures["domains"] @domain_testdomain=@domains["testdomain"] end def test_aa_break_everything @testdomain.destroy assert_raise ActiveRecord::RecordNotFound do Domain.find @testdomain.id end end def test_find domain_1 = Domain.find 1 assert domain_1 assert_equal @domain_testdomain["name"], domain_1.name assert_equal @domain_testdomain["password"], domain_1.password assert_equal @domain_testdomain["id"], domain_1.id end def test_auth_notfound assert_nil Domain.authenticate("nontest.domain", "foobar") end def test_auth domain_1 = Domain.find 1 assert domain_1 domain_testdomain = Domain.authenticate "test.domain", "foobar" assert domain_testdomain assert_equal domain_1, domain_testdomain end def test_disallowed_passwords u = Domain.new u.name = "nonbob" u.password = u.password_confirmation = "tiny" assert !u.save assert u.errors.invalid?('password') u.password = u.password_confirmation = "hugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehugehuge" assert !u.save assert u.errors.invalid?('password') u.password = u.password_confirmation = "" assert !u.save assert u.errors.invalid?('password') u.password = u.password_confirmation = "bobs_secure_password" assert u.save # assert u.errors.empty? end def test_bad_names u = Domain.new u.password = u.password_confirmation = "bobs_secure_password" u.name = "x" assert !u.save assert u.errors.invalid?('name') u.name = "hugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhugebobhug" assert !u.save assert u.errors.invalid?('name') u.name = "" assert !u.save assert u.errors.invalid?('name') u.name = "okbob" assert u.save # assert u.errors.empty? end def test_collision u = Domain.new u.name = "test.domain" u.password = u.password_confirmation = "bobs_secure_password" assert !u.save end def test_create u = Domain.new u.name = "nonexistingbob" u.password = u.password_confirmation = "bobs_secure_password" assert u.save end def test_sha1 u = Domain.new u.name = "nonexistingbob" u.password = u.password_confirmation = "bobs_secure_password" assert u.save assert_equal '826005bc4b82d02a3e6097556a45083375fe556c', u.password end # def test_change_nothing # d = Domain.find_by_name "test.domain" # assert_equal 'e7ce1e2e20ec9f11ce8e86c9c47ab9911c1d221e', d.password # d.password = d.password_confirmation = nil # result = d.save # unless result == true # d.errors.each do |thing, string| # puts "#{thing}: #{string}" # end # end # assert result # end end