enumerize 2.4.0 → 2.6.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 +15 -0
- data/Gemfile +1 -1
- data/Gemfile.global +1 -8
- data/Gemfile.rails70 +9 -0
- data/Gemfile.railsmaster +5 -0
- data/README.md +183 -102
- data/enumerize.gemspec +1 -1
- data/lib/enumerize/activerecord.rb +7 -3
- data/lib/enumerize/attribute.rb +4 -0
- data/lib/enumerize/base.rb +20 -16
- data/lib/enumerize/mongoid.rb +7 -0
- data/lib/enumerize/predicatable.rb +1 -1
- 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/lib/enumerize.rb +1 -1
- data/test/activemodel_test.rb +23 -23
- data/test/activerecord_test.rb +135 -109
- data/test/attribute_map_test.rb +7 -7
- data/test/attribute_test.rb +32 -32
- data/test/base_test.rb +62 -36
- data/test/module_attributes_test.rb +8 -8
- data/test/mongo_mapper_test.rb +9 -9
- data/test/mongoid_test.rb +31 -28
- data/test/multiple_test.rb +9 -9
- data/test/predicates_test.rb +19 -19
- data/test/rails_admin_test.rb +2 -2
- data/test/sequel_test.rb +199 -198
- data/test/set_test.rb +24 -24
- data/test/test_helper.rb +8 -0
- data/test/value_test.rb +29 -36
- metadata +7 -5
- data/.travis.yml +0 -35
data/test/multiple_test.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
|
5
|
+
class MultipleTest < MiniTest::Spec
|
6
6
|
let(:kklass) do
|
7
7
|
Class.new do
|
8
8
|
extend Enumerize
|
@@ -17,38 +17,38 @@ describe Enumerize::Base do
|
|
17
17
|
|
18
18
|
it 'returns [] when not set' do
|
19
19
|
kklass.enumerize :foos, in: %w(a b), multiple: true
|
20
|
-
object.foos.must_equal []
|
20
|
+
expect(object.foos).must_equal []
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'returns setted array' do
|
24
24
|
kklass.enumerize :foos, in: %w(a b c), multiple: true
|
25
25
|
object.foos = %w(a c)
|
26
|
-
object.foos.must_equal %w(a c)
|
26
|
+
expect(object.foos).must_equal %w(a c)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'sets default value as single value' do
|
30
30
|
kklass.enumerize :foos, in: %w(a b c), default: 'b', multiple: true
|
31
|
-
object.foos.must_equal %w(b)
|
31
|
+
expect(object.foos).must_equal %w(b)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'sets default value as array of one element' do
|
35
35
|
kklass.enumerize :foos, in: %w(a b c), default: %w(b), multiple: true
|
36
|
-
object.foos.must_equal %w(b)
|
36
|
+
expect(object.foos).must_equal %w(b)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'sets default value as array of several elements' do
|
40
40
|
kklass.enumerize :foos, in: %w(a b c), default: %w(b c), multiple: true
|
41
|
-
object.foos.must_equal %w(b c)
|
41
|
+
expect(object.foos).must_equal %w(b c)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "doesn't define _text method" do
|
45
45
|
kklass.enumerize :foos, in: %w(a b c), multiple: true
|
46
|
-
object.wont_respond_to :foos_text
|
46
|
+
expect(object).wont_respond_to :foos_text
|
47
47
|
end
|
48
48
|
|
49
49
|
it "doesn't define _value method" do
|
50
50
|
kklass.enumerize :foos, in: %w(a b c), multiple: true
|
51
|
-
object.wont_respond_to :foos_value
|
51
|
+
expect(object).wont_respond_to :foos_value
|
52
52
|
end
|
53
53
|
|
54
54
|
it "cannot define multiple with scope" do
|
@@ -60,6 +60,6 @@ describe Enumerize::Base do
|
|
60
60
|
it 'assign a name with the first letter capitalized' do
|
61
61
|
kklass.enumerize :Foos, in: %w(a b c), multiple: true
|
62
62
|
object.Foos = %w(a c)
|
63
|
-
object.Foos.must_equal %w(a c)
|
63
|
+
expect(object.Foos).must_equal %w(a c)
|
64
64
|
end
|
65
65
|
end
|
data/test/predicates_test.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
|
-
|
5
|
+
class PredicatesTest < MiniTest::Spec
|
6
6
|
let(:kklass) do
|
7
7
|
Class.new do
|
8
8
|
extend Enumerize
|
@@ -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
@@ -5,7 +5,7 @@ require 'sequel'
|
|
5
5
|
require 'logger'
|
6
6
|
require 'jdbc/sqlite3' if RUBY_PLATFORM == 'java'
|
7
7
|
|
8
|
-
|
8
|
+
class SequelTest < MiniTest::Spec
|
9
9
|
silence_warnings do
|
10
10
|
DB = if RUBY_PLATFORM == 'java'
|
11
11
|
Sequel.connect('jdbc:sqlite::memory:')
|
@@ -89,253 +89,254 @@ module SequelTest
|
|
89
89
|
include SkipValidationsLambdaWithParamEnum
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
92
|
+
it 'sets nil if invalid value is passed' do
|
93
|
+
user = User.new
|
94
|
+
user.sex = :invalid
|
95
|
+
expect(user.sex).must_be_nil
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
it 'saves value' do
|
99
|
+
User.filter{ true }.delete
|
100
|
+
user = User.new
|
101
|
+
user.sex = :female
|
102
|
+
user.save
|
103
|
+
expect(user.sex).must_equal 'female'
|
104
|
+
end
|
106
105
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
106
|
+
it 'loads value' do
|
107
|
+
User.filter{ true }.delete
|
108
|
+
User.create(:sex => :male)
|
109
|
+
store_translations(:en, :enumerize => {:sex => {:male => 'Male'}}) do
|
110
|
+
user = User.first
|
111
|
+
expect(user.sex).must_equal 'male'
|
112
|
+
expect(user.sex_text).must_equal 'Male'
|
115
113
|
end
|
114
|
+
end
|
116
115
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
it 'has default value' do
|
117
|
+
expect(User.new.role).must_equal 'user'
|
118
|
+
expect(User.new.values[:role]).must_equal 'user'
|
119
|
+
end
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
it 'does not set default value for not selected attributes' do
|
122
|
+
User.filter{ true }.delete
|
123
|
+
User.create(:sex => :male)
|
125
124
|
|
126
|
-
|
127
|
-
|
125
|
+
assert_equal [:id], User.select(:id).first.values.keys
|
126
|
+
end
|
128
127
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
128
|
+
it 'has default value with lambda' do
|
129
|
+
expect(User.new.lambda_role).must_equal 'admin'
|
130
|
+
expect(User.new.values[:lambda_role]).must_equal 'admin'
|
131
|
+
end
|
132
|
+
it 'uses after_initialize callback to set default value' do
|
133
|
+
User.filter{ true }.delete
|
134
|
+
User.create(sex: 'male', lambda_role: nil)
|
136
135
|
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
user = User.where(:sex => 'male').first
|
137
|
+
expect(user.lambda_role).must_equal 'admin'
|
138
|
+
end
|
140
139
|
|
141
|
-
|
142
|
-
|
143
|
-
|
140
|
+
it 'uses default value from db column' do
|
141
|
+
expect(User.new.account_type).must_equal 'basic'
|
142
|
+
end
|
144
143
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
it 'validates inclusion' do
|
145
|
+
user = User.new
|
146
|
+
user.role = 'wrong'
|
147
|
+
expect(user).wont_be :valid?
|
148
|
+
expect(user.errors[:role]).must_include 'is not included in the list'
|
149
|
+
end
|
151
150
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
151
|
+
it 'validates inclusion on mass assignment' do
|
152
|
+
assert_raises Sequel::ValidationFailed do
|
153
|
+
User.create(role: 'wrong')
|
156
154
|
end
|
155
|
+
end
|
157
156
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
157
|
+
it "uses persisted value for validation if it hasn't been set" do
|
158
|
+
user = User.create :sex => :male
|
159
|
+
expect(User[user.id].read_attribute_for_validation(:sex)).must_equal 'male'
|
160
|
+
end
|
162
161
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
162
|
+
it 'is valid with empty string assigned' do
|
163
|
+
user = User.new
|
164
|
+
user.role = ''
|
165
|
+
expect(user).must_be :valid?
|
166
|
+
end
|
168
167
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
168
|
+
it 'stores nil when empty string assigned' do
|
169
|
+
user = User.new
|
170
|
+
user.role = ''
|
171
|
+
expect(user.values[:role]).must_be_nil
|
172
|
+
end
|
174
173
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
174
|
+
it 'validates inclusion when :skip_validations = false' do
|
175
|
+
user = DoNotSkipValidationsUser.new
|
176
|
+
user.foo = 'wrong'
|
177
|
+
expect(user).wont_be :valid?
|
178
|
+
expect(user.errors[:foo]).must_include 'is not included in the list'
|
179
|
+
end
|
181
180
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
it 'does not validate inclusion when :skip_validations = true' do
|
182
|
+
user = SkipValidationsUser.new
|
183
|
+
user.foo = 'wrong'
|
184
|
+
expect(user).must_be :valid?
|
185
|
+
end
|
187
186
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
187
|
+
it 'supports :skip_validations option as lambda' do
|
188
|
+
user = SkipValidationsLambdaUser.new
|
189
|
+
user.foo = 'wrong'
|
190
|
+
expect(user).must_be :valid?
|
191
|
+
end
|
193
192
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
193
|
+
it 'supports :skip_validations option as lambda with a parameter' do
|
194
|
+
user = SkipValidationsLambdaWithParamUser.new
|
195
|
+
user.foo = 'wrong'
|
196
|
+
expect(user).must_be :valid?
|
197
|
+
end
|
199
198
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
199
|
+
it 'supports multiple attributes' do
|
200
|
+
user = User.new
|
201
|
+
user.interests ||= []
|
202
|
+
expect(user.interests).must_be_empty
|
203
|
+
user.interests << "music"
|
204
|
+
expect(user.interests).must_equal %w(music)
|
205
|
+
user.save
|
206
|
+
|
207
|
+
user = User[user.id]
|
208
|
+
expect(user.interests).must_be_instance_of Enumerize::Set
|
209
|
+
expect(user.interests).must_equal %w(music)
|
210
|
+
user.interests << "sports"
|
211
|
+
expect(user.interests).must_equal %w(music sports)
|
212
|
+
|
213
|
+
user.interests = []
|
214
|
+
interests = user.interests
|
215
|
+
interests << "music"
|
216
|
+
expect(interests).must_equal %w(music)
|
217
|
+
interests << "dancing"
|
218
|
+
expect(interests).must_equal %w(music dancing)
|
219
|
+
end
|
221
220
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
221
|
+
it 'returns invalid multiple value for validation' do
|
222
|
+
user = User.new
|
223
|
+
user.interests << :music
|
224
|
+
user.interests << :invalid
|
225
|
+
values = user.read_attribute_for_validation(:interests)
|
226
|
+
expect(values).must_equal %w(music invalid)
|
227
|
+
end
|
229
228
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
229
|
+
it 'validates multiple attributes' do
|
230
|
+
user = User.new
|
231
|
+
user.interests << :invalid
|
232
|
+
expect(user).wont_be :valid?
|
234
233
|
|
235
|
-
|
236
|
-
|
234
|
+
user.interests = Object.new
|
235
|
+
expect(user).wont_be :valid?
|
237
236
|
|
238
|
-
|
239
|
-
|
240
|
-
|
237
|
+
user.interests = ['music', '']
|
238
|
+
expect(user).must_be :valid?
|
239
|
+
end
|
241
240
|
|
242
|
-
|
243
|
-
|
241
|
+
it 'stores custom values for multiple attributes' do
|
242
|
+
User.filter{ true }.delete
|
244
243
|
|
245
|
-
|
246
|
-
|
244
|
+
klass = Class.new(User)
|
245
|
+
klass.enumerize :interests, in: { music: 0, sports: 1, dancing: 2, programming: 3}, multiple: true
|
247
246
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
247
|
+
user = klass.new
|
248
|
+
user.interests << :music
|
249
|
+
expect(user.interests).must_equal %w(music)
|
250
|
+
user.save
|
252
251
|
|
253
|
-
|
254
|
-
|
255
|
-
|
252
|
+
user = klass[user.id]
|
253
|
+
expect(user.interests).must_equal %w(music)
|
254
|
+
end
|
256
255
|
|
257
|
-
|
258
|
-
|
256
|
+
it 'adds scope' do
|
257
|
+
User.filter{ true }.delete
|
259
258
|
|
260
|
-
|
261
|
-
|
262
|
-
|
259
|
+
user_1 = User.create(sex: :female, skill: :noob, status: :active, role: :admin)
|
260
|
+
user_2 = User.create(sex: :female, skill: :casual, status: :blocked)
|
261
|
+
user_3 = User.create(sex: :male, skill: :pro)
|
263
262
|
|
264
|
-
|
265
|
-
|
266
|
-
|
263
|
+
expect(User.with_status(:active).to_a).must_equal [user_1]
|
264
|
+
expect(User.with_status(:blocked).to_a).must_equal [user_2]
|
265
|
+
expect(User.with_status(:active, :blocked).to_set).must_equal [user_1, user_2].to_set
|
267
266
|
|
268
|
-
|
269
|
-
|
267
|
+
expect(User.without_status(:active).to_a).must_equal [user_2]
|
268
|
+
expect(User.without_status(:active, :blocked).to_a).must_equal []
|
270
269
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
end
|
270
|
+
expect(User.having_role(:admin).to_a).must_equal [user_1]
|
271
|
+
expect(User.male.to_a).must_equal [user_3]
|
272
|
+
expect(User.pro.to_a).must_equal [user_3]
|
275
273
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
user_3 = User.new(status: '1')
|
274
|
+
expect(User.not_male.to_set).must_equal [user_1, user_2].to_set
|
275
|
+
expect(User.not_pro.to_set).must_equal [user_1, user_2].to_set
|
276
|
+
end
|
280
277
|
|
281
|
-
|
282
|
-
|
283
|
-
|
278
|
+
it 'allows either key or value as valid' do
|
279
|
+
user_1 = User.new(status: :active)
|
280
|
+
user_2 = User.new(status: 1)
|
281
|
+
user_3 = User.new(status: '1')
|
284
282
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
end
|
283
|
+
expect(user_1.status).must_equal 'active'
|
284
|
+
expect(user_2.status).must_equal 'active'
|
285
|
+
expect(user_3.status).must_equal 'active'
|
289
286
|
|
290
|
-
|
291
|
-
|
287
|
+
expect(user_1).must_be :valid?
|
288
|
+
expect(user_2).must_be :valid?
|
289
|
+
expect(user_3).must_be :valid?
|
290
|
+
end
|
292
291
|
|
293
|
-
|
294
|
-
|
295
|
-
document.visibility.must_equal 'protected'
|
296
|
-
end
|
292
|
+
it 'supports defining enumerized attributes on abstract class' do
|
293
|
+
Document.filter{ true }.delete
|
297
294
|
|
298
|
-
|
299
|
-
|
295
|
+
document = Document.new
|
296
|
+
document.visibility = :protected
|
297
|
+
expect(document.visibility).must_equal 'protected'
|
298
|
+
end
|
300
299
|
|
301
|
-
|
302
|
-
|
300
|
+
it 'supports defining enumerized scopes on abstract class' do
|
301
|
+
Document.filter{ true }.delete
|
303
302
|
|
304
|
-
|
305
|
-
|
303
|
+
document_1 = Document.create(visibility: :public)
|
304
|
+
document_2 = Document.create(visibility: :private)
|
306
305
|
|
307
|
-
|
308
|
-
|
306
|
+
expect(Document.with_visibility(:public).to_a).must_equal [document_1]
|
307
|
+
end
|
309
308
|
|
310
|
-
|
311
|
-
|
312
|
-
user.status = :active
|
313
|
-
user.valid?.must_equal false
|
309
|
+
it 'validates uniqueness' do
|
310
|
+
user = User.create(status: :active, sex: "male")
|
314
311
|
|
315
|
-
|
316
|
-
|
312
|
+
user = UniqStatusUser.new
|
313
|
+
user.sex = "male"
|
314
|
+
user.status = :active
|
315
|
+
expect(user.valid?).must_equal false
|
317
316
|
|
318
|
-
|
319
|
-
|
317
|
+
expect(user.errors[:status]).wont_be :empty?
|
318
|
+
end
|
320
319
|
|
321
|
-
|
320
|
+
it "doesn't update record" do
|
321
|
+
Document.filter{ true }.delete
|
322
322
|
|
323
|
-
|
324
|
-
document.updated_at = expected
|
325
|
-
document.save
|
323
|
+
expected = Time.new(2010, 10, 10)
|
326
324
|
|
327
|
-
|
328
|
-
|
325
|
+
document = Document.new
|
326
|
+
document.updated_at = expected
|
327
|
+
document.save
|
329
328
|
|
330
|
-
|
331
|
-
|
329
|
+
document = Document.last
|
330
|
+
document.save
|
332
331
|
|
333
|
-
|
334
|
-
|
335
|
-
user.status = :blocked
|
332
|
+
assert_equal expected, document.updated_at
|
333
|
+
end
|
336
334
|
|
337
|
-
|
338
|
-
|
339
|
-
|
335
|
+
it 'changes from dirty should be serialized as scalar values' do
|
336
|
+
user = User.create(:status => :active)
|
337
|
+
user.status = :blocked
|
338
|
+
|
339
|
+
expected = { status: [1, 2] }.to_yaml
|
340
|
+
assert_equal expected, user.column_changes.to_yaml
|
340
341
|
end
|
341
342
|
end
|