-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathterms_version_test.rb
More file actions
89 lines (75 loc) · 2.17 KB
/
terms_version_test.rb
File metadata and controls
89 lines (75 loc) · 2.17 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require "test_helper"
class TermsVersionTest < ActiveSupport::TestCase
test "should be valid with valid attributes" do
terms_version = TermsVersion.new(
version: 2,
current_type: :current,
published_at: Date.today,
title: "Test Terms Version",
description: "Test Description"
)
assert terms_version.valid?
end
test "should have current_type enum" do
terms_version = TermsVersion.new(
version: 2,
current_type: :current,
published_at: Date.today
)
assert terms_version.current?
assert_not terms_version.uncurrent?
terms_version.current_type = :uncurrent
assert terms_version.uncurrent?
assert_not terms_version.current?
end
test "current_version should return latest current version" do
version = TermsVersion.current_version
assert_not_nil version
assert_kind_of Integer, version
end
test "current_version should return highest version number" do
TermsVersion.create!(
version: 10,
current_type: :current,
published_at: Date.today,
title: "Version 10",
description: "Test"
)
TermsVersion.create!(
version: 15,
current_type: :current,
published_at: Date.today,
title: "Version 15",
description: "Test"
)
assert_equal 15, TermsVersion.current_version
end
test "current_version should only return current versions" do
TermsVersion.create!(
version: 20,
current_type: :uncurrent,
published_at: Date.today,
title: "Uncurrent",
description: "Test"
)
TermsVersion.create!(
version: 5,
current_type: :current,
published_at: Date.today,
title: "Current",
description: "Test"
)
assert_equal 5, TermsVersion.current_version
end
test "current_version returns nil when no current version exists" do
TermsVersion.update_all(current_type: :uncurrent)
assert_nil TermsVersion.current_version
end
test "should load from fixtures" do
assert TermsVersion.count > 0
terms_version = TermsVersion.first
assert_not_nil terms_version
assert_not_nil terms_version.version
assert_not_nil terms_version.published_at
end
end