formkeeper 0.0.14 → 0.0.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49bade6105761c7043e33898ec6df3c1384b757b
4
- data.tar.gz: c99e1c0952c1f1fc05afc68bee877c9c9280578a
3
+ metadata.gz: cb42cf5ca99b381d43bed10a94d7a29fbf441eb1
4
+ data.tar.gz: 23dba3a2f1c63dbd52624a03e408aa19f0cdac17
5
5
  SHA512:
6
- metadata.gz: 7818cfee006207687639c43c5b018e6d36507d18a76b7fc63c1031c1508bb8082d2716ac7a5382e871c1ae5ef2b08787b805af15143ec61810e42fce77d4f66a
7
- data.tar.gz: 97650f0a419d89073b866ab94890bbda3f05787cf15d64a44f6f55140946e1b227f9a13196689c89e8d425deadabc72283adcd5b003f982d57480b64e7892f38
6
+ metadata.gz: f4d0cc10eab3303e3d6281d9ecf5126644d9f57784d678de8ce531a40e585697edf60e8ee2c3da4071385c51655a3e8967abb8317b761ccdb04e8376005a9377
7
+ data.tar.gz: de70c2cda94b7a036fba3206cb2735efcfb57500650647b22c79e0301d9d0c1b96fba01f626fea2b55495c71c06148703fb981fc1185aab746fa433f28d5e93c
data/lib/formkeeper.rb CHANGED
@@ -323,6 +323,13 @@ module FormKeeper
323
323
  end
324
324
  end
325
325
 
326
+ class Different < Base
327
+ def validate(values, arg)
328
+ return false unless values.size == 2
329
+ values[0] != values[1]
330
+ end
331
+ end
332
+
326
333
  class Any < Base
327
334
  def validate(values, arg)
328
335
  values.any? { |v| not (v.nil? or v.empty?) }
@@ -726,6 +733,7 @@ module FormKeeper
726
733
  register_combination_constraint :date, CombinationConstraint::Date.new
727
734
  register_combination_constraint :time, CombinationConstraint::Time.new
728
735
  register_combination_constraint :same, CombinationConstraint::Same.new
736
+ register_combination_constraint :diff, CombinationConstraint::Different.new
729
737
  register_combination_constraint :any, CombinationConstraint::Any.new
730
738
 
731
739
  def initialize
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -250,7 +250,7 @@ describe FormKeeper::Validator do
250
250
  report.failed_on?(:colors)
251
251
  end
252
252
 
253
- it "validates combination params" do
253
+ it "validates combination same params" do
254
254
 
255
255
  rule = FormKeeper::Rule.new
256
256
  rule.filters :strip
@@ -275,7 +275,7 @@ describe FormKeeper::Validator do
275
275
 
276
276
  end
277
277
 
278
- it "validates combination params by synonym" do
278
+ it "validates combination same params by synonym" do
279
279
 
280
280
  rule = FormKeeper::Rule.new
281
281
  rule.filters :strip
@@ -300,7 +300,7 @@ describe FormKeeper::Validator do
300
300
 
301
301
  end
302
302
 
303
- it "validates invalid combination params" do
303
+ it "validates invalid combination same params" do
304
304
 
305
305
  rule = FormKeeper::Rule.new
306
306
  rule.filters :strip
@@ -325,5 +325,74 @@ describe FormKeeper::Validator do
325
325
  report.failed_on?(:same_email_address).should eql(true)
326
326
 
327
327
  end
328
- end
329
328
 
329
+ it "validates combination diff params" do
330
+
331
+ rule = FormKeeper::Rule.new
332
+ rule.filters :strip
333
+ rule.field :old_password, :present => true, :length => 8..16
334
+ rule.field :new_password, :present => true, :length => 8..16
335
+ rule.combination :different_password, :fields => [:old_password, :new_password], :diff => true
336
+
337
+ params = {}
338
+ params['old_password'] = 'hogehogebar_old '
339
+ params['new_password'] = 'hogehogebar_new '
340
+
341
+ validator = FormKeeper::Validator.new
342
+ report = validator.validate(params, rule)
343
+
344
+ #valid_params.keys.size.should == 2
345
+ report[:old_password].should == 'hogehogebar_old'
346
+ report[:new_password].should == 'hogehogebar_new'
347
+
348
+ report.failed?.should_not eql(true)
349
+
350
+ end
351
+
352
+ it "validates combination diff params by synonym" do
353
+
354
+ rule = FormKeeper::Rule.new
355
+ rule.filters :strip
356
+ rule.field :old_password, :present => true, :length => 8..16
357
+ rule.field :new_password, :present => true, :length => 8..16
358
+ rule.diff :different_password, [:old_password, :new_password], :filters => :upcase
359
+
360
+ params = {}
361
+ params['old_password'] = 'hogehogebar_old '
362
+ params['new_password'] = 'hogehogebar_new '
363
+
364
+ validator = FormKeeper::Validator.new
365
+ report = validator.validate(params, rule)
366
+
367
+ #valid_params.keys.size.should == 2
368
+ report[:old_password].should == 'hogehogebar_old'
369
+ report[:new_password].should == 'hogehogebar_new'
370
+
371
+ report.failed?.should_not eql(true)
372
+
373
+ end
374
+
375
+ it "validates invalid combination diff params" do
376
+
377
+ rule = FormKeeper::Rule.new
378
+ rule.filters :strip
379
+ rule.field :old_password, :present => true, :length => 8..16
380
+ rule.field :new_password, :present => true, :length => 8..16
381
+ rule.diff :different_password, [:old_password, :new_password], :filters => :upcase
382
+
383
+ params = {}
384
+ params['old_password'] = 'hogehogebar_old '
385
+ params['new_password'] = 'hogehogebar_old '
386
+
387
+ validator = FormKeeper::Validator.new
388
+ report = validator.validate(params, rule)
389
+
390
+ #valid_params.keys.size.should == 2
391
+ report[:old_password].should == 'hogehogebar_old'
392
+ report[:new_password].should == 'hogehogebar_old'
393
+
394
+ report.failed?.should eql(true)
395
+ report.failed_on?(:different_password).should eql(true)
396
+
397
+ end
398
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - lyokato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-30 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hpricot