2009-03-20 11:07:49 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'cases/helper'
|
|
|
|
|
|
|
|
require 'models/topic'
|
|
|
|
require 'models/reply'
|
2009-03-20 18:21:27 -04:00
|
|
|
require 'models/person'
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
class AcceptanceValidationTest < ActiveModel::TestCase
|
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
def teardown
|
|
|
|
Topic.reset_callbacks(:validate)
|
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
def test_terms_of_service_agreement_no_acceptance
|
2010-05-08 16:27:49 -04:00
|
|
|
Topic.validates_acceptance_of(:terms_of_service)
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2010-05-08 16:27:49 -04:00
|
|
|
t = Topic.new("title" => "We should not be confirmed")
|
|
|
|
assert t.valid?
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_terms_of_service_agreement
|
2010-05-08 16:27:49 -04:00
|
|
|
Topic.validates_acceptance_of(:terms_of_service)
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2010-05-08 16:27:49 -04:00
|
|
|
t = Topic.new("title" => "We should be confirmed","terms_of_service" => "")
|
|
|
|
assert t.invalid?
|
2009-03-20 11:07:49 -04:00
|
|
|
assert_equal ["must be accepted"], t.errors[:terms_of_service]
|
|
|
|
|
|
|
|
t.terms_of_service = "1"
|
2010-05-08 16:27:49 -04:00
|
|
|
assert t.valid?
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_eula
|
2010-05-08 16:27:49 -04:00
|
|
|
Topic.validates_acceptance_of(:eula, :message => "must be abided")
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2010-05-08 16:27:49 -04:00
|
|
|
t = Topic.new("title" => "We should be confirmed","eula" => "")
|
|
|
|
assert t.invalid?
|
2009-03-20 11:07:49 -04:00
|
|
|
assert_equal ["must be abided"], t.errors[:eula]
|
|
|
|
|
|
|
|
t.eula = "1"
|
2010-05-08 16:27:49 -04:00
|
|
|
assert t.valid?
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_terms_of_service_agreement_with_accept_value
|
2010-05-08 16:27:49 -04:00
|
|
|
Topic.validates_acceptance_of(:terms_of_service, :accept => "I agree.")
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2010-05-08 16:27:49 -04:00
|
|
|
t = Topic.new("title" => "We should be confirmed", "terms_of_service" => "")
|
|
|
|
assert t.invalid?
|
2009-03-20 11:07:49 -04:00
|
|
|
assert_equal ["must be accepted"], t.errors[:terms_of_service]
|
|
|
|
|
|
|
|
t.terms_of_service = "I agree."
|
2010-05-08 16:27:49 -04:00
|
|
|
assert t.valid?
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|
|
|
|
|
2009-03-20 18:21:27 -04:00
|
|
|
def test_validates_acceptance_of_for_ruby_class
|
2009-12-23 07:30:58 -05:00
|
|
|
Person.validates_acceptance_of :karma
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
p = Person.new
|
|
|
|
p.karma = ""
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
assert p.invalid?
|
|
|
|
assert_equal ["must be accepted"], p.errors[:karma]
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
p.karma = "1"
|
|
|
|
assert p.valid?
|
|
|
|
ensure
|
|
|
|
Person.reset_callbacks(:validate)
|
2009-03-20 18:21:27 -04:00
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|