enumerize 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +73 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.global +1 -8
- data/Gemfile.rails70 +9 -0
- data/Gemfile.railsmaster +5 -0
- data/README.md +182 -101
- data/lib/enumerize/activerecord.rb +6 -2
- data/lib/enumerize/scope/activerecord.rb +4 -0
- data/lib/enumerize/scope/mongoid.rb +4 -0
- data/lib/enumerize/scope/sequel.rb +4 -0
- data/lib/enumerize/version.rb +1 -1
- data/test/activemodel_test.rb +22 -22
- data/test/activerecord_test.rb +129 -106
- data/test/attribute_map_test.rb +7 -7
- data/test/attribute_test.rb +31 -31
- data/test/base_test.rb +35 -35
- data/test/module_attributes_test.rb +8 -8
- data/test/mongo_mapper_test.rb +8 -8
- data/test/mongoid_test.rb +30 -27
- data/test/multiple_test.rb +8 -8
- data/test/predicates_test.rb +18 -18
- data/test/rails_admin_test.rb +2 -2
- data/test/sequel_test.rb +56 -53
- data/test/set_test.rb +23 -23
- data/test/value_test.rb +28 -35
- metadata +10 -30
- data/.travis.yml +0 -35
data/test/predicates_test.rb
CHANGED
@@ -13,53 +13,53 @@ describe Enumerize::Predicates do
|
|
13
13
|
|
14
14
|
it 'creates predicate methods' do
|
15
15
|
kklass.enumerize(:foo, in: %w(a b), predicates: true)
|
16
|
-
object.must_respond_to :a?
|
17
|
-
object.must_respond_to :b?
|
16
|
+
expect(object).must_respond_to :a?
|
17
|
+
expect(object).must_respond_to :b?
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'creates predicate methods when enumerized values have dash in it' do
|
21
21
|
kklass.enumerize(:foo, in: %w(foo-bar bar-foo), predicates: true)
|
22
|
-
object.must_respond_to :foo_bar?
|
23
|
-
object.must_respond_to :bar_foo?
|
22
|
+
expect(object).must_respond_to :foo_bar?
|
23
|
+
expect(object).must_respond_to :bar_foo?
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'creates predicate methods on multiple attribute' do
|
27
27
|
kklass.enumerize(:foo, in: %w(a b), predicates: true, multiple: true)
|
28
|
-
object.must_respond_to :a?
|
29
|
-
object.must_respond_to :b?
|
28
|
+
expect(object).must_respond_to :a?
|
29
|
+
expect(object).must_respond_to :b?
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'checks values' do
|
33
33
|
kklass.enumerize(:foo, in: %w(a b), predicates: true)
|
34
34
|
object.foo = 'a'
|
35
|
-
object.a
|
36
|
-
object.b
|
35
|
+
expect(object.a?).must_equal true
|
36
|
+
expect(object.b?).must_equal false
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'checks values on multiple attribute' do
|
40
40
|
kklass.enumerize(:foo, in: %w(a b), predicates: true, multiple: true)
|
41
41
|
object.foo << :a
|
42
|
-
object.a
|
43
|
-
object.b
|
42
|
+
expect(object.a?).must_equal true
|
43
|
+
expect(object.b?).must_equal false
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'prefixes methods' do
|
47
47
|
kklass.enumerize(:foo, in: %w(a b), predicates: { prefix: 'bar' })
|
48
|
-
object.wont_respond_to :a?
|
49
|
-
object.wont_respond_to :b?
|
50
|
-
object.must_respond_to :bar_a?
|
51
|
-
object.must_respond_to :bar_b?
|
48
|
+
expect(object).wont_respond_to :a?
|
49
|
+
expect(object).wont_respond_to :b?
|
50
|
+
expect(object).must_respond_to :bar_a?
|
51
|
+
expect(object).must_respond_to :bar_b?
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'accepts only option' do
|
55
55
|
kklass.enumerize(:foo, in: %w(a b), predicates: { only: :a })
|
56
|
-
object.must_respond_to :a?
|
57
|
-
object.wont_respond_to :b?
|
56
|
+
expect(object).must_respond_to :a?
|
57
|
+
expect(object).wont_respond_to :b?
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'accepts except option' do
|
61
61
|
kklass.enumerize(:foo, in: %w(a b), predicates: { except: :a })
|
62
|
-
object.wont_respond_to :a?
|
63
|
-
object.must_respond_to :b?
|
62
|
+
expect(object).wont_respond_to :a?
|
63
|
+
expect(object).must_respond_to :b?
|
64
64
|
end
|
65
65
|
end
|
data/test/rails_admin_test.rb
CHANGED
@@ -14,14 +14,14 @@ class RailsAdminSpec < MiniTest::Spec
|
|
14
14
|
it 'defines enum method' do
|
15
15
|
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
16
16
|
kklass.enumerize(:foo, in: [:a, :b])
|
17
|
-
object.foo_enum.must_equal [['a text', 'a'], ['b text', 'b']]
|
17
|
+
expect(object.foo_enum).must_equal [['a text', 'a'], ['b text', 'b']]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'defines enum properly for custom values enumerations' do
|
22
22
|
store_translations(:en, :enumerize => {:foo => {:a => 'a text', :b => 'b text'}}) do
|
23
23
|
kklass.enumerize(:foo, in: {:a => 1, :b => 2})
|
24
|
-
object.foo_enum.must_equal [['a text', 'a'], ['b text', 'b']]
|
24
|
+
expect(object.foo_enum).must_equal [['a text', 'a'], ['b text', 'b']]
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/test/sequel_test.rb
CHANGED
@@ -93,7 +93,7 @@ module SequelTest
|
|
93
93
|
it 'sets nil if invalid value is passed' do
|
94
94
|
user = User.new
|
95
95
|
user.sex = :invalid
|
96
|
-
user.sex.must_be_nil
|
96
|
+
expect(user.sex).must_be_nil
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'saves value' do
|
@@ -101,7 +101,7 @@ module SequelTest
|
|
101
101
|
user = User.new
|
102
102
|
user.sex = :female
|
103
103
|
user.save
|
104
|
-
user.sex.must_equal 'female'
|
104
|
+
expect(user.sex).must_equal 'female'
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'loads value' do
|
@@ -109,14 +109,14 @@ module SequelTest
|
|
109
109
|
User.create(:sex => :male)
|
110
110
|
store_translations(:en, :enumerize => {:sex => {:male => 'Male'}}) do
|
111
111
|
user = User.first
|
112
|
-
user.sex.must_equal 'male'
|
113
|
-
user.sex_text.must_equal 'Male'
|
112
|
+
expect(user.sex).must_equal 'male'
|
113
|
+
expect(user.sex_text).must_equal 'Male'
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'has default value' do
|
118
|
-
User.new.role.must_equal 'user'
|
119
|
-
User.new.values[:role].must_equal 'user'
|
118
|
+
expect(User.new.role).must_equal 'user'
|
119
|
+
expect(User.new.values[:role]).must_equal 'user'
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'does not set default value for not selected attributes' do
|
@@ -127,26 +127,26 @@ module SequelTest
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'has default value with lambda' do
|
130
|
-
User.new.lambda_role.must_equal 'admin'
|
131
|
-
User.new.values[:lambda_role].must_equal 'admin'
|
130
|
+
expect(User.new.lambda_role).must_equal 'admin'
|
131
|
+
expect(User.new.values[:lambda_role]).must_equal 'admin'
|
132
132
|
end
|
133
133
|
it 'uses after_initialize callback to set default value' do
|
134
134
|
User.filter{ true }.delete
|
135
135
|
User.create(sex: 'male', lambda_role: nil)
|
136
136
|
|
137
137
|
user = User.where(:sex => 'male').first
|
138
|
-
user.lambda_role.must_equal 'admin'
|
138
|
+
expect(user.lambda_role).must_equal 'admin'
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'uses default value from db column' do
|
142
|
-
User.new.account_type.must_equal 'basic'
|
142
|
+
expect(User.new.account_type).must_equal 'basic'
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'validates inclusion' do
|
146
146
|
user = User.new
|
147
147
|
user.role = 'wrong'
|
148
|
-
user.wont_be :valid?
|
149
|
-
user.errors[:role].must_include 'is not included in the list'
|
148
|
+
expect(user).wont_be :valid?
|
149
|
+
expect(user.errors[:role]).must_include 'is not included in the list'
|
150
150
|
end
|
151
151
|
|
152
152
|
it 'validates inclusion on mass assignment' do
|
@@ -157,66 +157,66 @@ module SequelTest
|
|
157
157
|
|
158
158
|
it "uses persisted value for validation if it hasn't been set" do
|
159
159
|
user = User.create :sex => :male
|
160
|
-
User[user.id].read_attribute_for_validation(:sex).must_equal 'male'
|
160
|
+
expect(User[user.id].read_attribute_for_validation(:sex)).must_equal 'male'
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'is valid with empty string assigned' do
|
164
164
|
user = User.new
|
165
165
|
user.role = ''
|
166
|
-
user.must_be :valid?
|
166
|
+
expect(user).must_be :valid?
|
167
167
|
end
|
168
168
|
|
169
169
|
it 'stores nil when empty string assigned' do
|
170
170
|
user = User.new
|
171
171
|
user.role = ''
|
172
|
-
user.values[:role].must_be_nil
|
172
|
+
expect(user.values[:role]).must_be_nil
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'validates inclusion when :skip_validations = false' do
|
176
176
|
user = DoNotSkipValidationsUser.new
|
177
177
|
user.foo = 'wrong'
|
178
|
-
user.wont_be :valid?
|
179
|
-
user.errors[:foo].must_include 'is not included in the list'
|
178
|
+
expect(user).wont_be :valid?
|
179
|
+
expect(user.errors[:foo]).must_include 'is not included in the list'
|
180
180
|
end
|
181
181
|
|
182
182
|
it 'does not validate inclusion when :skip_validations = true' do
|
183
183
|
user = SkipValidationsUser.new
|
184
184
|
user.foo = 'wrong'
|
185
|
-
user.must_be :valid?
|
185
|
+
expect(user).must_be :valid?
|
186
186
|
end
|
187
187
|
|
188
188
|
it 'supports :skip_validations option as lambda' do
|
189
189
|
user = SkipValidationsLambdaUser.new
|
190
190
|
user.foo = 'wrong'
|
191
|
-
user.must_be :valid?
|
191
|
+
expect(user).must_be :valid?
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'supports :skip_validations option as lambda with a parameter' do
|
195
195
|
user = SkipValidationsLambdaWithParamUser.new
|
196
196
|
user.foo = 'wrong'
|
197
|
-
user.must_be :valid?
|
197
|
+
expect(user).must_be :valid?
|
198
198
|
end
|
199
199
|
|
200
200
|
it 'supports multiple attributes' do
|
201
201
|
user = User.new
|
202
202
|
user.interests ||= []
|
203
|
-
user.interests.must_be_empty
|
203
|
+
expect(user.interests).must_be_empty
|
204
204
|
user.interests << "music"
|
205
|
-
user.interests.must_equal %w(music)
|
205
|
+
expect(user.interests).must_equal %w(music)
|
206
206
|
user.save
|
207
207
|
|
208
208
|
user = User[user.id]
|
209
|
-
user.interests.must_be_instance_of Enumerize::Set
|
210
|
-
user.interests.must_equal %w(music)
|
209
|
+
expect(user.interests).must_be_instance_of Enumerize::Set
|
210
|
+
expect(user.interests).must_equal %w(music)
|
211
211
|
user.interests << "sports"
|
212
|
-
user.interests.must_equal %w(music sports)
|
212
|
+
expect(user.interests).must_equal %w(music sports)
|
213
213
|
|
214
214
|
user.interests = []
|
215
215
|
interests = user.interests
|
216
216
|
interests << "music"
|
217
|
-
interests.must_equal %w(music)
|
217
|
+
expect(interests).must_equal %w(music)
|
218
218
|
interests << "dancing"
|
219
|
-
interests.must_equal %w(music dancing)
|
219
|
+
expect(interests).must_equal %w(music dancing)
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'returns invalid multiple value for validation' do
|
@@ -224,19 +224,19 @@ module SequelTest
|
|
224
224
|
user.interests << :music
|
225
225
|
user.interests << :invalid
|
226
226
|
values = user.read_attribute_for_validation(:interests)
|
227
|
-
values.must_equal %w(music invalid)
|
227
|
+
expect(values).must_equal %w(music invalid)
|
228
228
|
end
|
229
229
|
|
230
230
|
it 'validates multiple attributes' do
|
231
231
|
user = User.new
|
232
232
|
user.interests << :invalid
|
233
|
-
user.wont_be :valid?
|
233
|
+
expect(user).wont_be :valid?
|
234
234
|
|
235
235
|
user.interests = Object.new
|
236
|
-
user.wont_be :valid?
|
236
|
+
expect(user).wont_be :valid?
|
237
237
|
|
238
238
|
user.interests = ['music', '']
|
239
|
-
user.must_be :valid?
|
239
|
+
expect(user).must_be :valid?
|
240
240
|
end
|
241
241
|
|
242
242
|
it 'stores custom values for multiple attributes' do
|
@@ -247,30 +247,33 @@ module SequelTest
|
|
247
247
|
|
248
248
|
user = klass.new
|
249
249
|
user.interests << :music
|
250
|
-
user.interests.must_equal %w(music)
|
250
|
+
expect(user.interests).must_equal %w(music)
|
251
251
|
user.save
|
252
252
|
|
253
253
|
user = klass[user.id]
|
254
|
-
user.interests.must_equal %w(music)
|
254
|
+
expect(user.interests).must_equal %w(music)
|
255
255
|
end
|
256
256
|
|
257
257
|
it 'adds scope' do
|
258
258
|
User.filter{ true }.delete
|
259
259
|
|
260
|
-
user_1 = User.create(status: :active, role: :admin)
|
261
|
-
user_2 = User.create(status: :blocked)
|
260
|
+
user_1 = User.create(sex: :female, skill: :noob, status: :active, role: :admin)
|
261
|
+
user_2 = User.create(sex: :female, skill: :casual, status: :blocked)
|
262
262
|
user_3 = User.create(sex: :male, skill: :pro)
|
263
263
|
|
264
|
-
User.with_status(:active).to_a.must_equal [user_1]
|
265
|
-
User.with_status(:blocked).to_a.must_equal [user_2]
|
266
|
-
User.with_status(:active, :blocked).to_set.must_equal [user_1, user_2].to_set
|
264
|
+
expect(User.with_status(:active).to_a).must_equal [user_1]
|
265
|
+
expect(User.with_status(:blocked).to_a).must_equal [user_2]
|
266
|
+
expect(User.with_status(:active, :blocked).to_set).must_equal [user_1, user_2].to_set
|
267
267
|
|
268
|
-
User.without_status(:active).to_a.must_equal [user_2]
|
269
|
-
User.without_status(:active, :blocked).to_a.must_equal []
|
268
|
+
expect(User.without_status(:active).to_a).must_equal [user_2]
|
269
|
+
expect(User.without_status(:active, :blocked).to_a).must_equal []
|
270
270
|
|
271
|
-
User.having_role(:admin).to_a.must_equal [user_1]
|
272
|
-
User.male.to_a.must_equal [user_3]
|
273
|
-
User.pro.to_a.must_equal [user_3]
|
271
|
+
expect(User.having_role(:admin).to_a).must_equal [user_1]
|
272
|
+
expect(User.male.to_a).must_equal [user_3]
|
273
|
+
expect(User.pro.to_a).must_equal [user_3]
|
274
|
+
|
275
|
+
expect(User.not_male.to_set).must_equal [user_1, user_2].to_set
|
276
|
+
expect(User.not_pro.to_set).must_equal [user_1, user_2].to_set
|
274
277
|
end
|
275
278
|
|
276
279
|
it 'allows either key or value as valid' do
|
@@ -278,13 +281,13 @@ module SequelTest
|
|
278
281
|
user_2 = User.new(status: 1)
|
279
282
|
user_3 = User.new(status: '1')
|
280
283
|
|
281
|
-
user_1.status.must_equal 'active'
|
282
|
-
user_2.status.must_equal 'active'
|
283
|
-
user_3.status.must_equal 'active'
|
284
|
+
expect(user_1.status).must_equal 'active'
|
285
|
+
expect(user_2.status).must_equal 'active'
|
286
|
+
expect(user_3.status).must_equal 'active'
|
284
287
|
|
285
|
-
user_1.must_be :valid?
|
286
|
-
user_2.must_be :valid?
|
287
|
-
user_3.must_be :valid?
|
288
|
+
expect(user_1).must_be :valid?
|
289
|
+
expect(user_2).must_be :valid?
|
290
|
+
expect(user_3).must_be :valid?
|
288
291
|
end
|
289
292
|
|
290
293
|
it 'supports defining enumerized attributes on abstract class' do
|
@@ -292,7 +295,7 @@ module SequelTest
|
|
292
295
|
|
293
296
|
document = Document.new
|
294
297
|
document.visibility = :protected
|
295
|
-
document.visibility.must_equal 'protected'
|
298
|
+
expect(document.visibility).must_equal 'protected'
|
296
299
|
end
|
297
300
|
|
298
301
|
it 'supports defining enumerized scopes on abstract class' do
|
@@ -301,7 +304,7 @@ module SequelTest
|
|
301
304
|
document_1 = Document.create(visibility: :public)
|
302
305
|
document_2 = Document.create(visibility: :private)
|
303
306
|
|
304
|
-
Document.with_visibility(:public).to_a.must_equal [document_1]
|
307
|
+
expect(Document.with_visibility(:public).to_a).must_equal [document_1]
|
305
308
|
end
|
306
309
|
|
307
310
|
it 'validates uniqueness' do
|
@@ -310,9 +313,9 @@ module SequelTest
|
|
310
313
|
user = UniqStatusUser.new
|
311
314
|
user.sex = "male"
|
312
315
|
user.status = :active
|
313
|
-
user.valid
|
316
|
+
expect(user.valid?).must_equal false
|
314
317
|
|
315
|
-
user.errors[:status].wont_be :empty?
|
318
|
+
expect(user.errors[:status]).wont_be :empty?
|
316
319
|
end
|
317
320
|
|
318
321
|
it "doesn't update record" do
|
data/test/set_test.rb
CHANGED
@@ -41,36 +41,36 @@ describe Enumerize::Set do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'equals to other set' do
|
44
|
-
set.must_equal Enumerize::Set.new(nil, kklass.foo, %w(a))
|
44
|
+
expect(set).must_equal Enumerize::Set.new(nil, kklass.foo, %w(a))
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'equals to array' do
|
48
|
-
set.must_equal %w(a)
|
48
|
+
expect(set).must_equal %w(a)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'equals to array of symbols' do
|
52
|
-
set.must_equal [:a]
|
52
|
+
expect(set).must_equal [:a]
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'has unique values' do
|
56
56
|
set << :a
|
57
|
-
set.must_equal %w(a)
|
57
|
+
expect(set).must_equal %w(a)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'equals to array with different value order' do
|
61
61
|
set << :b
|
62
|
-
set.must_equal %w(b a)
|
62
|
+
expect(set).must_equal %w(b a)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "isn't equal to a part of values" do
|
66
66
|
set << :b
|
67
|
-
set.wont_equal %w(a)
|
67
|
+
expect(set).wont_equal %w(a)
|
68
68
|
end
|
69
69
|
|
70
70
|
describe '#push' do
|
71
71
|
it 'appends values' do
|
72
72
|
set.push :b
|
73
|
-
set.must_include :b
|
73
|
+
expect(set).must_include :b
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'reassigns attribute' do
|
@@ -83,7 +83,7 @@ describe Enumerize::Set do
|
|
83
83
|
describe '#delete' do
|
84
84
|
it 'deletes value' do
|
85
85
|
set.delete :a
|
86
|
-
set.wont_include :a
|
86
|
+
expect(set).wont_include :a
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'reassigns attribute' do
|
@@ -96,64 +96,64 @@ describe Enumerize::Set do
|
|
96
96
|
describe '#inspect' do
|
97
97
|
it 'returns custom string' do
|
98
98
|
set << :b
|
99
|
-
set.inspect.must_equal '#<Enumerize::Set {a, b}>'
|
99
|
+
expect(set.inspect).must_equal '#<Enumerize::Set {a, b}>'
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe '#to_ary' do
|
104
104
|
it 'returns array' do
|
105
|
-
set.to_ary.must_be_instance_of Array
|
105
|
+
expect(set.to_ary).must_be_instance_of Array
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
describe '#texts' do
|
110
110
|
it 'returns array of text values' do
|
111
|
-
set.texts.must_equal ['A']
|
111
|
+
expect(set.texts).must_equal ['A']
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
describe '#join' do
|
116
116
|
it 'joins values' do
|
117
117
|
set << :b
|
118
|
-
set.join(', ').must_equal 'a, b'
|
118
|
+
expect(set.join(', ')).must_equal 'a, b'
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
describe 'boolean methods comparison' do
|
123
123
|
it 'returns true if value equals method' do
|
124
124
|
set << :a
|
125
|
-
set.a
|
125
|
+
expect(set.a?).must_equal true
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'returns false if value does not equal method' do
|
129
129
|
set << :a
|
130
|
-
set.b
|
130
|
+
expect(set.b?).must_equal false
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'raises NoMethodError if there are no values like boolean method' do
|
134
|
-
proc {
|
134
|
+
expect(proc {
|
135
135
|
set.some_method?
|
136
|
-
}.must_raise NoMethodError
|
136
|
+
}).must_raise NoMethodError
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'raises ArgumentError if arguments are passed' do
|
140
|
-
proc {
|
140
|
+
expect(proc {
|
141
141
|
set.a?('<3')
|
142
|
-
}.must_raise ArgumentError
|
142
|
+
}).must_raise ArgumentError
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'responds to methods for existing values' do
|
146
|
-
set.must_respond_to :a?
|
147
|
-
set.must_respond_to :b?
|
148
|
-
set.must_respond_to :c?
|
146
|
+
expect(set).must_respond_to :a?
|
147
|
+
expect(set).must_respond_to :b?
|
148
|
+
expect(set).must_respond_to :c?
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'returns a method object' do
|
152
|
-
set.method(:a?).must_be_instance_of Method
|
152
|
+
expect(set.method(:a?)).must_be_instance_of Method
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'does not respond to a method for not existing value' do
|
156
|
-
set.wont_respond_to :some_method?
|
156
|
+
expect(set).wont_respond_to :some_method?
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
data/test/value_test.rb
CHANGED
@@ -14,36 +14,36 @@ describe Enumerize::Value do
|
|
14
14
|
let(:val) { Enumerize::Value.new(attr, 'test_value', 1) }
|
15
15
|
|
16
16
|
it 'is a string' do
|
17
|
-
val.must_be_kind_of String
|
17
|
+
expect(val).must_be_kind_of String
|
18
18
|
end
|
19
19
|
|
20
20
|
describe 'equality' do
|
21
21
|
it 'is compared to string' do
|
22
|
-
val.must_be :==, 'test_value'
|
23
|
-
val.wont_be :==, 'not_value'
|
22
|
+
expect(val).must_be :==, 'test_value'
|
23
|
+
expect(val).wont_be :==, 'not_value'
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'is compared to symbol' do
|
27
|
-
val.must_be :==, :test_value
|
28
|
-
val.wont_be :==, :not_value
|
27
|
+
expect(val).must_be :==, :test_value
|
28
|
+
expect(val).wont_be :==, :not_value
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'is compared to integer' do
|
32
|
-
val.must_be :==, 1
|
33
|
-
val.wont_be :==, 2
|
32
|
+
expect(val).must_be :==, 1
|
33
|
+
expect(val).wont_be :==, 2
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe 'translation' do
|
38
38
|
it 'uses common translation' do
|
39
39
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
40
|
-
val.text.must_be :==, "Common translation"
|
40
|
+
expect(val.text).must_be :==, "Common translation"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'uses default translation from the "default" section if its present' do
|
45
45
|
store_translations(:en, :enumerize => {:defaults => {:attribute_name => {:test_value => "Common translation"}}}) do
|
46
|
-
val.text.must_be :==, "Common translation"
|
46
|
+
expect(val.text).must_be :==, "Common translation"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -51,7 +51,7 @@ describe Enumerize::Value do
|
|
51
51
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
52
52
|
|
53
53
|
store_translations(:en, :enumerize => {:model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
54
|
-
val.text.must_be :==, "Model Specific translation"
|
54
|
+
expect(val.text).must_be :==, "Model Specific translation"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,13 +59,13 @@ describe Enumerize::Value do
|
|
59
59
|
attr.i18n_scopes = ["enumerize.model_name.attribute_name"]
|
60
60
|
|
61
61
|
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}, :model_name => {:attribute_name => {:test_value => "Model Specific translation"}}}) do
|
62
|
-
val.text.must_be :==, "Model Specific translation"
|
62
|
+
expect(val.text).must_be :==, "Model Specific translation"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'uses simply humanized value when translation is undefined' do
|
67
67
|
store_translations(:en, :enumerize => {}) do
|
68
|
-
val.text.must_be :==, "Test value"
|
68
|
+
expect(val.text).must_be :==, "Test value"
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -73,7 +73,7 @@ describe Enumerize::Value do
|
|
73
73
|
attr.i18n_scopes = ["other.scope"]
|
74
74
|
|
75
75
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
76
|
-
val.text.must_be :==, "Scope specific translation"
|
76
|
+
expect(val.text).must_be :==, "Scope specific translation"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -81,14 +81,7 @@ describe Enumerize::Value do
|
|
81
81
|
attr.i18n_scopes = ["nonexistent.scope", "other.scope"]
|
82
82
|
|
83
83
|
store_translations(:en, :other => {:scope => {:test_value => "Scope specific translation"}}) do
|
84
|
-
val.text.must_be :==, "Scope specific translation"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'returns nil if value was modified' do
|
89
|
-
store_translations(:en, :enumerize => {:attribute_name => {:test_value => "Common translation"}}) do
|
90
|
-
modified_val = val.upcase
|
91
|
-
modified_val.text.must_be_nil
|
84
|
+
expect(val.text).must_be :==, "Scope specific translation"
|
92
85
|
end
|
93
86
|
end
|
94
87
|
end
|
@@ -99,44 +92,44 @@ describe Enumerize::Value do
|
|
99
92
|
end
|
100
93
|
|
101
94
|
it 'returns true if value equals method' do
|
102
|
-
val.test_value
|
95
|
+
expect(val.test_value?).must_equal true
|
103
96
|
end
|
104
97
|
|
105
98
|
it 'returns false if value does not equal method' do
|
106
|
-
val.other_value
|
99
|
+
expect(val.other_value?).must_equal false
|
107
100
|
end
|
108
101
|
|
109
102
|
it 'raises NoMethodError if there are no values like boolean method' do
|
110
|
-
proc {
|
103
|
+
expect(proc {
|
111
104
|
val.some_method?
|
112
|
-
}.must_raise NoMethodError
|
105
|
+
}).must_raise NoMethodError
|
113
106
|
end
|
114
107
|
|
115
108
|
it 'raises ArgumentError if arguments are passed' do
|
116
|
-
proc {
|
109
|
+
expect(proc {
|
117
110
|
val.other_value?('<3')
|
118
|
-
}.must_raise ArgumentError
|
111
|
+
}).must_raise ArgumentError
|
119
112
|
end
|
120
113
|
|
121
114
|
it 'responds to methods for existing values' do
|
122
|
-
val.must_respond_to :test_value?
|
123
|
-
val.must_respond_to :other_value?
|
115
|
+
expect(val).must_respond_to :test_value?
|
116
|
+
expect(val).must_respond_to :other_value?
|
124
117
|
end
|
125
118
|
|
126
119
|
it 'returns a method object' do
|
127
|
-
val.method(:test_value?).must_be_instance_of Method
|
120
|
+
expect(val.method(:test_value?)).must_be_instance_of Method
|
128
121
|
end
|
129
122
|
|
130
123
|
it "doesn't respond to a method for not existing value" do
|
131
|
-
val.wont_respond_to :some_method?
|
124
|
+
expect(val).wont_respond_to :some_method?
|
132
125
|
end
|
133
126
|
|
134
127
|
it "doesn't respond to methods is value was modified" do
|
135
128
|
modified_value = val.upcase
|
136
129
|
|
137
|
-
modified_value.upcase.wont_respond_to :some_method?
|
138
|
-
modified_value.upcase.wont_respond_to :test_value?
|
139
|
-
modified_value.upcase.wont_respond_to :other_value?
|
130
|
+
expect(modified_value.upcase).wont_respond_to :some_method?
|
131
|
+
expect(modified_value.upcase).wont_respond_to :test_value?
|
132
|
+
expect(modified_value.upcase).wont_respond_to :other_value?
|
140
133
|
end
|
141
134
|
end
|
142
135
|
|
@@ -149,7 +142,7 @@ describe Enumerize::Value do
|
|
149
142
|
|
150
143
|
it 'serializes with Marshal' do
|
151
144
|
dump_value = Marshal.dump(val)
|
152
|
-
Marshal.load(dump_value).must_equal 'test_value'
|
145
|
+
expect(Marshal.load(dump_value)).must_equal 'test_value'
|
153
146
|
end
|
154
147
|
end
|
155
148
|
|