Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow negative decimals on validates_numericality_of.

  • Loading branch information...
commit 40bbd59605ba0ee832b0704aac54be784f00093c 1 parent 8d7c3ce
Harold Giménez authored
2  lib/validatable/validations/validates_numericality_of.rb
View
@@ -8,7 +8,7 @@ def valid?(instance)
return true if allow_blank && value.blank?
value = value.to_s
- regex = self.only_integer ? /\A[+-]?\d+\Z/ : /^\d*\.{0,1}\d+$/
+ regex = self.only_integer ? /\A[+-]?\d+\Z/ : /\A[+-]?\d*\.{0,1}\d+$/
not (value =~ regex).nil?
end
8 test/unit/test_validates_numericality_of.rb
View
@@ -44,6 +44,12 @@
validation.valid?(instance)
end
+ expect true do
+ validation = Validatable::ValidatesNumericalityOf.new stub_everything, :some_negative_decimal
+ instance = stub(:some_negative_decimal => -1.23)
+ validation.valid?(instance)
+ end
+
expect false do
validation = Validatable::ValidatesNumericalityOf.new stub_everything, :some_decimal, :only_integer => true
instance = stub(:some_decimal => 1.23)
@@ -73,4 +79,4 @@
Validatable::ValidatesNumericalityOf.new(stub_everything, :test).must_understand(options.to_blank_options_hash)
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.