formeze 1.1.0 → 1.1.1
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.
- data/formeze.gemspec +1 -1
- data/lib/formeze.rb +7 -7
- data/spec/formeze_spec.rb +8 -0
- metadata +1 -1
data/formeze.gemspec
CHANGED
data/lib/formeze.rb
CHANGED
@@ -19,17 +19,17 @@ module Formeze
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def validate(value, &error)
|
22
|
-
error.call(
|
22
|
+
error.call(:'is required') if required? && value !~ /\S/
|
23
23
|
|
24
|
-
error.call(
|
24
|
+
error.call(:'has too many lines') if !multiline? && value.lines.count > 1
|
25
25
|
|
26
|
-
error.call(
|
26
|
+
error.call(:'has too many characters') if value.chars.count > char_limit
|
27
27
|
|
28
|
-
error.call(
|
28
|
+
error.call(:'has too many words') if word_limit? && value.scan(/\w+/).length > word_limit
|
29
29
|
|
30
|
-
error.call(
|
30
|
+
error.call(:'is invalid') if pattern? && value !~ pattern
|
31
31
|
|
32
|
-
error.call(
|
32
|
+
error.call(:'is invalid') if values? && !values.include?(value)
|
33
33
|
end
|
34
34
|
|
35
35
|
def key
|
@@ -202,7 +202,7 @@ module Formeze
|
|
202
202
|
unless form_data.has_key?(field.key)
|
203
203
|
next if field.multiple? || !field.key_required?
|
204
204
|
|
205
|
-
raise KeyError
|
205
|
+
raise KeyError, "missing form key: #{field.key}"
|
206
206
|
end
|
207
207
|
|
208
208
|
values = form_data.delete(field.key)
|
data/spec/formeze_spec.rb
CHANGED
@@ -77,6 +77,14 @@ describe 'FormWithField after parsing blank input' do
|
|
77
77
|
@form.valid?.must_equal(false)
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
describe 'errors method' do
|
82
|
+
it 'should return an array containing an error message' do
|
83
|
+
@form.errors.must_be_instance_of(Array)
|
84
|
+
@form.errors.length.must_equal(1)
|
85
|
+
@form.errors.first.to_s.must_equal('Title is required')
|
86
|
+
end
|
87
|
+
end
|
80
88
|
end
|
81
89
|
|
82
90
|
describe 'FormWithField after parsing input containing newlines' do
|