formkeeper 0.0.13 → 0.0.14
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 +4 -4
- data/Rakefile +1 -1
- data/lib/formkeeper/version.rb +1 -1
- data/lib/formkeeper.rb +17 -12
- data/spec/combination_any_spec.rb +6 -6
- data/spec/combination_date_spec.rb +5 -5
- data/spec/combination_datetime_spec.rb +8 -8
- data/spec/combination_same_spec.rb +4 -4
- data/spec/combination_time_spec.rb +7 -7
- data/spec/constraint_alnum_space_spec.rb +4 -4
- data/spec/constraint_alnum_spec.rb +4 -4
- data/spec/constraint_alpha_space_spec.rb +4 -4
- data/spec/constraint_alpha_spec.rb +4 -4
- data/spec/constraint_ascii_space_spec.rb +4 -4
- data/spec/constraint_ascii_spec.rb +4 -4
- data/spec/constraint_bytesize_spec.rb +5 -5
- data/spec/constraint_email_spec.rb +10 -10
- data/spec/constraint_int_spec.rb +14 -14
- data/spec/constraint_length_spec.rb +5 -5
- data/spec/constraint_regexp_spec.rb +2 -2
- data/spec/constraint_uint_spec.rb +14 -14
- data/spec/constraint_uri_spec.rb +8 -8
- data/spec/record_spec.rb +5 -5
- data/spec/report_spec.rb +36 -9
- data/spec/validator_spec.rb +15 -15
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49bade6105761c7043e33898ec6df3c1384b757b
|
4
|
+
data.tar.gz: c99e1c0952c1f1fc05afc68bee877c9c9280578a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7818cfee006207687639c43c5b018e6d36507d18a76b7fc63c1031c1508bb8082d2716ac7a5382e871c1ae5ef2b08787b805af15143ec61810e42fce77d4f66a
|
7
|
+
data.tar.gz: 97650f0a419d89073b866ab94890bbda3f05787cf15d64a44f6f55140946e1b227f9a13196689c89e8d425deadabc72283adcd5b003f982d57480b64e7892f38
|
data/Rakefile
CHANGED
data/lib/formkeeper/version.rb
CHANGED
data/lib/formkeeper.rb
CHANGED
@@ -101,7 +101,7 @@ module FormKeeper
|
|
101
101
|
def validate(value, arg)
|
102
102
|
result = value =~ /^[\x21-\x7e]+$/
|
103
103
|
result = !result if !arg
|
104
|
-
result
|
104
|
+
!!result
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -109,7 +109,7 @@ module FormKeeper
|
|
109
109
|
def validate(value, arg)
|
110
110
|
result = value =~ /^[\x20-\x7e]+$/
|
111
111
|
result = !result if !arg
|
112
|
-
result
|
112
|
+
!!result
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -117,7 +117,7 @@ module FormKeeper
|
|
117
117
|
def validate(value, arg)
|
118
118
|
r = arg
|
119
119
|
r = ::Regexp.new(r) unless r.kind_of?(::Regexp)
|
120
|
-
value =~ r
|
120
|
+
!!(value =~ r)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -158,7 +158,7 @@ module FormKeeper
|
|
158
158
|
true
|
159
159
|
else
|
160
160
|
result = !result if !arg
|
161
|
-
result
|
161
|
+
!!result
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
@@ -200,7 +200,7 @@ module FormKeeper
|
|
200
200
|
true
|
201
201
|
else
|
202
202
|
result = !result if !arg
|
203
|
-
result
|
203
|
+
!!result
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
@@ -209,7 +209,7 @@ module FormKeeper
|
|
209
209
|
def validate(value, arg)
|
210
210
|
result = value =~ /^[[:alpha:]]+$/
|
211
211
|
result = !result if !arg
|
212
|
-
result
|
212
|
+
!!result
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -217,7 +217,7 @@ module FormKeeper
|
|
217
217
|
def validate(value, arg)
|
218
218
|
result = value =~ /^[[:alpha:][:space:]]+$/
|
219
219
|
result = !result if !arg
|
220
|
-
result
|
220
|
+
!!result
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -225,7 +225,7 @@ module FormKeeper
|
|
225
225
|
def validate(value, arg)
|
226
226
|
result = value =~ /^[[:alnum:]]+$/
|
227
227
|
result = !result if !arg
|
228
|
-
result
|
228
|
+
!!result
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -233,7 +233,7 @@ module FormKeeper
|
|
233
233
|
def validate(value, arg)
|
234
234
|
result = value =~ /^[[:alnum:][:space:]]+$/
|
235
235
|
result = !result if !arg
|
236
|
-
result
|
236
|
+
!!result
|
237
237
|
end
|
238
238
|
end
|
239
239
|
|
@@ -275,7 +275,7 @@ module FormKeeper
|
|
275
275
|
|
276
276
|
def validate(value, arg)
|
277
277
|
r = ::Regexp.new('^' + regexp + '$')
|
278
|
-
value =~ r
|
278
|
+
!!(value =~ r)
|
279
279
|
end
|
280
280
|
|
281
281
|
end
|
@@ -289,7 +289,7 @@ module FormKeeper
|
|
289
289
|
when Range
|
290
290
|
return arg.include?(l)
|
291
291
|
else
|
292
|
-
raise ArgumentError
|
292
|
+
raise ArgumentError, 'Invalid number of arguments'
|
293
293
|
end
|
294
294
|
end
|
295
295
|
end
|
@@ -303,7 +303,7 @@ module FormKeeper
|
|
303
303
|
when Range
|
304
304
|
return arg.include?(l)
|
305
305
|
else
|
306
|
-
raise ArgumentError
|
306
|
+
raise ArgumentError, 'Invalid number of arguments'
|
307
307
|
end
|
308
308
|
end
|
309
309
|
end
|
@@ -447,6 +447,11 @@ module FormKeeper
|
|
447
447
|
def [](name)
|
448
448
|
@valid_params[name.to_sym]
|
449
449
|
end
|
450
|
+
def value(name)
|
451
|
+
name = name.to_sym
|
452
|
+
return self[name] if valid?(name)
|
453
|
+
failed_fields.include?(name) ? @failed_records[name].value : nil
|
454
|
+
end
|
450
455
|
def valid_fields
|
451
456
|
@valid_params.keys
|
452
457
|
end
|
@@ -3,14 +3,14 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe FormKeeper::CombinationConstraint::Any do
|
5
5
|
|
6
|
-
it "
|
6
|
+
it "validates values correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::CombinationConstraint::Any.new
|
9
|
-
constraint.validate(['aaaa', 'bbbb'], true).should
|
10
|
-
constraint.validate(['', ''], true).should_not
|
11
|
-
constraint.validate(['', nil], true).should_not
|
12
|
-
constraint.validate(['aaa', nil], true).should
|
13
|
-
constraint.validate(['aaa', 'bbbb', 'cccc', nil], true).should
|
9
|
+
constraint.validate(['aaaa', 'bbbb'], true).should eql(true)
|
10
|
+
constraint.validate(['', ''], true).should_not eql(true)
|
11
|
+
constraint.validate(['', nil], true).should_not eql(true)
|
12
|
+
constraint.validate(['aaa', nil], true).should eql(true)
|
13
|
+
constraint.validate(['aaa', 'bbbb', 'cccc', nil], true).should eql(true)
|
14
14
|
|
15
15
|
end
|
16
16
|
|
@@ -6,11 +6,11 @@ describe FormKeeper::CombinationConstraint::Date do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::CombinationConstraint::Date.new
|
9
|
-
constraint.validate(['2012', '2', '12'], true).should
|
10
|
-
constraint.validate(['2012', '2', '12', '12'], true).should_not
|
11
|
-
constraint.validate(['aaa', '12', '12'], true).should_not
|
12
|
-
constraint.validate(['2012', '28', '12'], true).should_not
|
13
|
-
constraint.validate(['2012', '2', '50'], true).should_not
|
9
|
+
constraint.validate(['2012', '2', '12'], true).should eql(true)
|
10
|
+
constraint.validate(['2012', '2', '12', '12'], true).should_not eql(true)
|
11
|
+
constraint.validate(['aaa', '12', '12'], true).should_not eql(true)
|
12
|
+
constraint.validate(['2012', '28', '12'], true).should_not eql(true)
|
13
|
+
constraint.validate(['2012', '2', '50'], true).should_not eql(true)
|
14
14
|
|
15
15
|
end
|
16
16
|
|
@@ -6,14 +6,14 @@ describe FormKeeper::CombinationConstraint::DateTime do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::CombinationConstraint::DateTime.new
|
9
|
-
constraint.validate(['2012', '2', '2', '23', '2', '12'], true).should
|
10
|
-
constraint.validate(['2012', '2', '2', '23', '2', '12', '11'], true).should_not
|
11
|
-
constraint.validate(['2012', '2', '2', '23', '2', 'a',], true).should_not
|
12
|
-
constraint.validate(['2012', '13', '2', '23', '2', '12',], true).should_not
|
13
|
-
constraint.validate(['2012', '2', '50', '23', '2', '12',], true).should_not
|
14
|
-
constraint.validate(['2012', '2', '28', '25', '2', '12',], true).should_not
|
15
|
-
constraint.validate(['2012', '2', '28', '23', '60', '12',], true).should_not
|
16
|
-
constraint.validate(['2012', '2', '28', '23', '59', '60',], true).should_not
|
9
|
+
constraint.validate(['2012', '2', '2', '23', '2', '12'], true).should eql(true)
|
10
|
+
constraint.validate(['2012', '2', '2', '23', '2', '12', '11'], true).should_not eql(true)
|
11
|
+
constraint.validate(['2012', '2', '2', '23', '2', 'a',], true).should_not eql(true)
|
12
|
+
constraint.validate(['2012', '13', '2', '23', '2', '12',], true).should_not eql(true)
|
13
|
+
constraint.validate(['2012', '2', '50', '23', '2', '12',], true).should_not eql(true)
|
14
|
+
constraint.validate(['2012', '2', '28', '25', '2', '12',], true).should_not eql(true)
|
15
|
+
constraint.validate(['2012', '2', '28', '23', '60', '12',], true).should_not eql(true)
|
16
|
+
constraint.validate(['2012', '2', '28', '23', '59', '60',], true).should_not eql(true)
|
17
17
|
|
18
18
|
end
|
19
19
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::CombinationConstraint::Same do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::CombinationConstraint::Same.new
|
9
|
-
constraint.validate('aaaa', true).should_not
|
10
|
-
constraint.validate(['aaaa', 'bbbb'], true).should_not
|
11
|
-
constraint.validate(['aaaa', 'aaaa', 'aaaa'], true).should_not
|
12
|
-
constraint.validate(['aaaa', 'aaaa'], true).should
|
9
|
+
constraint.validate('aaaa', true).should_not eql(true)
|
10
|
+
constraint.validate(['aaaa', 'bbbb'], true).should_not eql(true)
|
11
|
+
constraint.validate(['aaaa', 'aaaa', 'aaaa'], true).should_not eql(true)
|
12
|
+
constraint.validate(['aaaa', 'aaaa'], true).should eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,13 +6,13 @@ describe FormKeeper::CombinationConstraint::Time do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::CombinationConstraint::Time.new
|
9
|
-
constraint.validate(['23', '2', '12'], true).should
|
10
|
-
constraint.validate(['23', '2', '12', '11'], true).should_not
|
11
|
-
constraint.validate(['23', '2', 'aa'], true).should_not
|
12
|
-
constraint.validate(['0', '2', '12'], true).should
|
13
|
-
constraint.validate(['-2', '2', '12'], true).should_not
|
14
|
-
constraint.validate(['2', '60', '12'], true).should_not
|
15
|
-
constraint.validate(['2', '2', '60'], true).should_not
|
9
|
+
constraint.validate(['23', '2', '12'], true).should eql(true)
|
10
|
+
constraint.validate(['23', '2', '12', '11'], true).should_not eql(true)
|
11
|
+
constraint.validate(['23', '2', 'aa'], true).should_not eql(true)
|
12
|
+
constraint.validate(['0', '2', '12'], true).should eql(true)
|
13
|
+
constraint.validate(['-2', '2', '12'], true).should_not eql(true)
|
14
|
+
constraint.validate(['2', '60', '12'], true).should_not eql(true)
|
15
|
+
constraint.validate(['2', '2', '60'], true).should_not eql(true)
|
16
16
|
|
17
17
|
end
|
18
18
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::AlnumSpace do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::AlnumSpace.new
|
9
|
-
constraint.validate('abcd', true).should
|
10
|
-
constraint.validate('a1234bcd', true).should
|
11
|
-
constraint.validate('a%[]Aaa', true).should_not
|
12
|
-
constraint.validate('ab cd', true).should
|
9
|
+
constraint.validate('abcd', true).should eql(true)
|
10
|
+
constraint.validate('a1234bcd', true).should eql(true)
|
11
|
+
constraint.validate('a%[]Aaa', true).should_not eql(true)
|
12
|
+
constraint.validate('ab cd', true).should eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::Alnum do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Alnum.new
|
9
|
-
constraint.validate('abcd', true).should
|
10
|
-
constraint.validate('a1234bcd', true).should
|
11
|
-
constraint.validate('a%[]Aaa', true).should_not
|
12
|
-
constraint.validate('ab cd', true).should_not
|
9
|
+
constraint.validate('abcd', true).should eql(true)
|
10
|
+
constraint.validate('a1234bcd', true).should eql(true)
|
11
|
+
constraint.validate('a%[]Aaa', true).should_not eql(true)
|
12
|
+
constraint.validate('ab cd', true).should_not eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::AlphaSpace do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::AlphaSpace.new
|
9
|
-
constraint.validate('abcd', true).should
|
10
|
-
constraint.validate('a1234bcd', true).should_not
|
11
|
-
constraint.validate('a%[]Aaa', true).should_not
|
12
|
-
constraint.validate('ab cd', true).should
|
9
|
+
constraint.validate('abcd', true).should eql(true)
|
10
|
+
constraint.validate('a1234bcd', true).should_not eql(true)
|
11
|
+
constraint.validate('a%[]Aaa', true).should_not eql(true)
|
12
|
+
constraint.validate('ab cd', true).should eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::Alpha do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Alpha.new
|
9
|
-
constraint.validate('abcd', true).should
|
10
|
-
constraint.validate('a1234bcd', true).should_not
|
11
|
-
constraint.validate('a%[]Aaa', true).should_not
|
12
|
-
constraint.validate('ab cd', true).should_not
|
9
|
+
constraint.validate('abcd', true).should eql(true)
|
10
|
+
constraint.validate('a1234bcd', true).should_not eql(true)
|
11
|
+
constraint.validate('a%[]Aaa', true).should_not eql(true)
|
12
|
+
constraint.validate('ab cd', true).should_not eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::AsciiSpace do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::AsciiSpace.new
|
9
|
-
constraint.validate('aaaa', true).should
|
10
|
-
constraint.validate('a%[]Aaa', false).should_not
|
11
|
-
constraint.validate('[aAaa.', true).should
|
12
|
-
constraint.validate('[a Aaa.', true).should
|
9
|
+
constraint.validate('aaaa', true).should eql(true)
|
10
|
+
constraint.validate('a%[]Aaa', false).should_not eql(true)
|
11
|
+
constraint.validate('[aAaa.', true).should eql(true)
|
12
|
+
constraint.validate('[a Aaa.', true).should eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,10 +6,10 @@ describe FormKeeper::Constraint::Ascii do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Ascii.new
|
9
|
-
constraint.validate('aaaa', true).should
|
10
|
-
constraint.validate('a%[]Aaa', false).should_not
|
11
|
-
constraint.validate('[aAaa.', true).should
|
12
|
-
constraint.validate('[a Aaa.', true).should_not
|
9
|
+
constraint.validate('aaaa', true).should eql(true)
|
10
|
+
constraint.validate('a%[]Aaa', false).should_not eql(true)
|
11
|
+
constraint.validate('[aAaa.', true).should eql(true)
|
12
|
+
constraint.validate('[a Aaa.', true).should_not eql(true)
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -6,12 +6,12 @@ describe FormKeeper::Constraint::ByteSize do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::ByteSize.new
|
9
|
-
constraint.validate('aaaa', 0..10).should
|
10
|
-
constraint.validate('aaaa', 0..3).should_not
|
11
|
-
constraint.validate('aaaa', 4).should
|
12
|
-
constraint.validate('aaaa', 3).should_not
|
9
|
+
constraint.validate('aaaa', 0..10).should eql(true)
|
10
|
+
constraint.validate('aaaa', 0..3).should_not eql(true)
|
11
|
+
constraint.validate('aaaa', 4).should eql(true)
|
12
|
+
constraint.validate('aaaa', 3).should_not eql(true)
|
13
13
|
|
14
|
-
constraint.validate('ほげ', 2).should_not
|
14
|
+
constraint.validate('ほげ', 2).should_not eql(true)
|
15
15
|
|
16
16
|
end
|
17
17
|
|
@@ -5,16 +5,16 @@ describe FormKeeper::Constraint::Email do
|
|
5
5
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
constraint = FormKeeper::Constraint::Email.new
|
8
|
-
constraint.validate('lyo.kato@gmail.com', true).should
|
9
|
-
constraint.validate('foo.foo.foo@docomo.ne.jp', true).should
|
10
|
-
constraint.validate('foo.@docomo.ne.jp', true).should
|
11
|
-
constraint.validate('foo..foo@docomo.ne.jp', true).should
|
12
|
-
constraint.validate('lyo.kato', true).should_not
|
13
|
-
constraint.validate('foo@', true).should_not
|
14
|
-
constraint.validate('@foo', true).should_not
|
15
|
-
constraint.validate('.foo@example.com', true).should_not
|
16
|
-
constraint.validate('foo[@example.com', true).should_not
|
17
|
-
constraint.validate('foo @example.com', true).should_not
|
8
|
+
constraint.validate('lyo.kato@gmail.com', true).should eql(true)
|
9
|
+
constraint.validate('foo.foo.foo@docomo.ne.jp', true).should eql(true)
|
10
|
+
constraint.validate('foo.@docomo.ne.jp', true).should eql(true)
|
11
|
+
constraint.validate('foo..foo@docomo.ne.jp', true).should eql(true)
|
12
|
+
constraint.validate('lyo.kato', true).should_not eql(true)
|
13
|
+
constraint.validate('foo@', true).should_not eql(true)
|
14
|
+
constraint.validate('@foo', true).should_not eql(true)
|
15
|
+
constraint.validate('.foo@example.com', true).should_not eql(true)
|
16
|
+
constraint.validate('foo[@example.com', true).should_not eql(true)
|
17
|
+
constraint.validate('foo @example.com', true).should_not eql(true)
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
data/spec/constraint_int_spec.rb
CHANGED
@@ -6,21 +6,21 @@ describe FormKeeper::Constraint::Int do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Int.new
|
9
|
-
constraint.validate('aaaa', true).should_not
|
10
|
-
constraint.validate('aaaa', false).should
|
11
|
-
constraint.validate('1111', true).should
|
12
|
-
constraint.validate('1111', false).should_not
|
13
|
-
constraint.validate('-1111', true).should
|
14
|
-
constraint.validate('-1111', false).should_not
|
9
|
+
constraint.validate('aaaa', true).should_not eql(true)
|
10
|
+
constraint.validate('aaaa', false).should eql(true)
|
11
|
+
constraint.validate('1111', true).should eql(true)
|
12
|
+
constraint.validate('1111', false).should_not eql(true)
|
13
|
+
constraint.validate('-1111', true).should eql(true)
|
14
|
+
constraint.validate('-1111', false).should_not eql(true)
|
15
15
|
|
16
|
-
constraint.validate('1111', {:gt => 111}).should
|
17
|
-
constraint.validate('1111', {:gt => 2222}).should_not
|
18
|
-
constraint.validate('1111', {:gt => 111, :lte => 1111}).should
|
19
|
-
constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not
|
20
|
-
constraint.validate('1111', {:gt => 111, :lt => 1112}).should
|
21
|
-
constraint.validate('1111', {:gte => 1111, :lte => 1111}).should
|
22
|
-
constraint.validate('1111', {:between => 1110..1112}).should
|
23
|
-
constraint.validate('1111', {:between => 1113..1115}).should_not
|
16
|
+
constraint.validate('1111', {:gt => 111}).should eql(true)
|
17
|
+
constraint.validate('1111', {:gt => 2222}).should_not eql(true)
|
18
|
+
constraint.validate('1111', {:gt => 111, :lte => 1111}).should eql(true)
|
19
|
+
constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not eql(true)
|
20
|
+
constraint.validate('1111', {:gt => 111, :lt => 1112}).should eql(true)
|
21
|
+
constraint.validate('1111', {:gte => 1111, :lte => 1111}).should eql(true)
|
22
|
+
constraint.validate('1111', {:between => 1110..1112}).should eql(true)
|
23
|
+
constraint.validate('1111', {:between => 1113..1115}).should_not eql(true)
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
@@ -6,12 +6,12 @@ describe FormKeeper::Constraint::Length do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Length.new
|
9
|
-
constraint.validate('aaaa', 0..10).should
|
10
|
-
constraint.validate('aaaa', 0..3).should_not
|
11
|
-
constraint.validate('aaaa', 4).should
|
12
|
-
constraint.validate('aaaa', 3).should_not
|
9
|
+
constraint.validate('aaaa', 0..10).should eql(true)
|
10
|
+
constraint.validate('aaaa', 0..3).should_not eql(true)
|
11
|
+
constraint.validate('aaaa', 4).should eql(true)
|
12
|
+
constraint.validate('aaaa', 3).should_not eql(true)
|
13
13
|
|
14
|
-
constraint.validate('ほげ', 2).should
|
14
|
+
constraint.validate('ほげ', 2).should eql(true)
|
15
15
|
|
16
16
|
end
|
17
17
|
|
@@ -6,8 +6,8 @@ describe FormKeeper::Constraint::Regexp do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Regexp.new
|
9
|
-
constraint.validate('this is ruby', %r{ruby}).should
|
10
|
-
constraint.validate('this is perl', %r{ruby}).should_not
|
9
|
+
constraint.validate('this is ruby', %r{ruby}).should eql(true)
|
10
|
+
constraint.validate('this is perl', %r{ruby}).should_not eql(true)
|
11
11
|
|
12
12
|
end
|
13
13
|
|
@@ -6,21 +6,21 @@ describe FormKeeper::Constraint::Uint do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::Uint.new
|
9
|
-
constraint.validate('aaaa', true).should_not
|
10
|
-
constraint.validate('aaaa', false).should
|
11
|
-
constraint.validate('1111', true).should
|
12
|
-
constraint.validate('1111', false).should_not
|
13
|
-
constraint.validate('-1111', true).should_not
|
14
|
-
constraint.validate('-1111', false).should
|
9
|
+
constraint.validate('aaaa', true).should_not eql(true)
|
10
|
+
constraint.validate('aaaa', false).should eql(true)
|
11
|
+
constraint.validate('1111', true).should eql(true)
|
12
|
+
constraint.validate('1111', false).should_not eql(true)
|
13
|
+
constraint.validate('-1111', true).should_not eql(true)
|
14
|
+
constraint.validate('-1111', false).should eql(true)
|
15
15
|
|
16
|
-
constraint.validate('1111', {:gt => 111}).should
|
17
|
-
constraint.validate('1111', {:gt => 2222}).should_not
|
18
|
-
constraint.validate('1111', {:gt => 111, :lte => 1111}).should
|
19
|
-
constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not
|
20
|
-
constraint.validate('1111', {:gt => 111, :lt => 1112}).should
|
21
|
-
constraint.validate('1111', {:gte => 1111, :lte => 1111}).should
|
22
|
-
constraint.validate('1111', {:between => 1110..1112}).should
|
23
|
-
constraint.validate('1111', {:between => 1113..1115}).should_not
|
16
|
+
constraint.validate('1111', {:gt => 111}).should eql(true)
|
17
|
+
constraint.validate('1111', {:gt => 2222}).should_not eql(true)
|
18
|
+
constraint.validate('1111', {:gt => 111, :lte => 1111}).should eql(true)
|
19
|
+
constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not eql(true)
|
20
|
+
constraint.validate('1111', {:gt => 111, :lt => 1112}).should eql(true)
|
21
|
+
constraint.validate('1111', {:gte => 1111, :lte => 1111}).should eql(true)
|
22
|
+
constraint.validate('1111', {:between => 1110..1112}).should eql(true)
|
23
|
+
constraint.validate('1111', {:between => 1113..1115}).should_not eql(true)
|
24
24
|
|
25
25
|
end
|
26
26
|
|
data/spec/constraint_uri_spec.rb
CHANGED
@@ -6,15 +6,15 @@ describe FormKeeper::Constraint::URI do
|
|
6
6
|
it "validate value correctly" do
|
7
7
|
|
8
8
|
constraint = FormKeeper::Constraint::URI.new
|
9
|
-
constraint.validate('aaaa', :http).should_not
|
10
|
-
constraint.validate('http://example.org/', :http).should
|
11
|
-
constraint.validate('http://example.org/', [:http]).should
|
12
|
-
constraint.validate('https://example.org/', [:http]).should_not
|
13
|
-
constraint.validate('http://example.org/', [:http, :https]).should
|
14
|
-
constraint.validate('https://example.org/', [:http, :https]).should
|
9
|
+
constraint.validate('aaaa', :http).should_not eql(true)
|
10
|
+
constraint.validate('http://example.org/', :http).should eql(true)
|
11
|
+
constraint.validate('http://example.org/', [:http]).should eql(true)
|
12
|
+
constraint.validate('https://example.org/', [:http]).should_not eql(true)
|
13
|
+
constraint.validate('http://example.org/', [:http, :https]).should eql(true)
|
14
|
+
constraint.validate('https://example.org/', [:http, :https]).should eql(true)
|
15
15
|
|
16
|
-
constraint.validate('aaaa', :http).should_not
|
17
|
-
constraint.validate('aaa', [:http, :https]).should_not
|
16
|
+
constraint.validate('aaaa', :http).should_not eql(true)
|
17
|
+
constraint.validate('aaa', [:http, :https]).should_not eql(true)
|
18
18
|
|
19
19
|
end
|
20
20
|
|
data/spec/record_spec.rb
CHANGED
@@ -11,15 +11,15 @@ describe FormKeeper::Record do
|
|
11
11
|
record.value = 'foo'
|
12
12
|
record.value.should == 'foo'
|
13
13
|
|
14
|
-
record.failed?.should_not
|
14
|
+
record.failed?.should_not eql(true)
|
15
15
|
|
16
16
|
record.fail(:present)
|
17
17
|
record.fail(:length)
|
18
18
|
|
19
|
-
record.failed?.should
|
20
|
-
record.failed_by?(:present).should
|
21
|
-
record.failed_by?(:length).should
|
22
|
-
record.failed_by?(:bytesize).should_not
|
19
|
+
record.failed?.should eql(true)
|
20
|
+
record.failed_by?(:present).should eql(true)
|
21
|
+
record.failed_by?(:length).should eql(true)
|
22
|
+
record.failed_by?(:bytesize).should_not eql(true)
|
23
23
|
|
24
24
|
record.failed_constraints[0].should == :present
|
25
25
|
record.failed_constraints[1].should == :length
|
data/spec/report_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe FormKeeper::Report do
|
|
13
13
|
report << record1
|
14
14
|
report << record2
|
15
15
|
|
16
|
-
report.failed?.should_not
|
16
|
+
report.failed?.should_not eql(true)
|
17
17
|
report[:username].should == 'foo'
|
18
18
|
report[:password].should == 'bar'
|
19
19
|
|
@@ -36,14 +36,14 @@ describe FormKeeper::Report do
|
|
36
36
|
report << record2
|
37
37
|
report << record3
|
38
38
|
|
39
|
-
report.failed?.should
|
40
|
-
report.failed_on?(:password).should
|
41
|
-
report.failed_on?(:password, :length).should
|
42
|
-
report.failed_on?(:password, :present).should_not
|
43
|
-
report.failed_on?(:email).should
|
44
|
-
report.failed_on?(:email, :present).should
|
45
|
-
report.failed_on?(:email, :length).should
|
46
|
-
report.failed_on?(:email, :ascii).should_not
|
39
|
+
report.failed?.should eql(true)
|
40
|
+
report.failed_on?(:password).should eql(true)
|
41
|
+
report.failed_on?(:password, :length).should eql(true)
|
42
|
+
report.failed_on?(:password, :present).should_not eql(true)
|
43
|
+
report.failed_on?(:email).should eql(true)
|
44
|
+
report.failed_on?(:email, :present).should eql(true)
|
45
|
+
report.failed_on?(:email, :length).should eql(true)
|
46
|
+
report.failed_on?(:email, :ascii).should_not eql(true)
|
47
47
|
report[:username].should == 'foo'
|
48
48
|
report[:password].should be_nil
|
49
49
|
report[:email].should be_nil
|
@@ -79,5 +79,32 @@ describe FormKeeper::Report do
|
|
79
79
|
report.message(:login, :password, :length).should == "Password's length should be between 8 and 16"
|
80
80
|
end
|
81
81
|
|
82
|
+
it "provides access to form inputs" do
|
83
|
+
|
84
|
+
messages = FormKeeper::Messages.from_file(File.dirname(__FILE__) + '/asset/messages.yaml')
|
85
|
+
|
86
|
+
report = FormKeeper::Report.new(messages)
|
87
|
+
record1 = FormKeeper::Record.new(:name)
|
88
|
+
record1.value = 'foo'
|
89
|
+
record2 = FormKeeper::Record.new(:email)
|
90
|
+
record2.value = 'bar'
|
91
|
+
record3 = FormKeeper::Record.new(:contact)
|
92
|
+
record3.value = 'baz'
|
93
|
+
record2.fail(:email)
|
94
|
+
|
95
|
+
report << record1
|
96
|
+
report << record2
|
97
|
+
report << record3
|
98
|
+
|
99
|
+
report.value(:name).should eql('foo')
|
100
|
+
report.value(:email).should eql('bar')
|
101
|
+
report.value(:contact).should eql('baz')
|
102
|
+
|
103
|
+
#expect {
|
104
|
+
# report.value(:blegga)
|
105
|
+
#}.to raise_error(ArgumentError, "unknown field :blegga")
|
106
|
+
report.value(:blegga).should be_nil
|
107
|
+
end
|
108
|
+
|
82
109
|
|
83
110
|
end
|
data/spec/validator_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe FormKeeper::Validator do
|
|
19
19
|
validator = FormKeeper::Validator.new
|
20
20
|
report = validator.validate(params, rule)
|
21
21
|
|
22
|
-
report.failed?.should_not
|
22
|
+
report.failed?.should_not eql(true)
|
23
23
|
|
24
24
|
report[:username].should == 'hogehogefoo'
|
25
25
|
report[:password].should == 'hogehogebar'
|
@@ -46,7 +46,7 @@ describe FormKeeper::Validator do
|
|
46
46
|
validator = FormKeeper::Validator.new
|
47
47
|
report = validator.validate(params, rule)
|
48
48
|
|
49
|
-
report.failed?.should_not
|
49
|
+
report.failed?.should_not eql(true)
|
50
50
|
|
51
51
|
report[:username].should == 'hogehogefoo'
|
52
52
|
report[:password].should == 'hogehogebar'
|
@@ -73,7 +73,7 @@ describe FormKeeper::Validator do
|
|
73
73
|
validator = FormKeeper::Validator.new
|
74
74
|
report = validator.validate(params, rule)
|
75
75
|
|
76
|
-
report.failed?.should_not
|
76
|
+
report.failed?.should_not eql(true)
|
77
77
|
|
78
78
|
report[:username].should == 'hogehogefoo'
|
79
79
|
report[:password].should == 'hogehogebar'
|
@@ -101,8 +101,8 @@ describe FormKeeper::Validator do
|
|
101
101
|
report[:username].should == 'hogehogefoo'
|
102
102
|
report[:nickname].should == 'HOGEHOGE BUZ'
|
103
103
|
|
104
|
-
report.failed?.should
|
105
|
-
report.failed_on?(:password).should
|
104
|
+
report.failed?.should eql(true)
|
105
|
+
report.failed_on?(:password).should eql(true)
|
106
106
|
|
107
107
|
end
|
108
108
|
|
@@ -122,7 +122,7 @@ describe FormKeeper::Validator do
|
|
122
122
|
validator = FormKeeper::Validator.new
|
123
123
|
report = validator.validate(params, rule)
|
124
124
|
|
125
|
-
report.failed?.should_not
|
125
|
+
report.failed?.should_not eql(true)
|
126
126
|
#valid_params.keys.size.should == 3
|
127
127
|
report[:username].should == 'hogehogefoo'
|
128
128
|
report[:password].should == 'hogehogebar'
|
@@ -150,7 +150,7 @@ describe FormKeeper::Validator do
|
|
150
150
|
report[:username].should == 'hogehogefoo'
|
151
151
|
report[:password].should == 'hogehogebar'
|
152
152
|
|
153
|
-
report.failed?.should
|
153
|
+
report.failed?.should eql(true)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "validates empty checkbox params" do
|
@@ -173,7 +173,7 @@ describe FormKeeper::Validator do
|
|
173
173
|
report[:username].should == 'hogehogefoo'
|
174
174
|
report[:password].should == 'hogehogebar'
|
175
175
|
|
176
|
-
report.failed?.should
|
176
|
+
report.failed?.should eql(true)
|
177
177
|
|
178
178
|
end
|
179
179
|
|
@@ -197,7 +197,7 @@ describe FormKeeper::Validator do
|
|
197
197
|
report[:username].should == 'hogehogefoo'
|
198
198
|
report[:password].should == 'hogehogebar'
|
199
199
|
|
200
|
-
report.failed?.should
|
200
|
+
report.failed?.should eql(true)
|
201
201
|
|
202
202
|
end
|
203
203
|
|
@@ -222,7 +222,7 @@ describe FormKeeper::Validator do
|
|
222
222
|
report[:password].should == 'hogehogebar'
|
223
223
|
report[:colors].should == ['white', 'black']
|
224
224
|
|
225
|
-
report.failed?.should_not
|
225
|
+
report.failed?.should_not eql(true)
|
226
226
|
|
227
227
|
end
|
228
228
|
|
@@ -246,7 +246,7 @@ describe FormKeeper::Validator do
|
|
246
246
|
report[:username].should == 'hogehogefoo'
|
247
247
|
report[:password].should == 'hogehogebar'
|
248
248
|
|
249
|
-
report.failed?.should
|
249
|
+
report.failed?.should eql(true)
|
250
250
|
report.failed_on?(:colors)
|
251
251
|
end
|
252
252
|
|
@@ -271,7 +271,7 @@ describe FormKeeper::Validator do
|
|
271
271
|
report[:username].should == 'hogehogefoo'
|
272
272
|
report[:password].should == 'hogehogebar'
|
273
273
|
|
274
|
-
report.failed?.should_not
|
274
|
+
report.failed?.should_not eql(true)
|
275
275
|
|
276
276
|
end
|
277
277
|
|
@@ -296,7 +296,7 @@ describe FormKeeper::Validator do
|
|
296
296
|
report[:username].should == 'hogehogefoo'
|
297
297
|
report[:password].should == 'hogehogebar'
|
298
298
|
|
299
|
-
report.failed?.should_not
|
299
|
+
report.failed?.should_not eql(true)
|
300
300
|
|
301
301
|
end
|
302
302
|
|
@@ -321,8 +321,8 @@ describe FormKeeper::Validator do
|
|
321
321
|
report[:username].should == 'hogehogefoo'
|
322
322
|
report[:password].should == 'hogehogebar'
|
323
323
|
|
324
|
-
report.failed?.should
|
325
|
-
report.failed_on?(:same_email_address).should
|
324
|
+
report.failed?.should eql(true)
|
325
|
+
report.failed_on?(:same_email_address).should eql(true)
|
326
326
|
|
327
327
|
end
|
328
328
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formkeeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lyokato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hpricot
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Helper library for stuff around HTML forms
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -124,17 +124,17 @@ require_paths:
|
|
124
124
|
- lib
|
125
125
|
required_ruby_version: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- -
|
127
|
+
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
129
|
version: '0'
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
|
-
- -
|
132
|
+
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
137
|
+
rubygems_version: 2.2.2
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: This modules provides you an easy way for form-validation and fill-in-form
|