formkeeper 0.0.4 → 0.0.5

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.
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/formkeeper.rb CHANGED
@@ -87,10 +87,18 @@ module FormKeeper
87
87
  end
88
88
  end
89
89
 
90
+ class AsciiSpace < Base
91
+ def validate(value, arg)
92
+ result = value =~ /^[\x20-\x7e]+$/
93
+ result = !result if !arg
94
+ result
95
+ end
96
+ end
97
+
90
98
  class Regexp < Base
91
99
  def validate(value, arg)
92
100
  r = arg
93
- r = Regexp.new(r) unless r.kind_of?(Regexp)
101
+ r = ::Regexp.new(r) unless r.kind_of?(::Regexp)
94
102
  value =~ r
95
103
  end
96
104
  end
@@ -145,7 +153,7 @@ module FormKeeper
145
153
 
146
154
  class URI < Base
147
155
  def validate(value, arg)
148
- u = URI.parse(value)
156
+ u = ::URI.parse(value)
149
157
  return false if u.nil?
150
158
  arg = [arg] unless arg.kind_of?(Array)
151
159
  arg.collect(&:to_s).include?(u.scheme)
@@ -166,12 +174,12 @@ module FormKeeper
166
174
  end
167
175
  end
168
176
 
169
- class Characters < Base
177
+ class ByteSize < Base
170
178
  def validate(value, arg)
171
- l = value.split(//u).length
179
+ l = value.bytesize
172
180
  case arg
173
181
  when Fixnum
174
- return (l == args)
182
+ return (l == arg)
175
183
  when Range
176
184
  return arg.include?(l)
177
185
  else
@@ -564,6 +572,7 @@ module FormKeeper
564
572
  register_filter :upcase, Filter::UpCase.new
565
573
 
566
574
  register_constraint :ascii, Constraint::Ascii.new
575
+ register_constraint :ascii_space, Constraint::AsciiSpace.new
567
576
  register_constraint :regexp, Constraint::Regexp.new
568
577
  register_constraint :int, Constraint::Int.new
569
578
  register_constraint :uint, Constraint::Uint.new
@@ -573,7 +582,7 @@ module FormKeeper
573
582
  register_constraint :alnum_space, Constraint::AlnumSpace.new
574
583
  register_constraint :uri, Constraint::URI.new
575
584
  register_constraint :length, Constraint::Length.new
576
- register_constraint :characters, Constraint::Characters.new
585
+ register_constraint :bytesize, Constraint::ByteSize.new
577
586
 
578
587
  register_combination_constraint :datetime, CombinationConstraint::DateTime.new
579
588
  register_combination_constraint :date, CombinationConstraint::Date.new
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::AlnumSpace do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::AlnumSpace.new
9
+ constraint.validate('abcd', true).should be_true
10
+ constraint.validate('a1234bcd', true).should be_true
11
+ constraint.validate('a%[]Aaa', true).should_not be_true
12
+ constraint.validate('ab cd', true).should be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Alnum do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Alnum.new
9
+ constraint.validate('abcd', true).should be_true
10
+ constraint.validate('a1234bcd', true).should be_true
11
+ constraint.validate('a%[]Aaa', true).should_not be_true
12
+ constraint.validate('ab cd', true).should_not be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::AlphaSpace do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::AlphaSpace.new
9
+ constraint.validate('abcd', true).should be_true
10
+ constraint.validate('a1234bcd', true).should_not be_true
11
+ constraint.validate('a%[]Aaa', true).should_not be_true
12
+ constraint.validate('ab cd', true).should be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Alpha do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Alpha.new
9
+ constraint.validate('abcd', true).should be_true
10
+ constraint.validate('a1234bcd', true).should_not be_true
11
+ constraint.validate('a%[]Aaa', true).should_not be_true
12
+ constraint.validate('ab cd', true).should_not be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::AsciiSpace do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::AsciiSpace.new
9
+ constraint.validate('aaaa', true).should be_true
10
+ constraint.validate('a%[]Aaa', false).should_not be_true
11
+ constraint.validate('[aAaa.', true).should be_true
12
+ constraint.validate('[a Aaa.', true).should be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Ascii do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Ascii.new
9
+ constraint.validate('aaaa', true).should be_true
10
+ constraint.validate('a%[]Aaa', false).should_not be_true
11
+ constraint.validate('[aAaa.', true).should be_true
12
+ constraint.validate('[a Aaa.', true).should_not be_true
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::ByteSize do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::ByteSize.new
9
+ constraint.validate('aaaa', 0..10).should be_true
10
+ constraint.validate('aaaa', 0..3).should_not be_true
11
+ constraint.validate('aaaa', 4).should be_true
12
+ constraint.validate('aaaa', 3).should_not be_true
13
+
14
+ constraint.validate('ほげ', 2).should_not be_true
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Int do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Int.new
9
+ constraint.validate('aaaa', true).should_not be_true
10
+ constraint.validate('aaaa', false).should be_true
11
+ constraint.validate('1111', true).should be_true
12
+ constraint.validate('1111', false).should_not be_true
13
+ constraint.validate('-1111', true).should be_true
14
+ constraint.validate('-1111', false).should_not be_true
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Length do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Length.new
9
+ constraint.validate('aaaa', 0..10).should be_true
10
+ constraint.validate('aaaa', 0..3).should_not be_true
11
+ constraint.validate('aaaa', 4).should be_true
12
+ constraint.validate('aaaa', 3).should_not be_true
13
+
14
+ constraint.validate('ほげ', 2).should be_true
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Regexp do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Regexp.new
9
+ constraint.validate('this is ruby', %r{ruby}).should be_true
10
+ constraint.validate('this is perl', %r{ruby}).should_not be_true
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::Uint do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::Uint.new
9
+ constraint.validate('aaaa', true).should_not be_true
10
+ constraint.validate('aaaa', false).should be_true
11
+ constraint.validate('1111', true).should be_true
12
+ constraint.validate('1111', false).should_not be_true
13
+ constraint.validate('-1111', true).should_not be_true
14
+ constraint.validate('-1111', false).should be_true
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Constraint::URI do
5
+
6
+ it "validate value correctly" do
7
+
8
+ constraint = FormKeeper::Constraint::URI.new
9
+ constraint.validate('aaaa', :http).should_not be_true
10
+ constraint.validate('http://example.org/', :http).should be_true
11
+ constraint.validate('http://example.org/', [:http]).should be_true
12
+ constraint.validate('https://example.org/', [:http]).should_not be_true
13
+ constraint.validate('http://example.org/', [:http, :https]).should be_true
14
+ constraint.validate('https://example.org/', [:http, :https]).should be_true
15
+
16
+ constraint.validate('aaaa', :http).should_not be_true
17
+ constraint.validate('aaa', [:http, :https]).should_not be_true
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormKeeper::Filter::DownCase do
4
+
5
+ it "filters value correctly" do
6
+ filter = FormKeeper::Filter::DownCase.new
7
+ filter.process("foo").should == "foo";
8
+ filter.process("Foo").should == "foo";
9
+ filter.process("FOO").should == "foo";
10
+ filter.process(" FOO").should == " foo";
11
+ end
12
+
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormKeeper::Filter::Strip do
4
+
5
+ it "filters value correctly" do
6
+ filter = FormKeeper::Filter::Strip.new
7
+ filter.process("foo").should == "foo";
8
+ filter.process(" foo").should == "foo";
9
+ filter.process("foo ").should == "foo";
10
+ filter.process(" foo ").should == "foo";
11
+ filter.process(" foo ").should == "foo";
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormKeeper::Filter::UpCase do
4
+
5
+ it "filters value correctly" do
6
+ filter = FormKeeper::Filter::UpCase.new
7
+ filter.process("FOO").should == "FOO";
8
+ filter.process("fOO").should == "FOO";
9
+ filter.process("foo").should == "FOO";
10
+ filter.process(" foo").should == " FOO";
11
+ end
12
+
13
+ end
data/spec/record_spec.rb CHANGED
@@ -19,7 +19,7 @@ describe FormKeeper::Record do
19
19
  record.failed?.should be_true
20
20
  record.failed_by?(:present).should be_true
21
21
  record.failed_by?(:length).should be_true
22
- record.failed_by?(:characters).should_not be_true
22
+ record.failed_by?(:bytesize).should_not be_true
23
23
 
24
24
  record.failed_constraints[0].should == :present
25
25
  record.failed_constraints[1].should == :length
@@ -45,9 +45,9 @@ describe FormKeeper::Respondent do
45
45
  <label>Sake</label><input type="radio" name="food" value="1">
46
46
  <label>Umeboshi</label><input type="radio" name="food" value="2">
47
47
  <h2>Where did you know about this page?</h2>
48
- <label>web site</label><input type="radio" name="media" value="0" checked>
49
- <label>magazine</label><input type="radio" name="media" value="1">
50
- <label>TV show</label><input type="radio" name="media" value="2">
48
+ <label>web site</label><input type="checkbox" name="media" value="0" checked>
49
+ <label>magazine</label><input type="checkbox" name="media" value="1">
50
+ <label>TV show</label><input type="checkbox" name="media" value="2">
51
51
  </form>
52
52
  </body>
53
53
  </html>
@@ -63,9 +63,9 @@ describe FormKeeper::Respondent do
63
63
  <label>Sake</label><input type="radio" name="food" value="1" checked="checked" />
64
64
  <label>Umeboshi</label><input type="radio" name="food" value="2" />
65
65
  <h2>Where did you know about this page?</h2>
66
- <label>web site</label><input type="radio" name="media" value="0" />
67
- <label>magazine</label><input type="radio" name="media" value="1" checked="checked" />
68
- <label>TV show</label><input type="radio" name="media" value="2" checked="checked" />
66
+ <label>web site</label><input type="checkbox" name="media" value="0" />
67
+ <label>magazine</label><input type="checkbox" name="media" value="1" checked="checked" />
68
+ <label>TV show</label><input type="checkbox" name="media" value="2" checked="checked" />
69
69
  </form>
70
70
  </body>
71
71
  </html>
@@ -8,7 +8,7 @@ describe FormKeeper::Validator do
8
8
  rule.filters :strip
9
9
  rule.field :username, :present => true, :length => 8..16
10
10
  rule.field :password, :present => true, :length => 8..16
11
- rule.field :nickname, :characters => 8..16, :filters => :upcase
11
+ rule.field :nickname, :bytesize => 8..16, :filters => :upcase
12
12
 
13
13
  params = {}
14
14
  params['username'] = ' hogehogefoo'
@@ -32,7 +32,7 @@ describe FormKeeper::Validator do
32
32
  rule.filters :strip
33
33
  rule.field :username, :present => true, :length => 8..16
34
34
  rule.field :password, :present => true, :length => 8..16
35
- rule.field :nickname, :characters => 8..16, :filters => :upcase
35
+ rule.field :nickname, :bytesize => 8..16, :filters => :upcase
36
36
 
37
37
  params = {}
38
38
  params['username'] = ' hogehogefoo'
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.4
4
+ version: 0.0.5
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: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helper library for stuff around HTML forms
15
15
  email:
@@ -28,6 +28,21 @@ files:
28
28
  - lib/formkeeper.rb
29
29
  - lib/formkeeper/version.rb
30
30
  - spec/asset/messages.yaml
31
+ - spec/constraint_alnum_space_spec.rb
32
+ - spec/constraint_alnum_spec.rb
33
+ - spec/constraint_alpha_space_spec.rb
34
+ - spec/constraint_alpha_spec.rb
35
+ - spec/constraint_ascii_space_spec.rb
36
+ - spec/constraint_ascii_spec.rb
37
+ - spec/constraint_bytesize_spec.rb
38
+ - spec/constraint_int_spec.rb
39
+ - spec/constraint_length_spec.rb
40
+ - spec/constraint_regexp_spec.rb
41
+ - spec/constraint_uint_spec.rb
42
+ - spec/constraint_uri_spec.rb
43
+ - spec/filter_downcase_spec.rb
44
+ - spec/filter_strip_spec.rb
45
+ - spec/filter_upcase_spec.rb
31
46
  - spec/messages_spec.rb
32
47
  - spec/record_spec.rb
33
48
  - spec/report_spec.rb
@@ -49,7 +64,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
64
  version: '0'
50
65
  segments:
51
66
  - 0
52
- hash: 2548277773188687121
67
+ hash: -2485237141662980897
53
68
  required_rubygems_version: !ruby/object:Gem::Requirement
54
69
  none: false
55
70
  requirements:
@@ -58,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
73
  version: '0'
59
74
  segments:
60
75
  - 0
61
- hash: 2548277773188687121
76
+ hash: -2485237141662980897
62
77
  requirements: []
63
78
  rubyforge_project:
64
79
  rubygems_version: 1.8.24
@@ -67,6 +82,21 @@ specification_version: 3
67
82
  summary: This modules provides you an easy way for form-validation and fill-in-form
68
83
  test_files:
69
84
  - spec/asset/messages.yaml
85
+ - spec/constraint_alnum_space_spec.rb
86
+ - spec/constraint_alnum_spec.rb
87
+ - spec/constraint_alpha_space_spec.rb
88
+ - spec/constraint_alpha_spec.rb
89
+ - spec/constraint_ascii_space_spec.rb
90
+ - spec/constraint_ascii_spec.rb
91
+ - spec/constraint_bytesize_spec.rb
92
+ - spec/constraint_int_spec.rb
93
+ - spec/constraint_length_spec.rb
94
+ - spec/constraint_regexp_spec.rb
95
+ - spec/constraint_uint_spec.rb
96
+ - spec/constraint_uri_spec.rb
97
+ - spec/filter_downcase_spec.rb
98
+ - spec/filter_strip_spec.rb
99
+ - spec/filter_upcase_spec.rb
70
100
  - spec/messages_spec.rb
71
101
  - spec/record_spec.rb
72
102
  - spec/report_spec.rb