1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# encoding: utf-8
require 'cases/helper'
require 'cases/tests_database'
require 'models/topic'
require 'models/reply'
require 'models/developer'
require 'models/person'
class AcceptanceValidationTest < ActiveModel::TestCase
include ActiveModel::TestsDatabase
def teardown
Topic.reset_callbacks(:validate)
end
def test_terms_of_service_agreement_no_acceptance
Topic.validates_acceptance_of(:terms_of_service, :on => :create)
t = Topic.create("title" => "We should not be confirmed")
assert t.save
end
def test_terms_of_service_agreement
Topic.validates_acceptance_of(:terms_of_service, :on => :create)
t = Topic.create("title" => "We should be confirmed","terms_of_service" => "")
assert !t.save
assert_equal ["must be accepted"], t.errors[:terms_of_service]
t.terms_of_service = "1"
assert t.save
end
def test_eula
Topic.validates_acceptance_of(:eula, :message => "must be abided", :on => :create)
t = Topic.create("title" => "We should be confirmed","eula" => "")
assert !t.save
assert_equal ["must be abided"], t.errors[:eula]
t.eula = "1"
assert t.save
end
def test_terms_of_service_agreement_with_accept_value
Topic.validates_acceptance_of(:terms_of_service, :on => :create, :accept => "I agree.")
t = Topic.create("title" => "We should be confirmed", "terms_of_service" => "")
assert !t.save
assert_equal ["must be accepted"], t.errors[:terms_of_service]
t.terms_of_service = "I agree."
assert t.save
end
def test_validates_acceptance_of_for_ruby_class
Person.validates_acceptance_of :karma
p = Person.new
p.karma = ""
assert p.invalid?
assert_equal ["must be accepted"], p.errors[:karma]
p.karma = "1"
assert p.valid?
ensure
Person.reset_callbacks(:validate)
end
end
|