detox 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/detox.rb +1 -0
- data/lib/detox/locales/en.yml +1 -0
- data/lib/detox/locales/ja.yml +1 -0
- data/lib/detox/validations/values_uniqueness.rb +25 -0
- data/lib/detox/version.rb +1 -1
- data/spec/detox/validations/values_uniqueness_spec.rb +460 -0
- data/spec/test_class/values_uniqueness_test.rb +27 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3539084844db07a30aed07576d36bc3856a3676
|
4
|
+
data.tar.gz: 2718b759268e66ca0937e2af388a5c6f3e99a7d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77da47126cd49d77e0a9abe5feefe4b1c47276ef4630f120ec3819be8360579b5c86b237d19374636aa6af10368693fd9b2aacc6f7a5f4f725e4ff93851b0523
|
7
|
+
data.tar.gz: 1db5eab41c1c3934dce9832d9a7d22588622099b6122f28966c35ba4fb864d432970e00b6d7dc1a26189be2639314077c693dcfc6d2ef4538ac0d63b64472e2f
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ Look [spec/test_class](https://github.com/pinzolo/detox/tree/master/spec/test_cl
|
|
27
27
|
- Validators for attribute that has Array or Hash value
|
28
28
|
- **ordering**: validates continuous numbers
|
29
29
|
- **possession**: validates subset values
|
30
|
+
- **values_uniqueness**: validates unique values
|
30
31
|
- **all_xxx**: validates that all value are valid, by basic validators (xxx is presence, format etc.)
|
31
32
|
- **any_xxx**: validates that has valid value, by basic validators (xxx is presence, format etc.)
|
32
33
|
|
@@ -38,3 +39,9 @@ Look [spec/test_class](https://github.com/pinzolo/detox/tree/master/spec/test_cl
|
|
38
39
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
40
|
4. Push to the branch (`git push origin my-new-feature`)
|
40
41
|
5. Create new Pull Request
|
42
|
+
|
43
|
+
|
44
|
+
## Changelog
|
45
|
+
- v1.0.0 (2013-11-07 JST): First release
|
46
|
+
- v1.0.1 (2013-11-13 JST): Add ValuesUniquenessValidator
|
47
|
+
|
data/lib/detox.rb
CHANGED
data/lib/detox/locales/en.yml
CHANGED
@@ -3,6 +3,7 @@ en:
|
|
3
3
|
messages:
|
4
4
|
invalid_as_order: "is not satisfied as order"
|
5
5
|
possession: "must possess target (target: %{target})"
|
6
|
+
values_not_unique: "contains duplicate value"
|
6
7
|
all_presence: "can't contain blank value"
|
7
8
|
all_absence: "can't contain not blank value"
|
8
9
|
all_format: "contains invalid format value"
|
data/lib/detox/locales/ja.yml
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "active_support/core_ext"
|
3
|
+
require "detox/array_validity"
|
4
|
+
|
5
|
+
module Detox::Validations
|
6
|
+
class ValuesUniquenessValidator < ActiveModel::EachValidator
|
7
|
+
include Detox::ArrayValidity
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
values = convert_to_validatee(value, options.slice(*Detox::ArrayValidity::RESERVED_OPTIONS))
|
11
|
+
return if values.blank?
|
12
|
+
|
13
|
+
unless values_valid?(values)
|
14
|
+
message = options[:message] || :values_not_unique
|
15
|
+
record.errors.add(attribute, message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def values_valid?(values)
|
21
|
+
values.uniq.length == values.length
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/lib/detox/version.rb
CHANGED
@@ -0,0 +1,460 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "active_support/i18n"
|
4
|
+
require "test_class/values_uniqueness_test"
|
5
|
+
|
6
|
+
describe Detox::Validations::ValuesUniquenessValidator do
|
7
|
+
describe "validation result" do
|
8
|
+
context "when given no option" do# {{{
|
9
|
+
let(:test) { ValuesUniquenessTestWithoutOption.new }
|
10
|
+
|
11
|
+
context "when apply to nil" do
|
12
|
+
it "is valid" do
|
13
|
+
test.seq = nil
|
14
|
+
expect(test.valid?).to eq true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when apply to Array" do# {{{
|
19
|
+
context "when apply to [] (empty)" do
|
20
|
+
it "is valid" do
|
21
|
+
test.seq = []
|
22
|
+
expect(test.valid?).to eq true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "when apply to ['1', '2', '3'] (no duplicate value, nil, empty and blank)" do
|
26
|
+
it "is valid" do
|
27
|
+
test.seq = ["1", "2", "3"]
|
28
|
+
expect(test.valid?).to eq true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "when apply to ['1', '3', '1'] (contains duplicate value)" do
|
32
|
+
it "is invalid" do
|
33
|
+
test.seq = ["1", "3", "1"]
|
34
|
+
expect(test.valid?).to eq false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context "when apply to ['1', '2', nil, '3'] (no duplicate value but contains nil)" do
|
38
|
+
it "is valid" do
|
39
|
+
test.seq = ['1', '2', nil, '3']
|
40
|
+
expect(test.valid?).to eq true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context "when apply to ['1', '2', nil, '3', nil] (contains 2 nil)" do
|
44
|
+
it "is invalid" do
|
45
|
+
test.seq = ['1', '2', nil, '3', nil]
|
46
|
+
expect(test.valid?).to eq false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context "when apply to ['1', '2', '', '3'] (no duplicate value but contains empty)" do
|
50
|
+
it "is valid" do
|
51
|
+
test.seq = ['1', '2', "", '3']
|
52
|
+
expect(test.valid?).to eq true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context "when apply to ['1', '2', '', '3', ''] (contains 2 empty)" do
|
56
|
+
it "is invalid" do
|
57
|
+
test.seq = ['1', '2', "", '3', ""]
|
58
|
+
expect(test.valid?).to eq false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "when apply to ['1', '2', ' ', '3'] (no duplicate value but contains blank)" do
|
62
|
+
it "is valid" do
|
63
|
+
test.seq = ['1', '2', " ", '3']
|
64
|
+
expect(test.valid?).to eq true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context "when apply to ['1', '2', ' ', '3', ' '] (contains 2 blank)" do
|
68
|
+
it "is invalid" do
|
69
|
+
test.seq = ['1', '2', " ", '3', " "]
|
70
|
+
expect(test.valid?).to eq false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end# }}}
|
74
|
+
|
75
|
+
context "when apply to Hash" do# {{{
|
76
|
+
context "when apply to {} (empty)" do
|
77
|
+
it "is valid" do
|
78
|
+
test.seq = []
|
79
|
+
expect(test.valid?).to eq true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "when apply to { :a => '2', :b => '3', :c => '1' } (no duplicate value, nil, empty and blank)" do
|
83
|
+
it "is valid" do
|
84
|
+
test.seq = { :a => '2', :b => '3', :c => '1' }
|
85
|
+
expect(test.valid?).to eq true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context "when apply to { :a => '1', :b => '2', :c => '1' } (contains duplicate value)" do
|
89
|
+
it "is invalid" do
|
90
|
+
test.seq = { :a => '1', :b => '2', :c => '1' }
|
91
|
+
expect(test.valid?).to eq false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3' } (no duplicate value but contains nil)" do
|
95
|
+
it "is valid" do
|
96
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3' }
|
97
|
+
expect(test.valid?).to eq true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil } (contains 2 nil)" do
|
101
|
+
it "is invalid" do
|
102
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil }
|
103
|
+
expect(test.valid?).to eq false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3' } (no duplicate value but contains empty)" do
|
107
|
+
it "is valid" do
|
108
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3' }
|
109
|
+
expect(test.valid?).to eq true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3', :e => '' } (contains 2 empty)" do
|
113
|
+
it "is invalid" do
|
114
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3', :e => '' }
|
115
|
+
expect(test.valid?).to eq false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3' } (no duplicate value but contains blank)" do
|
119
|
+
it "is valid" do
|
120
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3' }
|
121
|
+
expect(test.valid?).to eq true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' } (contains 2 blank)" do
|
125
|
+
it "is invalid" do
|
126
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' }
|
127
|
+
expect(test.valid?).to eq false
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end# }}}
|
131
|
+
end# }}}
|
132
|
+
|
133
|
+
context "when given ignore_nil_value option" do# {{{
|
134
|
+
let(:test) { ValuesUniquenessTestWithIgnoreNilValueOption.new }
|
135
|
+
|
136
|
+
context "when apply to nil" do
|
137
|
+
it "is valid" do
|
138
|
+
test.seq = nil
|
139
|
+
expect(test.valid?).to eq true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when apply to Array" do# {{{
|
144
|
+
context "when apply to [] (empty)" do
|
145
|
+
it "is valid" do
|
146
|
+
test.seq = []
|
147
|
+
expect(test.valid?).to eq true
|
148
|
+
end
|
149
|
+
end
|
150
|
+
context "when apply to ['1', '2', '3'] (no duplicate value, nil, empty and blank)" do
|
151
|
+
it "is valid" do
|
152
|
+
test.seq = ["1", "2", "3"]
|
153
|
+
expect(test.valid?).to eq true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context "when apply to ['1', '3', '1'] (contains duplicate value)" do
|
157
|
+
it "is invalid" do
|
158
|
+
test.seq = ["1", "3", "1"]
|
159
|
+
expect(test.valid?).to eq false
|
160
|
+
end
|
161
|
+
end
|
162
|
+
context "when apply to ['1', '2', nil, '3'] (no duplicate value but contains nil)" do
|
163
|
+
it "is valid" do
|
164
|
+
test.seq = ['1', '2', nil, '3']
|
165
|
+
expect(test.valid?).to eq true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
context "when apply to ['1', '2', nil, '3', nil] (contains 2 nil)" do
|
169
|
+
it "is valid" do
|
170
|
+
test.seq = ['1', '2', nil, '3', nil]
|
171
|
+
expect(test.valid?).to eq true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
context "when apply to ['1', '2', '', '3'] (no duplicate value but contains empty)" do
|
175
|
+
it "is valid" do
|
176
|
+
test.seq = ['1', '2', "", '3']
|
177
|
+
expect(test.valid?).to eq true
|
178
|
+
end
|
179
|
+
end
|
180
|
+
context "when apply to ['1', '2', '', '3', ''] (contains 2 empty)" do
|
181
|
+
it "is invalid" do
|
182
|
+
test.seq = ['1', '2', "", '3', ""]
|
183
|
+
expect(test.valid?).to eq false
|
184
|
+
end
|
185
|
+
end
|
186
|
+
context "when apply to ['1', '2', ' ', '3'] (no duplicate value but contains blank)" do
|
187
|
+
it "is valid" do
|
188
|
+
test.seq = ['1', '2', " ", '3']
|
189
|
+
expect(test.valid?).to eq true
|
190
|
+
end
|
191
|
+
end
|
192
|
+
context "when apply to ['1', '2', ' ', '3', ' '] (contains 2 blank)" do
|
193
|
+
it "is invalid" do
|
194
|
+
test.seq = ['1', '2', " ", '3', " "]
|
195
|
+
expect(test.valid?).to eq false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end# }}}
|
199
|
+
|
200
|
+
context "when apply to Hash" do# {{{
|
201
|
+
context "when apply to {} (empty)" do
|
202
|
+
it "is valid" do
|
203
|
+
test.seq = []
|
204
|
+
expect(test.valid?).to eq true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
context "when apply to { :a => '2', :b => '3', :c => '1' } (no duplicate value, nil, empty and blank)" do
|
208
|
+
it "is valid" do
|
209
|
+
test.seq = { :a => '2', :b => '3', :c => '1' }
|
210
|
+
expect(test.valid?).to eq true
|
211
|
+
end
|
212
|
+
end
|
213
|
+
context "when apply to { :a => '1', :b => '2', :c => '1' } (contains duplicate value)" do
|
214
|
+
it "is invalid" do
|
215
|
+
test.seq = { :a => '1', :b => '2', :c => '1' }
|
216
|
+
expect(test.valid?).to eq false
|
217
|
+
end
|
218
|
+
end
|
219
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3' } (no duplicate value but contains nil)" do
|
220
|
+
it "is valid" do
|
221
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3' }
|
222
|
+
expect(test.valid?).to eq true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil } (contains 2 nil)" do
|
226
|
+
it "is valid" do
|
227
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil }
|
228
|
+
expect(test.valid?).to eq true
|
229
|
+
end
|
230
|
+
end
|
231
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3' } (no duplicate value but contains empty)" do
|
232
|
+
it "is valid" do
|
233
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3' }
|
234
|
+
expect(test.valid?).to eq true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3', :e => '' } (contains 2 empty)" do
|
238
|
+
it "is invalid" do
|
239
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3', :e => '' }
|
240
|
+
expect(test.valid?).to eq false
|
241
|
+
end
|
242
|
+
end
|
243
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3' } (no duplicate value but contains blank)" do
|
244
|
+
it "is valid" do
|
245
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3' }
|
246
|
+
expect(test.valid?).to eq true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' } (contains 2 blank)" do
|
250
|
+
it "is invalid" do
|
251
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' }
|
252
|
+
expect(test.valid?).to eq false
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end# }}}
|
256
|
+
end# }}}
|
257
|
+
|
258
|
+
context "when given ignore_blank_value option" do# {{{
|
259
|
+
let(:test) { ValuesUniquenessTestWithIgnoreBlankValueOption.new }
|
260
|
+
|
261
|
+
context "when apply to nil" do
|
262
|
+
it "is valid" do
|
263
|
+
test.seq = nil
|
264
|
+
expect(test.valid?).to eq true
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "when apply to Array" do# {{{
|
269
|
+
context "when apply to [] (empty)" do
|
270
|
+
it "is valid" do
|
271
|
+
test.seq = []
|
272
|
+
expect(test.valid?).to eq true
|
273
|
+
end
|
274
|
+
end
|
275
|
+
context "when apply to ['1', '2', '3'] (no duplicate value, nil, empty and blank)" do
|
276
|
+
it "is valid" do
|
277
|
+
test.seq = ["1", "2", "3"]
|
278
|
+
expect(test.valid?).to eq true
|
279
|
+
end
|
280
|
+
end
|
281
|
+
context "when apply to ['1', '3', '1'] (contains duplicate value)" do
|
282
|
+
it "is invalid" do
|
283
|
+
test.seq = ["1", "3", "1"]
|
284
|
+
expect(test.valid?).to eq false
|
285
|
+
end
|
286
|
+
end
|
287
|
+
context "when apply to ['1', '2', nil, '3'] (no duplicate value but contains nil)" do
|
288
|
+
it "is valid" do
|
289
|
+
test.seq = ['1', '2', nil, '3']
|
290
|
+
expect(test.valid?).to eq true
|
291
|
+
end
|
292
|
+
end
|
293
|
+
context "when apply to ['1', '2', nil, '3', nil] (contains 2 nil)" do
|
294
|
+
it "is valid" do
|
295
|
+
test.seq = ['1', '2', nil, '3', nil]
|
296
|
+
expect(test.valid?).to eq true
|
297
|
+
end
|
298
|
+
end
|
299
|
+
context "when apply to ['1', '2', '', '3'] (no duplicate value but contains empty)" do
|
300
|
+
it "is valid" do
|
301
|
+
test.seq = ['1', '2', "", '3']
|
302
|
+
expect(test.valid?).to eq true
|
303
|
+
end
|
304
|
+
end
|
305
|
+
context "when apply to ['1', '2', '', '3', ''] (contains 2 empty)" do
|
306
|
+
it "is valid" do
|
307
|
+
test.seq = ['1', '2', "", '3', ""]
|
308
|
+
expect(test.valid?).to eq true
|
309
|
+
end
|
310
|
+
end
|
311
|
+
context "when apply to ['1', '2', ' ', '3'] (no duplicate value but contains blank)" do
|
312
|
+
it "is valid" do
|
313
|
+
test.seq = ['1', '2', " ", '3']
|
314
|
+
expect(test.valid?).to eq true
|
315
|
+
end
|
316
|
+
end
|
317
|
+
context "when apply to ['1', '2', ' ', '3', ' '] (contains 2 blank)" do
|
318
|
+
it "is valid" do
|
319
|
+
test.seq = ['1', '2', " ", '3', " "]
|
320
|
+
expect(test.valid?).to eq true
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end# }}}
|
324
|
+
|
325
|
+
context "when apply to Hash" do# {{{
|
326
|
+
context "when apply to {} (empty)" do
|
327
|
+
it "is valid" do
|
328
|
+
test.seq = []
|
329
|
+
expect(test.valid?).to eq true
|
330
|
+
end
|
331
|
+
end
|
332
|
+
context "when apply to { :a => '2', :b => '3', :c => '1' } (no duplicate value, nil, empty and blank)" do
|
333
|
+
it "is valid" do
|
334
|
+
test.seq = { :a => '2', :b => '3', :c => '1' }
|
335
|
+
expect(test.valid?).to eq true
|
336
|
+
end
|
337
|
+
end
|
338
|
+
context "when apply to { :a => '1', :b => '2', :c => '1' } (contains duplicate value)" do
|
339
|
+
it "is invalid" do
|
340
|
+
test.seq = { :a => '1', :b => '2', :c => '1' }
|
341
|
+
expect(test.valid?).to eq false
|
342
|
+
end
|
343
|
+
end
|
344
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3' } (no duplicate value but contains nil)" do
|
345
|
+
it "is valid" do
|
346
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3' }
|
347
|
+
expect(test.valid?).to eq true
|
348
|
+
end
|
349
|
+
end
|
350
|
+
context "when apply to { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil } (contains 2 nil)" do
|
351
|
+
it "is valid" do
|
352
|
+
test.seq = { :a => '1', :b => '2', :c => nil, :d => '3', :e => nil }
|
353
|
+
expect(test.valid?).to eq true
|
354
|
+
end
|
355
|
+
end
|
356
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3' } (no duplicate value but contains empty)" do
|
357
|
+
it "is valid" do
|
358
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3' }
|
359
|
+
expect(test.valid?).to eq true
|
360
|
+
end
|
361
|
+
end
|
362
|
+
context "when apply to { :a => '1', :b => '2', :c => '', :d => '3', :e => '' } (contains 2 empty)" do
|
363
|
+
it "is valid" do
|
364
|
+
test.seq = { :a => '1', :b => '2', :c => '', :d => '3', :e => '' }
|
365
|
+
expect(test.valid?).to eq true
|
366
|
+
end
|
367
|
+
end
|
368
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3' } (no duplicate value but contains blank)" do
|
369
|
+
it "is valid" do
|
370
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3' }
|
371
|
+
expect(test.valid?).to eq true
|
372
|
+
end
|
373
|
+
end
|
374
|
+
context "when apply to { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' } (contains 2 blank)" do
|
375
|
+
it "is valid" do
|
376
|
+
test.seq = { :a => '1', :b => '2', :c => ' ', :d => '3', :e => ' ' }
|
377
|
+
expect(test.valid?).to eq true
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end# }}}
|
381
|
+
end# }}}
|
382
|
+
end
|
383
|
+
|
384
|
+
describe "error message" do
|
385
|
+
context "when given no option" do# {{{
|
386
|
+
let(:test) { ValuesUniquenessTestWithoutOption.new }
|
387
|
+
|
388
|
+
context "when valid" do
|
389
|
+
before do
|
390
|
+
test.seq = ['1', '2', '3']
|
391
|
+
test.valid?
|
392
|
+
end
|
393
|
+
|
394
|
+
it "has no message" do
|
395
|
+
expect(test.errors.present?).to eq false
|
396
|
+
end
|
397
|
+
end
|
398
|
+
context "when invalid" do
|
399
|
+
before do
|
400
|
+
test.seq = ['1', '2', '1']
|
401
|
+
test.valid?
|
402
|
+
end
|
403
|
+
|
404
|
+
it "has 1 error message" do
|
405
|
+
expect(test.errors.empty?).to eq false
|
406
|
+
expect(test.errors.size).to eq 1
|
407
|
+
end
|
408
|
+
it "error message is associated with seq attribute" do
|
409
|
+
expect(test.errors.include?(:seq)).to eq true
|
410
|
+
end
|
411
|
+
it "error messsage is 'Seq contains duplicate value'" do
|
412
|
+
expect(test.errors.full_messages.first).to eq 'Seq contains duplicate value'
|
413
|
+
end
|
414
|
+
end
|
415
|
+
context "when using i18n" do
|
416
|
+
before do
|
417
|
+
@base_locale = I18n.locale
|
418
|
+
I18n.locale = :ja
|
419
|
+
test.seq = ['1', '2', '1']
|
420
|
+
test.valid?
|
421
|
+
end
|
422
|
+
after do
|
423
|
+
I18n.locale = @base_locale
|
424
|
+
end
|
425
|
+
it "error messsage is translated" do
|
426
|
+
expect(test.errors.full_messages.first).to eq 'Seq は重複する値を含んでいます'
|
427
|
+
end
|
428
|
+
end
|
429
|
+
end# }}}
|
430
|
+
|
431
|
+
context "when given message option" do# {{{
|
432
|
+
let(:test) { ValuesUniquenessTestWithMessageOption.new }
|
433
|
+
|
434
|
+
context "when invalid" do
|
435
|
+
before do
|
436
|
+
test.seq = ['1', '2', '1']
|
437
|
+
test.valid?
|
438
|
+
end
|
439
|
+
it "error messsage uses given message" do
|
440
|
+
expect(test.errors.full_messages.first).to eq 'Seq is invalid'
|
441
|
+
end
|
442
|
+
end
|
443
|
+
context "when using i18n" do
|
444
|
+
before do
|
445
|
+
@base_locale = I18n.locale
|
446
|
+
I18n.locale = :ja
|
447
|
+
test.seq = ['1', '2', '1']
|
448
|
+
test.valid?
|
449
|
+
end
|
450
|
+
after do
|
451
|
+
I18n.locale = @base_locale
|
452
|
+
end
|
453
|
+
it "error messsage is not translated" do
|
454
|
+
expect(test.errors.full_messages.first).to eq 'Seq is invalid'
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end# }}}
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "test_class/model_base"
|
3
|
+
|
4
|
+
class ValuesUniquenessTestWithoutOption < ModelBase
|
5
|
+
attr_accessor :seq
|
6
|
+
|
7
|
+
validates :seq, :values_uniqueness => true
|
8
|
+
end
|
9
|
+
|
10
|
+
class ValuesUniquenessTestWithIgnoreNilValueOption < ModelBase
|
11
|
+
attr_accessor :seq
|
12
|
+
|
13
|
+
validates :seq, :values_uniqueness => { :ignore_nil_value => true }
|
14
|
+
end
|
15
|
+
|
16
|
+
class ValuesUniquenessTestWithIgnoreBlankValueOption < ModelBase
|
17
|
+
attr_accessor :seq
|
18
|
+
|
19
|
+
validates :seq, :values_uniqueness => { :ignore_blank_value => true }
|
20
|
+
end
|
21
|
+
|
22
|
+
class ValuesUniquenessTestWithMessageOption < ModelBase
|
23
|
+
attr_accessor :seq
|
24
|
+
|
25
|
+
validates :seq, :values_uniqueness => { :message => "is invalid" }
|
26
|
+
end
|
27
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: detox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pinzolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/detox/validations/any.rb
|
107
107
|
- lib/detox/validations/ordering.rb
|
108
108
|
- lib/detox/validations/possession.rb
|
109
|
+
- lib/detox/validations/values_uniqueness.rb
|
109
110
|
- lib/detox/validity_broker.rb
|
110
111
|
- lib/detox/version.rb
|
111
112
|
- spec/detox/array_validity_spec.rb
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- spec/detox/validations/any_validator_check_validity_spec.rb
|
129
130
|
- spec/detox/validations/ordering_spec.rb
|
130
131
|
- spec/detox/validations/possession_spec.rb
|
132
|
+
- spec/detox/validations/values_uniqueness_spec.rb
|
131
133
|
- spec/detox/validity_broker_spec.rb
|
132
134
|
- spec/spec_helper.rb
|
133
135
|
- spec/test_class/all_absence_test.rb
|
@@ -150,6 +152,7 @@ files:
|
|
150
152
|
- spec/test_class/model_base.rb
|
151
153
|
- spec/test_class/ordering_test.rb
|
152
154
|
- spec/test_class/possession_test.rb
|
155
|
+
- spec/test_class/values_uniqueness_test.rb
|
153
156
|
homepage: https://github.com/pinzolo/detox
|
154
157
|
licenses:
|
155
158
|
- MIT
|
@@ -195,6 +198,7 @@ test_files:
|
|
195
198
|
- spec/detox/validations/any_validator_check_validity_spec.rb
|
196
199
|
- spec/detox/validations/ordering_spec.rb
|
197
200
|
- spec/detox/validations/possession_spec.rb
|
201
|
+
- spec/detox/validations/values_uniqueness_spec.rb
|
198
202
|
- spec/detox/validity_broker_spec.rb
|
199
203
|
- spec/spec_helper.rb
|
200
204
|
- spec/test_class/all_absence_test.rb
|
@@ -217,3 +221,4 @@ test_files:
|
|
217
221
|
- spec/test_class/model_base.rb
|
218
222
|
- spec/test_class/ordering_test.rb
|
219
223
|
- spec/test_class/possession_test.rb
|
224
|
+
- spec/test_class/values_uniqueness_test.rb
|