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
|
2014-01-27 05:22:26 -05:00
|
|
|
Topic.clear_validators!
|
2009-12-23 07:30:58 -05:00
|
|
|
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
|
2013-05-01 20:10:06 -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
|
2013-05-01 20:10:06 -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
|
2014-01-27 13:43:35 -05:00
|
|
|
Person.clear_validators!
|
2009-03-20 18:21:27 -04:00
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|