formkeeper 0.0.4

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.
@@ -0,0 +1,273 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormKeeper::Validator do
4
+
5
+ it "validates valid params according to rule" do
6
+
7
+ rule = FormKeeper::Rule.new
8
+ rule.filters :strip
9
+ rule.field :username, :present => true, :length => 8..16
10
+ rule.field :password, :present => true, :length => 8..16
11
+ rule.field :nickname, :characters => 8..16, :filters => :upcase
12
+
13
+ params = {}
14
+ params['username'] = ' hogehogefoo'
15
+ params['password'] = 'hogehogebar '
16
+ params['nickname'] = 'hogehoge buz'
17
+
18
+ validator = FormKeeper::Validator.new
19
+ report = validator.validate(params, rule)
20
+
21
+ report.failed?.should_not be_true
22
+
23
+ report[:username].should == 'hogehogefoo'
24
+ report[:password].should == 'hogehogebar'
25
+ report[:nickname].should == 'HOGEHOGE BUZ'
26
+
27
+ end
28
+
29
+ it "validates unpresent params according to rule" do
30
+
31
+ rule = FormKeeper::Rule.new
32
+ rule.filters :strip
33
+ rule.field :username, :present => true, :length => 8..16
34
+ rule.field :password, :present => true, :length => 8..16
35
+ rule.field :nickname, :characters => 8..16, :filters => :upcase
36
+
37
+ params = {}
38
+ params['username'] = ' hogehogefoo'
39
+ params['nickname'] = 'hogehoge buz'
40
+
41
+ validator = FormKeeper::Validator.new
42
+ report = validator.validate(params, rule)
43
+
44
+ #valid_params.keys.size.should == 2
45
+ report[:username].should == 'hogehogefoo'
46
+ report[:nickname].should == 'HOGEHOGE BUZ'
47
+
48
+ report.failed?.should be_true
49
+ report.failed_on?(:password).should be_true
50
+
51
+ end
52
+
53
+ it "validates checkbox params" do
54
+
55
+ rule = FormKeeper::Rule.new
56
+ rule.filters :strip
57
+ rule.field :username, :present => true, :length => 8..16
58
+ rule.field :password, :present => true, :length => 8..16
59
+ rule.checkbox :colors, :count => 1..3
60
+
61
+ params = {}
62
+ params['username'] = ' hogehogefoo'
63
+ params['password'] = 'hogehogebar '
64
+ params['colors'] = ['white', 'black', 'blue']
65
+
66
+ validator = FormKeeper::Validator.new
67
+ report = validator.validate(params, rule)
68
+
69
+ report.failed?.should_not be_true
70
+ #valid_params.keys.size.should == 3
71
+ report[:username].should == 'hogehogefoo'
72
+ report[:password].should == 'hogehogebar'
73
+ report[:colors].should == ['white', 'black', 'blue']
74
+
75
+ end
76
+
77
+ it "validates invalid checkbox params" do
78
+
79
+ rule = FormKeeper::Rule.new
80
+ rule.filters :strip
81
+ rule.field :username, :present => true, :length => 8..16
82
+ rule.field :password, :present => true, :length => 8..16
83
+ rule.checkbox :colors, :count => 1..2
84
+
85
+ params = {}
86
+ params['username'] = ' hogehogefoo'
87
+ params['password'] = 'hogehogebar '
88
+ params['colors'] = ['white', 'black', 'blue']
89
+
90
+ validator = FormKeeper::Validator.new
91
+ report = validator.validate(params, rule)
92
+
93
+ #valid_params.keys.size.should == 2
94
+ report[:username].should == 'hogehogefoo'
95
+ report[:password].should == 'hogehogebar'
96
+
97
+ report.failed?.should be_true
98
+ end
99
+
100
+ it "validates empty checkbox params" do
101
+
102
+ rule = FormKeeper::Rule.new
103
+ rule.filters :strip
104
+ rule.field :username, :present => true, :length => 8..16
105
+ rule.field :password, :present => true, :length => 8..16
106
+ rule.checkbox :colors, :count => 1..2
107
+
108
+ params = {}
109
+ params['username'] = ' hogehogefoo'
110
+ params['password'] = 'hogehogebar '
111
+ params['colors'] = []
112
+
113
+ validator = FormKeeper::Validator.new
114
+ report = validator.validate(params, rule)
115
+
116
+ #valid_params.keys.size.should == 2
117
+ report[:username].should == 'hogehogefoo'
118
+ report[:password].should == 'hogehogebar'
119
+
120
+ report.failed?.should be_true
121
+
122
+ end
123
+
124
+ it "validates filtered-empty checkbox params" do
125
+
126
+ rule = FormKeeper::Rule.new
127
+ rule.filters :strip
128
+ rule.field :username, :present => true, :length => 8..16
129
+ rule.field :password, :present => true, :length => 8..16
130
+ rule.checkbox :colors, :count => 1..2
131
+
132
+ params = {}
133
+ params['username'] = ' hogehogefoo'
134
+ params['password'] = 'hogehogebar '
135
+ params['colors'] = [' ']
136
+
137
+ validator = FormKeeper::Validator.new
138
+ report = validator.validate(params, rule)
139
+
140
+ #valid_params.keys.size.should == 2
141
+ report[:username].should == 'hogehogefoo'
142
+ report[:password].should == 'hogehogebar'
143
+
144
+ report.failed?.should be_true
145
+
146
+ end
147
+
148
+ it "validates checkbox params with constraint" do
149
+
150
+ rule = FormKeeper::Rule.new
151
+ rule.filters :strip
152
+ rule.field :username, :present => true, :length => 8..16
153
+ rule.field :password, :present => true, :length => 8..16
154
+ rule.checkbox :colors, :count => 1..2, :length => 4..5
155
+
156
+ params = {}
157
+ params['username'] = ' hogehogefoo'
158
+ params['password'] = 'hogehogebar '
159
+ params['colors'] = [' white', 'black']
160
+
161
+ validator = FormKeeper::Validator.new
162
+ report = validator.validate(params, rule)
163
+
164
+ #valid_params.keys.size.should == 3
165
+ report[:username].should == 'hogehogefoo'
166
+ report[:password].should == 'hogehogebar'
167
+ report[:colors].should == ['white', 'black']
168
+
169
+ report.failed?.should_not be_true
170
+
171
+ end
172
+
173
+ it "validates invalid checkbox params with constraint" do
174
+
175
+ rule = FormKeeper::Rule.new
176
+ rule.filters :strip
177
+ rule.field :username, :present => true, :length => 8..16
178
+ rule.field :password, :present => true, :length => 8..16
179
+ rule.checkbox :colors, :count => 1..2, :length => 4..5
180
+
181
+ params = {}
182
+ params['username'] = ' hogehogefoo'
183
+ params['password'] = 'hogehogebar '
184
+ params['colors'] = [' white', 'black', 'red']
185
+
186
+ validator = FormKeeper::Validator.new
187
+ report = validator.validate(params, rule)
188
+
189
+ #valid_params.keys.size.should == 2
190
+ report[:username].should == 'hogehogefoo'
191
+ report[:password].should == 'hogehogebar'
192
+
193
+ report.failed?.should be_true
194
+ report.failed_on?(:colors)
195
+ end
196
+
197
+ it "validates combination params" do
198
+
199
+ rule = FormKeeper::Rule.new
200
+ rule.filters :strip
201
+ rule.field :username, :present => true, :length => 8..16
202
+ rule.field :password, :present => true, :length => 8..16
203
+ rule.combination :same_email_address, :fields => [:email1, :email2], :same => true
204
+
205
+ params = {}
206
+ params['username'] = ' hogehogefoo'
207
+ params['password'] = 'hogehogebar '
208
+ params['email1'] = 'hoge@example.org'
209
+ params['email2'] = 'hoge@example.org'
210
+
211
+ validator = FormKeeper::Validator.new
212
+ report = validator.validate(params, rule)
213
+
214
+ #valid_params.keys.size.should == 2
215
+ report[:username].should == 'hogehogefoo'
216
+ report[:password].should == 'hogehogebar'
217
+
218
+ report.failed?.should_not be_true
219
+
220
+ end
221
+
222
+ it "validates combination params by synonym" do
223
+
224
+ rule = FormKeeper::Rule.new
225
+ rule.filters :strip
226
+ rule.field :username, :present => true, :length => 8..16
227
+ rule.field :password, :present => true, :length => 8..16
228
+ rule.same :same_email_address, [:email1, :email2], :filters => :upcase
229
+
230
+ params = {}
231
+ params['username'] = ' hogehogefoo'
232
+ params['password'] = 'hogehogebar '
233
+ params['email1'] = 'hoge@example.org'
234
+ params['email2'] = 'hoge@example.org'
235
+
236
+ validator = FormKeeper::Validator.new
237
+ report = validator.validate(params, rule)
238
+
239
+ #valid_params.keys.size.should == 2
240
+ report[:username].should == 'hogehogefoo'
241
+ report[:password].should == 'hogehogebar'
242
+
243
+ report.failed?.should_not be_true
244
+
245
+ end
246
+
247
+ it "validates invalid combination params" do
248
+
249
+ rule = FormKeeper::Rule.new
250
+ rule.filters :strip
251
+ rule.field :username, :present => true, :length => 8..16
252
+ rule.field :password, :present => true, :length => 8..16
253
+ rule.same :same_email_address, [:email1, :email2], :filters => :upcase
254
+
255
+ params = {}
256
+ params['username'] = ' hogehogefoo'
257
+ params['password'] = 'hogehogebar '
258
+ params['email1'] = 'hoge@example.org'
259
+ params['email2'] = 'hoge2@example.org'
260
+
261
+ validator = FormKeeper::Validator.new
262
+ report = validator.validate(params, rule)
263
+
264
+ #valid_params.keys.size.should == 2
265
+ report[:username].should == 'hogehogefoo'
266
+ report[:password].should == 'hogehogebar'
267
+
268
+ report.failed?.should be_true
269
+ report.failed_on?(:same_email_address).should be_true
270
+
271
+ end
272
+ end
273
+
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formkeeper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - lyokato
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Helper library for stuff around HTML forms
15
+ email:
16
+ - lyo.kato@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - formkeeper.gemspec
28
+ - lib/formkeeper.rb
29
+ - lib/formkeeper/version.rb
30
+ - spec/asset/messages.yaml
31
+ - spec/messages_spec.rb
32
+ - spec/record_spec.rb
33
+ - spec/report_spec.rb
34
+ - spec/respondent_spec.rb
35
+ - spec/rule_spec.rb
36
+ - spec/spec_helper.rb
37
+ - spec/validator_spec.rb
38
+ homepage: ''
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ segments:
51
+ - 0
52
+ hash: 2548277773188687121
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: 2548277773188687121
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.24
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: This modules provides you an easy way for form-validation and fill-in-form
68
+ test_files:
69
+ - spec/asset/messages.yaml
70
+ - spec/messages_spec.rb
71
+ - spec/record_spec.rb
72
+ - spec/report_spec.rb
73
+ - spec/respondent_spec.rb
74
+ - spec/rule_spec.rb
75
+ - spec/spec_helper.rb
76
+ - spec/validator_spec.rb