formeze 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/formeze.gemspec +1 -1
- data/lib/formeze.rb +9 -7
- data/spec/formeze_spec.rb +19 -0
- metadata +1 -1
data/formeze.gemspec
CHANGED
data/lib/formeze.rb
CHANGED
@@ -19,17 +19,19 @@ module Formeze
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def validate(value, &error)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if value !~ /\S/ # blank
|
23
|
+
error.call(:'is required') if required?
|
24
|
+
else
|
25
|
+
error.call(:'has too many lines') if !multiline? && value.lines.count > 1
|
25
26
|
|
26
|
-
|
27
|
+
error.call(:'has too many characters') if value.chars.count > char_limit
|
27
28
|
|
28
|
-
|
29
|
+
error.call(:'has too many words') if word_limit? && value.scan(/\w+/).length > word_limit
|
29
30
|
|
30
|
-
|
31
|
+
error.call(:'is invalid') if pattern? && value !~ pattern
|
31
32
|
|
32
|
-
|
33
|
+
error.call(:'is invalid') if values? && !values.include?(value)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
|
35
37
|
def key
|
data/spec/formeze_spec.rb
CHANGED
@@ -418,6 +418,25 @@ describe 'FormWithOptionalKey after parsing input without the key' do
|
|
418
418
|
end
|
419
419
|
end
|
420
420
|
|
421
|
+
class FormWithOptionalFieldThatCanOnlyHaveSpecifiedValues
|
422
|
+
Formeze.setup(self)
|
423
|
+
|
424
|
+
field :size, required: false, values: %w(S M L XL)
|
425
|
+
end
|
426
|
+
|
427
|
+
describe 'FormWithOptionalFieldThatCanOnlyHaveSpecifiedValues after parsing blank input' do
|
428
|
+
before do
|
429
|
+
@form = FormWithOptionalFieldThatCanOnlyHaveSpecifiedValues.new
|
430
|
+
@form.parse('size=')
|
431
|
+
end
|
432
|
+
|
433
|
+
describe 'valid query method' do
|
434
|
+
it 'should return true' do
|
435
|
+
@form.valid?.must_equal(true)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
421
440
|
Rails = Object.new
|
422
441
|
|
423
442
|
class RailsForm
|