detox 1.0.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 +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +19 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +40 -0
- data/Rakefile +11 -0
- data/detox.gemspec +27 -0
- data/gemfiles/activemodel_3_2_x.gemfile +5 -0
- data/gemfiles/activemodel_4_0_x.gemfile +5 -0
- data/lib/active_model/validations/absence.rb +19 -0
- data/lib/detox.rb +11 -0
- data/lib/detox/array_validity.rb +23 -0
- data/lib/detox/locales/en.yml +21 -0
- data/lib/detox/locales/ja.yml +21 -0
- data/lib/detox/validations/all.rb +41 -0
- data/lib/detox/validations/any.rb +57 -0
- data/lib/detox/validations/ordering.rb +34 -0
- data/lib/detox/validations/possession.rb +30 -0
- data/lib/detox/validity_broker.rb +55 -0
- data/lib/detox/version.rb +4 -0
- data/spec/detox/array_validity_spec.rb +214 -0
- data/spec/detox/validations/all_absence_spec.rb +147 -0
- data/spec/detox/validations/all_acceptance_spec.rb +352 -0
- data/spec/detox/validations/all_exclusion_spec.rb +137 -0
- data/spec/detox/validations/all_format_spec.rb +351 -0
- data/spec/detox/validations/all_inclusion_spec.rb +352 -0
- data/spec/detox/validations/all_length_spec.rb +388 -0
- data/spec/detox/validations/all_numericality_spec.rb +369 -0
- data/spec/detox/validations/all_presence_spec.rb +159 -0
- data/spec/detox/validations/any_absence_spec.rb +597 -0
- data/spec/detox/validations/any_acceptance_spec.rb +597 -0
- data/spec/detox/validations/any_exclusion_spec.rb +597 -0
- data/spec/detox/validations/any_format_spec.rb +597 -0
- data/spec/detox/validations/any_inclusion_spec.rb +597 -0
- data/spec/detox/validations/any_length_spec.rb +597 -0
- data/spec/detox/validations/any_numericality_spec.rb +609 -0
- data/spec/detox/validations/any_presence_spec.rb +596 -0
- data/spec/detox/validations/any_validator_check_validity_spec.rb +126 -0
- data/spec/detox/validations/ordering_spec.rb +452 -0
- data/spec/detox/validations/possession_spec.rb +263 -0
- data/spec/detox/validity_broker_spec.rb +126 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/test_class/all_absence_test.rb +14 -0
- data/spec/test_class/all_acceptance_test.rb +27 -0
- data/spec/test_class/all_exclusion_test.rb +15 -0
- data/spec/test_class/all_format_test.rb +26 -0
- data/spec/test_class/all_inclusion_test.rb +27 -0
- data/spec/test_class/all_length_test.rb +28 -0
- data/spec/test_class/all_numericality_test.rb +33 -0
- data/spec/test_class/all_presence_test.rb +14 -0
- data/spec/test_class/any_absence_test.rb +33 -0
- data/spec/test_class/any_acceptance_test.rb +34 -0
- data/spec/test_class/any_exclusion_test.rb +34 -0
- data/spec/test_class/any_format_test.rb +34 -0
- data/spec/test_class/any_inclusion_test.rb +33 -0
- data/spec/test_class/any_length_test.rb +33 -0
- data/spec/test_class/any_numericality_test.rb +35 -0
- data/spec/test_class/any_presence_test.rb +33 -0
- data/spec/test_class/array_validity_test.rb +6 -0
- data/spec/test_class/model_base.rb +11 -0
- data/spec/test_class/ordering_test.rb +33 -0
- data/spec/test_class/possession_test.rb +22 -0
- metadata +219 -0
@@ -0,0 +1,597 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "active_support/i18n"
|
4
|
+
require "test_class/any_format_test"
|
5
|
+
|
6
|
+
describe Detox::Validations::AnyFormatValidator do
|
7
|
+
describe "validation result" do
|
8
|
+
context "when given no additional option" do# {{{
|
9
|
+
let(:test) { AnyFormatTest.new }
|
10
|
+
|
11
|
+
context "when apply to nil" do
|
12
|
+
it "is valid" do
|
13
|
+
test.words = 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.words = []
|
22
|
+
expect(test.valid?).to eq true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context "when apply to [nil, '', ' '] (all words are nil or empty or blank)" do
|
26
|
+
it "is invalid" do
|
27
|
+
test.words = [nil, "", " "]
|
28
|
+
expect(test.valid?).to eq false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "when apply to ['foo', 'b@r', 'b@r', 'b@r', 'b@r'] (1 valid value)" do
|
32
|
+
it "is valid" do
|
33
|
+
test.words = ['foo', 'b@r', 'b@r', 'b@r', 'b@r']
|
34
|
+
expect(test.valid?).to eq true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context "when apply to ['foo', 'foo', 'b@r', 'b@r', 'b@r'] (2 valid words)" do
|
38
|
+
it "is valid" do
|
39
|
+
test.words = ['foo', 'foo', 'b@r', 'b@r', 'b@r']
|
40
|
+
expect(test.valid?).to eq true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
context "when apply to ['foo', 'foo', 'foo', 'b@r', 'b@r'] (3 valid words)" do
|
44
|
+
it "is valid" do
|
45
|
+
test.words = ['foo', 'foo', 'foo', 'b@r', 'b@r']
|
46
|
+
expect(test.valid?).to eq true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'b@r'] (4 valid words)" do
|
50
|
+
it "is valid" do
|
51
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
52
|
+
expect(test.valid?).to eq true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'foo'] (all valid words)" do
|
56
|
+
it "is valid" do
|
57
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'foo']
|
58
|
+
expect(test.valid?).to eq true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end# }}}
|
62
|
+
|
63
|
+
context "when apply to Hash" do# {{{
|
64
|
+
context "when apply to {} (empty)" do
|
65
|
+
it "is valid" do
|
66
|
+
test.words = {}
|
67
|
+
expect(test.valid?).to eq true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "when apply to { :a => nil, :b => '', :c => ' ' } (all words are nil or empty or blank)" do
|
71
|
+
it "is invalid" do
|
72
|
+
test.words = { :a => nil, :b => "", :c => " " }
|
73
|
+
expect(test.valid?).to eq false
|
74
|
+
end
|
75
|
+
end
|
76
|
+
context "when apply to { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (1 valid value)" do
|
77
|
+
it "is valid" do
|
78
|
+
test.words = { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
79
|
+
expect(test.valid?).to eq true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (2 valid words)" do
|
83
|
+
it "is valid" do
|
84
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
85
|
+
expect(test.valid?).to eq true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' } (3 valid words)" do
|
89
|
+
it "is valid" do
|
90
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
91
|
+
expect(test.valid?).to eq true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' } (4 valid words)" do
|
95
|
+
it "is valid" do
|
96
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' }
|
97
|
+
expect(test.valid?).to eq true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' } (all valid words)" do
|
101
|
+
it "is valid" do
|
102
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' }
|
103
|
+
expect(test.valid?).to eq true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end# }}}
|
107
|
+
end# }}}
|
108
|
+
|
109
|
+
context "when given only :min_valid_count option" do# {{{
|
110
|
+
let(:test) { AnyFormatTestWithMinValidCountOnly.new }
|
111
|
+
|
112
|
+
context "when apply to nil" do
|
113
|
+
it "is valid" do
|
114
|
+
test.words = nil
|
115
|
+
expect(test.valid?).to eq true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when apply to Array" do# {{{
|
120
|
+
context "when apply to [] (empty)" do
|
121
|
+
it "is valid" do
|
122
|
+
test.words = []
|
123
|
+
expect(test.valid?).to eq true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
context "when apply to [nil, '', ' '] (all words are nil or empty or blank)" do
|
127
|
+
it "is invalid" do
|
128
|
+
test.words = [nil, "", " "]
|
129
|
+
expect(test.valid?).to eq false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context "when apply to ['foo', 'b@r', 'b@r', 'b@r', 'b@r'] (1 valid value)" do
|
133
|
+
it "is invalid" do
|
134
|
+
test.words = ['foo', 'b@r', 'b@r', 'b@r', 'b@r']
|
135
|
+
expect(test.valid?).to eq false
|
136
|
+
end
|
137
|
+
end
|
138
|
+
context "when apply to ['foo', 'foo', 'b@r', 'b@r', 'b@r'] (2 valid words)" do
|
139
|
+
it "is valid" do
|
140
|
+
test.words = ['foo', 'foo', 'b@r', 'b@r', 'b@r']
|
141
|
+
expect(test.valid?).to eq true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
context "when apply to ['foo', 'foo', 'foo', 'b@r', 'b@r'] (3 valid words)" do
|
145
|
+
it "is valid" do
|
146
|
+
test.words = ['foo', 'foo', 'foo', 'b@r', 'b@r']
|
147
|
+
expect(test.valid?).to eq true
|
148
|
+
end
|
149
|
+
end
|
150
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'b@r'] (4 valid words)" do
|
151
|
+
it "is valid" do
|
152
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
153
|
+
expect(test.valid?).to eq true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'foo'] (all valid words)" do
|
157
|
+
it "is valid" do
|
158
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'foo']
|
159
|
+
expect(test.valid?).to eq true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end# }}}
|
163
|
+
|
164
|
+
context "when apply to Hash" do# {{{
|
165
|
+
context "when apply to {} (empty)" do
|
166
|
+
it "is valid" do
|
167
|
+
test.words = {}
|
168
|
+
expect(test.valid?).to eq true
|
169
|
+
end
|
170
|
+
end
|
171
|
+
context "when apply to { :a => nil, :b => '', :c => ' ' } (all words are nil or empty or blank)" do
|
172
|
+
it "is invalid" do
|
173
|
+
test.words = { :a => nil, :b => "", :c => " " }
|
174
|
+
expect(test.valid?).to eq false
|
175
|
+
end
|
176
|
+
end
|
177
|
+
context "when apply to { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (1 valid value)" do
|
178
|
+
it "is invalid" do
|
179
|
+
test.words = { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
180
|
+
expect(test.valid?).to eq false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (2 valid words)" do
|
184
|
+
it "is valid" do
|
185
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
186
|
+
expect(test.valid?).to eq true
|
187
|
+
end
|
188
|
+
end
|
189
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' } (3 valid words)" do
|
190
|
+
it "is valid" do
|
191
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' }
|
192
|
+
expect(test.valid?).to eq true
|
193
|
+
end
|
194
|
+
end
|
195
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' } (4 valid words)" do
|
196
|
+
it "is valid" do
|
197
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' }
|
198
|
+
expect(test.valid?).to eq true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' } (all valid words)" do
|
202
|
+
it "is valid" do
|
203
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' }
|
204
|
+
expect(test.valid?).to eq true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end# }}}
|
208
|
+
end# }}}
|
209
|
+
|
210
|
+
context "when given only :max_valid_count option" do# {{{
|
211
|
+
let(:test) { AnyFormatTestWithMaxValidCountOnly.new }
|
212
|
+
|
213
|
+
context "when apply to nil" do
|
214
|
+
it "is valid" do
|
215
|
+
test.words = nil
|
216
|
+
expect(test.valid?).to eq true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when apply to Array" do# {{{
|
221
|
+
context "when apply to [] (empty)" do
|
222
|
+
it "is valid" do
|
223
|
+
test.words = []
|
224
|
+
expect(test.valid?).to eq true
|
225
|
+
end
|
226
|
+
end
|
227
|
+
context "when apply to [nil, '', ' '] (all words are nil or empty or blank)" do
|
228
|
+
it "is invalid" do
|
229
|
+
test.words = [nil, "", " "]
|
230
|
+
expect(test.valid?).to eq false
|
231
|
+
end
|
232
|
+
end
|
233
|
+
context "when apply to ['foo', 'b@r', 'b@r', 'b@r', 'b@r'] (1 valid value)" do
|
234
|
+
it "is valid" do
|
235
|
+
test.words = ['foo', 'b@r', 'b@r', 'b@r', 'b@r']
|
236
|
+
expect(test.valid?).to eq true
|
237
|
+
end
|
238
|
+
end
|
239
|
+
context "when apply to ['foo', 'foo', 'b@r', 'b@r', 'b@r'] (2 valid words)" do
|
240
|
+
it "is valid" do
|
241
|
+
test.words = ['foo', 'foo', 'b@r', 'b@r', 'b@r']
|
242
|
+
expect(test.valid?).to eq true
|
243
|
+
end
|
244
|
+
end
|
245
|
+
context "when apply to ['foo', 'foo', 'foo', 'b@r', 'b@r'] (3 valid words)" do
|
246
|
+
it "is valid" do
|
247
|
+
test.words = ['foo', 'foo', 'foo', 'b@r', 'b@r']
|
248
|
+
expect(test.valid?).to eq true
|
249
|
+
end
|
250
|
+
end
|
251
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'b@r'] (4 valid words)" do
|
252
|
+
it "is invalid" do
|
253
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
254
|
+
expect(test.valid?).to eq false
|
255
|
+
end
|
256
|
+
end
|
257
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'foo'] (all valid words)" do
|
258
|
+
it "is invalid" do
|
259
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'foo']
|
260
|
+
expect(test.valid?).to eq false
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end# }}}
|
264
|
+
|
265
|
+
context "when apply to Hash" do# {{{
|
266
|
+
context "when apply to {} (empty)" do
|
267
|
+
it "is valid" do
|
268
|
+
test.words = {}
|
269
|
+
expect(test.valid?).to eq true
|
270
|
+
end
|
271
|
+
end
|
272
|
+
context "when apply to { :a => nil, :b => '', :c => ' ' } (all words are nil or empty or blank)" do
|
273
|
+
it "is invalid" do
|
274
|
+
test.words = { :a => nil, :b => "", :c => " " }
|
275
|
+
expect(test.valid?).to eq false
|
276
|
+
end
|
277
|
+
end
|
278
|
+
context "when apply to { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (1 valid value)" do
|
279
|
+
it "is valid" do
|
280
|
+
test.words = { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
281
|
+
expect(test.valid?).to eq true
|
282
|
+
end
|
283
|
+
end
|
284
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (2 valid words)" do
|
285
|
+
it "is valid" do
|
286
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
287
|
+
expect(test.valid?).to eq true
|
288
|
+
end
|
289
|
+
end
|
290
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' } (3 valid words)" do
|
291
|
+
it "is valid" do
|
292
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' }
|
293
|
+
expect(test.valid?).to eq true
|
294
|
+
end
|
295
|
+
end
|
296
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' } (4 valid words)" do
|
297
|
+
it "is invalid" do
|
298
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' }
|
299
|
+
expect(test.valid?).to eq false
|
300
|
+
end
|
301
|
+
end
|
302
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' } (all valid words)" do
|
303
|
+
it "is invalid" do
|
304
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' }
|
305
|
+
expect(test.valid?).to eq false
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end# }}}
|
309
|
+
end# }}}
|
310
|
+
|
311
|
+
context "when given :min_valid_count and :max_valid_count option" do# {{{
|
312
|
+
let(:test) { AnyFormatTestWithBothValidCount.new }
|
313
|
+
|
314
|
+
context "when apply to nil" do
|
315
|
+
it "is valid" do
|
316
|
+
test.words = nil
|
317
|
+
expect(test.valid?).to eq true
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context "when apply to Array" do# {{{
|
322
|
+
context "when apply to [] (empty)" do
|
323
|
+
it "is valid" do
|
324
|
+
test.words = []
|
325
|
+
expect(test.valid?).to eq true
|
326
|
+
end
|
327
|
+
end
|
328
|
+
context "when apply to [nil, '', ' '] (all words are nil or empty or blank)" do
|
329
|
+
it "is invalid" do
|
330
|
+
test.words = [nil, "", " "]
|
331
|
+
expect(test.valid?).to eq false
|
332
|
+
end
|
333
|
+
end
|
334
|
+
context "when apply to ['foo', 'b@r', 'b@r', 'b@r', 'b@r'] (1 valid value)" do
|
335
|
+
it "is invalid" do
|
336
|
+
test.words = ['foo', 'b@r', 'b@r', 'b@r', 'b@r']
|
337
|
+
expect(test.valid?).to eq false
|
338
|
+
end
|
339
|
+
end
|
340
|
+
context "when apply to ['foo', 'foo', 'b@r', 'b@r', 'b@r'] (2 valid words)" do
|
341
|
+
it "is valid" do
|
342
|
+
test.words = ['foo', 'foo', 'b@r', 'b@r', 'b@r']
|
343
|
+
expect(test.valid?).to eq true
|
344
|
+
end
|
345
|
+
end
|
346
|
+
context "when apply to ['foo', 'foo', 'foo', 'b@r', 'b@r'] (3 valid words)" do
|
347
|
+
it "is valid" do
|
348
|
+
test.words = ['foo', 'foo', 'foo', 'b@r', 'b@r']
|
349
|
+
expect(test.valid?).to eq true
|
350
|
+
end
|
351
|
+
end
|
352
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'b@r'] (4 valid words)" do
|
353
|
+
it "is invalid" do
|
354
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
355
|
+
expect(test.valid?).to eq false
|
356
|
+
end
|
357
|
+
end
|
358
|
+
context "when apply to ['foo', 'foo', 'foo', 'foo', 'foo'] (all valid words)" do
|
359
|
+
it "is invalid" do
|
360
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'foo']
|
361
|
+
expect(test.valid?).to eq false
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end# }}}
|
365
|
+
|
366
|
+
context "when apply to Hash" do# {{{
|
367
|
+
context "when apply to {} (empty)" do
|
368
|
+
it "is valid" do
|
369
|
+
test.words = {}
|
370
|
+
expect(test.valid?).to eq true
|
371
|
+
end
|
372
|
+
end
|
373
|
+
context "when apply to { :a => nil, :b => '', :c => ' ' } (all words are nil or empty or blank)" do
|
374
|
+
it "is invalid" do
|
375
|
+
test.words = { :a => nil, :b => "", :c => " " }
|
376
|
+
expect(test.valid?).to eq false
|
377
|
+
end
|
378
|
+
end
|
379
|
+
context "when apply to { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (1 valid value)" do
|
380
|
+
it "is invalid" do
|
381
|
+
test.words = { :a => 'foo', :b => 'b@r', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
382
|
+
expect(test.valid?).to eq false
|
383
|
+
end
|
384
|
+
end
|
385
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r' :e => 'b@r' } (2 valid words)" do
|
386
|
+
it "is valid" do
|
387
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'b@r', :d => 'b@r', :e => 'b@r' }
|
388
|
+
expect(test.valid?).to eq true
|
389
|
+
end
|
390
|
+
end
|
391
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' } (3 valid words)" do
|
392
|
+
it "is valid" do
|
393
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'b@r', :e => 'b@r' }
|
394
|
+
expect(test.valid?).to eq true
|
395
|
+
end
|
396
|
+
end
|
397
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' } (4 valid words)" do
|
398
|
+
it "is invalid" do
|
399
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'b@r' }
|
400
|
+
expect(test.valid?).to eq false
|
401
|
+
end
|
402
|
+
end
|
403
|
+
context "when apply to { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' } (all valid words)" do
|
404
|
+
it "is invalid" do
|
405
|
+
test.words = { :a => 'foo', :b => 'foo', :c => 'foo', :d => 'foo', :e => 'foo' }
|
406
|
+
expect(test.valid?).to eq false
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end# }}}
|
410
|
+
end# }}}
|
411
|
+
end
|
412
|
+
|
413
|
+
describe "error message" do
|
414
|
+
context "when given no option" do# {{{
|
415
|
+
let(:test) { AnyFormatTest.new }
|
416
|
+
|
417
|
+
context "when valid" do
|
418
|
+
before do
|
419
|
+
test.words = ['foo', 'foo', 'b@r']
|
420
|
+
test.valid?
|
421
|
+
end
|
422
|
+
|
423
|
+
it "has no message" do
|
424
|
+
expect(test.errors.present?).to eq false
|
425
|
+
end
|
426
|
+
end
|
427
|
+
context "when invalid" do
|
428
|
+
before do
|
429
|
+
test.words = ['b@r', "", " "]
|
430
|
+
test.valid?
|
431
|
+
end
|
432
|
+
|
433
|
+
it "has 1 error message" do
|
434
|
+
expect(test.errors.empty?).to eq false
|
435
|
+
expect(test.errors.size).to eq 1
|
436
|
+
end
|
437
|
+
it "error message is associated with words attribute" do
|
438
|
+
expect(test.errors.include?(:words)).to eq true
|
439
|
+
end
|
440
|
+
it %q{error messsage is "Words must be valid format (required number is 1-)"} do
|
441
|
+
expect(test.errors.full_messages.first).to eq "Words must be valid format (required number is 1-)"
|
442
|
+
end
|
443
|
+
end
|
444
|
+
context "when using i18n" do
|
445
|
+
before do
|
446
|
+
@base_locale = I18n.locale
|
447
|
+
I18n.locale = :ja
|
448
|
+
test.words = ['b@r', "", " "]
|
449
|
+
test.valid?
|
450
|
+
end
|
451
|
+
after do
|
452
|
+
I18n.locale = @base_locale
|
453
|
+
end
|
454
|
+
it "error messsage is translated" do
|
455
|
+
expect(test.errors.full_messages.first).to eq "Words は必要数(1~)が正しい形式でなければなりません"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end# }}}
|
459
|
+
|
460
|
+
context "when given :min_valid_count option" do# {{{
|
461
|
+
let(:test) { AnyFormatTestWithMinValidCountOnly.new }
|
462
|
+
|
463
|
+
context "when invalid" do
|
464
|
+
before do
|
465
|
+
test.words = ['foo', "", " "]
|
466
|
+
test.valid?
|
467
|
+
end
|
468
|
+
|
469
|
+
it "has 1 error message" do
|
470
|
+
expect(test.errors.empty?).to eq false
|
471
|
+
expect(test.errors.size).to eq 1
|
472
|
+
end
|
473
|
+
it "error message is associated with words attribute" do
|
474
|
+
expect(test.errors.include?(:words)).to eq true
|
475
|
+
end
|
476
|
+
it %q{error messsage is "Words must be valid format (required number is 2-)"} do
|
477
|
+
expect(test.errors.full_messages.first).to eq "Words must be valid format (required number is 2-)"
|
478
|
+
end
|
479
|
+
end
|
480
|
+
context "when using i18n" do
|
481
|
+
before do
|
482
|
+
@base_locale = I18n.locale
|
483
|
+
I18n.locale = :ja
|
484
|
+
test.words = ['foo', "", " "]
|
485
|
+
test.valid?
|
486
|
+
end
|
487
|
+
after do
|
488
|
+
I18n.locale = @base_locale
|
489
|
+
end
|
490
|
+
it "error messsage is translated" do
|
491
|
+
expect(test.errors.full_messages.first).to eq "Words は必要数(2~)が正しい形式でなければなりません"
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end# }}}
|
495
|
+
|
496
|
+
context "when given :max_valid_count option" do# {{{
|
497
|
+
let(:test) { AnyFormatTestWithMaxValidCountOnly.new }
|
498
|
+
|
499
|
+
context "when invalid" do
|
500
|
+
before do
|
501
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
502
|
+
test.valid?
|
503
|
+
end
|
504
|
+
|
505
|
+
it "has 1 error message" do
|
506
|
+
expect(test.errors.empty?).to eq false
|
507
|
+
expect(test.errors.size).to eq 1
|
508
|
+
end
|
509
|
+
it "error message is associated with words attribute" do
|
510
|
+
expect(test.errors.include?(:words)).to eq true
|
511
|
+
end
|
512
|
+
it %q{error messsage is "Words must be valid format (required number is 1-3)"} do
|
513
|
+
expect(test.errors.full_messages.first).to eq "Words must be valid format (required number is 1-3)"
|
514
|
+
end
|
515
|
+
end
|
516
|
+
context "when using i18n" do
|
517
|
+
before do
|
518
|
+
@base_locale = I18n.locale
|
519
|
+
I18n.locale = :ja
|
520
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
521
|
+
test.valid?
|
522
|
+
end
|
523
|
+
after do
|
524
|
+
I18n.locale = @base_locale
|
525
|
+
end
|
526
|
+
it "error messsage is translated" do
|
527
|
+
expect(test.errors.full_messages.first).to eq "Words は必要数(1~3)が正しい形式でなければなりません"
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end# }}}
|
531
|
+
|
532
|
+
context "when given :min_valid_count and :max_valid_count option" do# {{{
|
533
|
+
let(:test) { AnyFormatTestWithBothValidCount.new }
|
534
|
+
|
535
|
+
context "when invalid" do
|
536
|
+
before do
|
537
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
538
|
+
test.valid?
|
539
|
+
end
|
540
|
+
|
541
|
+
it "has 1 error message" do
|
542
|
+
expect(test.errors.empty?).to eq false
|
543
|
+
expect(test.errors.size).to eq 1
|
544
|
+
end
|
545
|
+
it "error message is associated with words attribute" do
|
546
|
+
expect(test.errors.include?(:words)).to eq true
|
547
|
+
end
|
548
|
+
it %q{error messsage is "Words must be valid format (required number is 2-3)"} do
|
549
|
+
expect(test.errors.full_messages.first).to eq "Words must be valid format (required number is 2-3)"
|
550
|
+
end
|
551
|
+
end
|
552
|
+
context "when using i18n" do
|
553
|
+
before do
|
554
|
+
@base_locale = I18n.locale
|
555
|
+
I18n.locale = :ja
|
556
|
+
test.words = ['foo', 'foo', 'foo', 'foo', 'b@r']
|
557
|
+
test.valid?
|
558
|
+
end
|
559
|
+
after do
|
560
|
+
I18n.locale = @base_locale
|
561
|
+
end
|
562
|
+
it "error messsage is translated" do
|
563
|
+
expect(test.errors.full_messages.first).to eq "Words は必要数(2~3)が正しい形式でなければなりません"
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end# }}}
|
567
|
+
|
568
|
+
context "when given message option" do# {{{
|
569
|
+
let(:test) { AnyFormatTestWithMessageOption.new }
|
570
|
+
|
571
|
+
context "when invalid" do
|
572
|
+
before do
|
573
|
+
test.words = ['b@r', "", " "]
|
574
|
+
test.valid?
|
575
|
+
end
|
576
|
+
it "error messsage uses given message" do
|
577
|
+
expect(test.errors.full_messages.first).to eq 'Words is invalid'
|
578
|
+
end
|
579
|
+
end
|
580
|
+
context "when using i18n" do
|
581
|
+
before do
|
582
|
+
@base_locale = I18n.locale
|
583
|
+
I18n.locale = :ja
|
584
|
+
test.words = ['b@r', "", " "]
|
585
|
+
test.valid?
|
586
|
+
end
|
587
|
+
after do
|
588
|
+
I18n.locale = @base_locale
|
589
|
+
end
|
590
|
+
it "error messsage is not translated" do
|
591
|
+
expect(test.errors.full_messages.first).to eq 'Words is invalid'
|
592
|
+
end
|
593
|
+
end
|
594
|
+
end# }}}
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|