client_side_validations 3.0.1 → 3.0.2

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.
@@ -22,7 +22,7 @@ module ClientSideValidations::ActiveModel
22
22
  validator_hash = attr[1].inject({}) do |kind_hash, validator|
23
23
  client_side_hash = validator.client_side_hash(self, attr[0])
24
24
  # Yeah yeah, #new_record? is not part of ActiveModel :p
25
- if ((self.respond_to?(:new_record?) && client_side_hash[:on] == (self.new_record? ? :create : :update)) || client_side_hash[:on].nil?)
25
+ if (can_use_for_client_side_validation?(client_side_hash, validator))
26
26
  kind_hash.merge!(validator.kind => client_side_hash.except(:on))
27
27
  else
28
28
  kind_hash.merge!({})
@@ -32,6 +32,12 @@ module ClientSideValidations::ActiveModel
32
32
  attr_hash.merge!(attr[0] => validator_hash)
33
33
  end.delete_if { |key, value| value.blank? }
34
34
  end
35
+
36
+ private
37
+
38
+ def can_use_for_client_side_validation?(client_side_hash, validator)
39
+ ((self.respond_to?(:new_record?) && client_side_hash[:on] == (self.new_record? ? :create : :update)) || client_side_hash[:on].nil?) && !validator.options.key?(:if) && !validator.options.key?(:unless)
40
+ end
35
41
  end
36
42
  end
37
43
 
@@ -1,3 +1,3 @@
1
1
  module ClientSideValidations
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.2"
3
3
  end
@@ -137,5 +137,15 @@ class ActiveModel::ValidationsTest < ClientSideValidations::ActiveModelTestBase
137
137
  expected_hash = {}
138
138
  assert_equal expected_hash, person.client_side_validation_hash
139
139
  end
140
+
141
+ def test_validators_with_if_or_unless_are_ignored
142
+ person = new_person do |p|
143
+ p.validates_presence_of :first_name, :if => Proc.new { |p| true }
144
+ p.validates_presence_of :last_name, :unless => Proc.new { |p| true }
145
+ end
146
+
147
+ expected_hash = {}
148
+ assert_equal expected_hash, person.client_side_validation_hash
149
+ end
140
150
  end
141
151
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: client_side_validations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.0.1
5
+ version: 3.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Cardarella