formkeeper 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/formkeeper.rb CHANGED
@@ -212,24 +212,27 @@ module FormKeeper
212
212
  class Date < Base
213
213
  def validate(values, arg)
214
214
  return false unless values.size == 3
215
+ return false unless values.all? { |v| v =~ /^[[:digit:]]+$/ }
215
216
  # TODO handle range by args[:from] and args[:to]
216
- ::Date.valid_date?(values[0], values[1], values[2])
217
+ ::Date.valid_date?(values[0].to_i, values[1].to_i, values[2].to_i)
217
218
  end
218
219
  end
219
220
 
220
221
  class Time < Base
221
222
  def validate(values, arg)
222
223
  return false unless values.size == 3
224
+ return false unless values.all? { |v| v =~ /^[[:digit:]]+$/ }
223
225
  # TODO handle range by args[:from] and args[:to]
224
- (0..23).include?(values[0]) and (0..59).include(values[1]) and (0..59).include(values[2])
226
+ (0..23).include?(values[0].to_i) and (0..59).include?(values[1].to_i) and (0..59).include?(values[2].to_i)
225
227
  end
226
228
  end
227
229
 
228
230
  class DateTime < Base
229
231
  def validate(values, arg)
230
232
  return false unless values.size == 6
233
+ return false unless values.all? { |v| v =~ /^[[:digit:]]+$/ }
231
234
  # TODO handle range by args[:from] and args[:to]
232
- ::Date.valid_date?(values[0], values[1], values[2]) and (0..23).include?(values[3]) and (0..59).include(values[5]) and (0..59).include(values[5])
235
+ ::Date.valid_date?(values[0].to_i, values[1].to_i, values[2].to_i) and (0..23).include?(values[3].to_i) and (0..59).include?(values[4].to_i) and (0..59).include?(values[5].to_i)
233
236
  end
234
237
  end
235
238
  end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::CombinationConstraint::Any do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::CombinationConstraint::Any.new
9
+ constraint.validate(['aaaa', 'bbbb'], true).should be_true
10
+ constraint.validate(['', ''], true).should_not be_true
11
+ constraint.validate(['', nil], true).should_not be_true
12
+ constraint.validate(['aaa', nil], true).should be_true
13
+ constraint.validate(['aaa', 'bbbb', 'cccc', nil], true).should be_true
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::CombinationConstraint::Date do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::CombinationConstraint::Date.new
9
+ constraint.validate(['2012', '2', '12'], true).should be_true
10
+ constraint.validate(['2012', '2', '12', '12'], true).should_not be_true
11
+ constraint.validate(['aaa', '12', '12'], true).should_not be_true
12
+ constraint.validate(['2012', '28', '12'], true).should_not be_true
13
+ constraint.validate(['2012', '2', '50'], true).should_not be_true
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::CombinationConstraint::DateTime do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::CombinationConstraint::DateTime.new
9
+ constraint.validate(['2012', '2', '2', '23', '2', '12'], true).should be_true
10
+ constraint.validate(['2012', '2', '2', '23', '2', '12', '11'], true).should_not be_true
11
+ constraint.validate(['2012', '2', '2', '23', '2', 'a',], true).should_not be_true
12
+ constraint.validate(['2012', '13', '2', '23', '2', '12',], true).should_not be_true
13
+ constraint.validate(['2012', '2', '50', '23', '2', '12',], true).should_not be_true
14
+ constraint.validate(['2012', '2', '28', '25', '2', '12',], true).should_not be_true
15
+ constraint.validate(['2012', '2', '28', '23', '60', '12',], true).should_not be_true
16
+ constraint.validate(['2012', '2', '28', '23', '59', '60',], true).should_not be_true
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::CombinationConstraint::Same do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::CombinationConstraint::Same.new
9
+ constraint.validate('aaaa', true).should_not be_true
10
+ constraint.validate(['aaaa', 'bbbb'], true).should_not be_true
11
+ constraint.validate(['aaaa', 'aaaa', 'aaaa'], true).should_not be_true
12
+ constraint.validate(['aaaa', 'aaaa'], true).should be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::CombinationConstraint::Time do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::CombinationConstraint::Time.new
9
+ constraint.validate(['23', '2', '12'], true).should be_true
10
+ constraint.validate(['23', '2', '12', '11'], true).should_not be_true
11
+ constraint.validate(['23', '2', 'aa'], true).should_not be_true
12
+ constraint.validate(['0', '2', '12'], true).should be_true
13
+ constraint.validate(['-2', '2', '12'], true).should_not be_true
14
+ constraint.validate(['2', '60', '12'], true).should_not be_true
15
+ constraint.validate(['2', '2', '60'], true).should_not be_true
16
+
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -28,6 +28,11 @@ files:
28
28
  - lib/formkeeper.rb
29
29
  - lib/formkeeper/version.rb
30
30
  - spec/asset/messages.yaml
31
+ - spec/combination_any_spec.rb
32
+ - spec/combination_date_spec.rb
33
+ - spec/combination_datetime_spec.rb
34
+ - spec/combination_same_spec.rb
35
+ - spec/combination_time_spec.rb
31
36
  - spec/constraint_alnum_space_spec.rb
32
37
  - spec/constraint_alnum_spec.rb
33
38
  - spec/constraint_alpha_space_spec.rb
@@ -64,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
69
  version: '0'
65
70
  segments:
66
71
  - 0
67
- hash: -2485237141662980897
72
+ hash: 356989708151318593
68
73
  required_rubygems_version: !ruby/object:Gem::Requirement
69
74
  none: false
70
75
  requirements:
@@ -73,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
78
  version: '0'
74
79
  segments:
75
80
  - 0
76
- hash: -2485237141662980897
81
+ hash: 356989708151318593
77
82
  requirements: []
78
83
  rubyforge_project:
79
84
  rubygems_version: 1.8.24
@@ -82,6 +87,11 @@ specification_version: 3
82
87
  summary: This modules provides you an easy way for form-validation and fill-in-form
83
88
  test_files:
84
89
  - spec/asset/messages.yaml
90
+ - spec/combination_any_spec.rb
91
+ - spec/combination_date_spec.rb
92
+ - spec/combination_datetime_spec.rb
93
+ - spec/combination_same_spec.rb
94
+ - spec/combination_time_spec.rb
85
95
  - spec/constraint_alnum_space_spec.rb
86
96
  - spec/constraint_alnum_spec.rb
87
97
  - spec/constraint_alpha_space_spec.rb