@@ -70,6 +70,7 @@ class EnumTest < ActiveRecord::TestCase
70
70
assert_equal "visible" , @book . author_visibility
71
71
assert_equal "visible" , @book . illustrator_visibility
72
72
assert_equal "medium" , @book . difficulty
73
+ assert_equal "soft" , @book . cover
73
74
end
74
75
75
76
test "find via scope" do
@@ -108,6 +109,7 @@ class EnumTest < ActiveRecord::TestCase
108
109
assert_not_equal @book , Book . where ( status : [ written , written ] ) . first
109
110
assert_not_equal @book , Book . where . not ( status : published ) . first
110
111
assert_equal @book , Book . where . not ( status : written ) . first
112
+ assert_equal @book , Book . where ( cover : Book . covers [ :soft ] ) . first
111
113
end
112
114
113
115
test "find via where with symbols" do
@@ -119,6 +121,8 @@ class EnumTest < ActiveRecord::TestCase
119
121
assert_equal @book , Book . where . not ( status : :written ) . first
120
122
assert_equal books ( :ddd ) , Book . where ( last_read : :forgotten ) . first
121
123
assert_nil Book . where ( status : :prohibited ) . first
124
+ assert_equal @book , Book . where ( cover : :soft ) . first
125
+ assert_equal @book , Book . where . not ( cover : :hard ) . first
122
126
end
123
127
124
128
test "find via where with strings" do
@@ -145,6 +149,8 @@ class EnumTest < ActiveRecord::TestCase
145
149
146
150
enabled = Book . boolean_statuses [ :enabled ] . to_s
147
151
assert_equal book , Book . where ( boolean_status : enabled ) . last
152
+ assert_equal @book , Book . where ( cover : "soft" ) . first
153
+ assert_equal @book , Book . where . not ( cover : "hard" ) . first
148
154
end
149
155
150
156
test "build from scope" do
@@ -170,11 +176,15 @@ class EnumTest < ActiveRecord::TestCase
170
176
assert_predicate @book , :in_english?
171
177
@book . author_visibility_visible!
172
178
assert_predicate @book , :author_visibility_visible?
179
+ @book . hard!
180
+ assert_predicate @book , :hard?
173
181
end
174
182
175
183
test "update by setter" do
176
184
@book . update! status : :written
177
185
assert_predicate @book , :written?
186
+ @book . update! cover : :hard
187
+ assert_predicate @book , :hard?
178
188
end
179
189
180
190
test "enum methods are overwritable" do
@@ -185,11 +195,15 @@ class EnumTest < ActiveRecord::TestCase
185
195
test "direct assignment" do
186
196
@book . status = :written
187
197
assert_predicate @book , :written?
198
+ @book . cover = :hard
199
+ assert_predicate @book , :hard?
188
200
end
189
201
190
202
test "assign string value" do
191
203
@book . status = "written"
192
204
assert_predicate @book , :written?
205
+ @book . cover = "hard"
206
+ assert_predicate @book , :hard?
193
207
end
194
208
195
209
test "enum changed attributes" do
0 commit comments