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 CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'formeze'
3
- s.version = '1.1.1'
3
+ s.version = '1.1.2'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
data/lib/formeze.rb CHANGED
@@ -19,17 +19,19 @@ module Formeze
19
19
  end
20
20
 
21
21
  def validate(value, &error)
22
- error.call(:'is required') if required? && value !~ /\S/
23
-
24
- error.call(:'has too many lines') if !multiline? && value.lines.count > 1
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
- error.call(:'has too many characters') if value.chars.count > char_limit
27
+ error.call(:'has too many characters') if value.chars.count > char_limit
27
28
 
28
- error.call(:'has too many words') if word_limit? && value.scan(/\w+/).length > word_limit
29
+ error.call(:'has too many words') if word_limit? && value.scan(/\w+/).length > word_limit
29
30
 
30
- error.call(:'is invalid') if pattern? && value !~ pattern
31
+ error.call(:'is invalid') if pattern? && value !~ pattern
31
32
 
32
- error.call(:'is invalid') if values? && !values.include?(value)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formeze
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: