-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp_version_test.rb
More file actions
125 lines (104 loc) · 3.38 KB
/
app_version_test.rb
File metadata and controls
125 lines (104 loc) · 3.38 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "test_helper"
class AppVersionTest < ActiveSupport::TestCase
test "should be valid with valid attributes" do
app_version = AppVersion.new(
platform: "ios",
version: 2,
current_type: :current,
forced_update_type: :unforced_update,
title: "Test Version",
description: "Test Description"
)
assert app_version.valid?
end
test "should have current_type enum" do
app_version = AppVersion.new(
platform: "ios",
version: 2,
current_type: :current,
forced_update_type: :unforced_update
)
assert app_version.current?
assert_not app_version.uncurrent?
app_version.current_type = :uncurrent
assert app_version.uncurrent?
assert_not app_version.current?
end
test "should have forced_update_type enum" do
app_version = AppVersion.new(
platform: "ios",
version: 2,
current_type: :current,
forced_update_type: :forced_update
)
assert app_version.forced_update?
assert_not app_version.unforced_update?
app_version.forced_update_type = :unforced_update
assert app_version.unforced_update?
assert_not app_version.forced_update?
end
test "current_version should return latest current version for platform" do
ios_version = AppVersion.current_version(platform: "ios")
assert_not_nil ios_version
assert_kind_of Integer, ios_version
android_version = AppVersion.current_version(platform: "android")
assert_not_nil android_version
assert_kind_of Integer, android_version
end
test "current_version should return highest version for platform" do
AppVersion.create!(
platform: "ios",
version: 10,
current_type: :current,
forced_update_type: :unforced_update,
title: "Version 10",
description: "Test"
)
AppVersion.create!(
platform: "ios",
version: 15,
current_type: :current,
forced_update_type: :unforced_update,
title: "Version 15",
description: "Test"
)
assert_equal 15, AppVersion.current_version(platform: "ios")
end
test "current_version should only return current versions" do
AppVersion.create!(
platform: "android",
version: 20,
current_type: :uncurrent,
forced_update_type: :unforced_update,
title: "Uncurrent",
description: "Test"
)
AppVersion.create!(
platform: "android",
version: 5,
current_type: :current,
forced_update_type: :unforced_update,
title: "Current",
description: "Test"
)
assert_equal 5, AppVersion.current_version(platform: "android")
end
test "current_version returns nil for nonexistent platform" do
assert_nil AppVersion.current_version(platform: "nonexistent")
end
test "current_version respects chained scopes" do
version = AppVersion.forced_update.current_version(platform: "ios")
assert_not_nil version
# unforced_update scope should not find forced_update records
AppVersion.where(platform: "ios").update_all(forced_update_type: :forced_update)
version = AppVersion.unforced_update.current_version(platform: "ios")
assert_nil version
end
test "should load from fixtures" do
assert AppVersion.count > 0
ios_version = AppVersion.find_by(platform: "ios")
assert_not_nil ios_version
android_version = AppVersion.find_by(platform: "android")
assert_not_nil android_version
end
end