formeze 2.1.0 → 2.1.1
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 -1
- data/spec/formeze_spec.rb +33 -0
- metadata +2 -2
data/formeze.gemspec
CHANGED
data/lib/formeze.rb
CHANGED
@@ -142,8 +142,16 @@ module Formeze
|
|
142
142
|
@options.has_key?(:when) ? form.instance_eval(&@options[:when]) : true
|
143
143
|
end
|
144
144
|
|
145
|
+
def field_value?(form)
|
146
|
+
form.send(@field.name) =~ /\S/
|
147
|
+
end
|
148
|
+
|
149
|
+
def field_errors?(form)
|
150
|
+
form.errors_on?(@field.name)
|
151
|
+
end
|
152
|
+
|
145
153
|
def validate(form)
|
146
|
-
if validates?(form) && !
|
154
|
+
if validates?(form) && field_value?(form) && !field_errors?(form)
|
147
155
|
return_value = if @block.arity == 1
|
148
156
|
@block.call(form.send(@field.name))
|
149
157
|
else
|
data/spec/formeze_spec.rb
CHANGED
@@ -665,6 +665,39 @@ describe 'FormWithCustomMinimumSpendValidation after parsing invalid input' do
|
|
665
665
|
end
|
666
666
|
end
|
667
667
|
|
668
|
+
class FormWithOptionalFieldAndCustomValidation < Formeze::Form
|
669
|
+
field :website, :required => false
|
670
|
+
|
671
|
+
validates :website do
|
672
|
+
website =~ /\./ && website !~ /\s/
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
describe 'FormWithOptionalFieldAndCustomValidation after parsing blank input' do
|
677
|
+
before do
|
678
|
+
@form = FormWithOptionalFieldAndCustomValidation.new
|
679
|
+
@form.parse('website=')
|
680
|
+
end
|
681
|
+
|
682
|
+
describe 'valid query method' do
|
683
|
+
it 'returns true' do
|
684
|
+
@form.valid?.must_equal(true)
|
685
|
+
end
|
686
|
+
end
|
687
|
+
|
688
|
+
describe 'errors method' do
|
689
|
+
it 'returns an empty array' do
|
690
|
+
@form.errors.must_be_empty
|
691
|
+
end
|
692
|
+
end
|
693
|
+
|
694
|
+
describe 'errors_on query method' do
|
695
|
+
it 'returns false when given the field name' do
|
696
|
+
@form.errors_on?(:website).must_equal(false)
|
697
|
+
end
|
698
|
+
end
|
699
|
+
end
|
700
|
+
|
668
701
|
describe 'FormWithField on Rails' do
|
669
702
|
before do
|
670
703
|
@form = FormWithField.new
|
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: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|