未验证 提交 5b1c3e5a 编写于 作者: M Matthew Draper 提交者: Rafael Mendonça França

Merge pull request #29249 from bradleypriest/numericality-precision-regression

Fix regression in Numericality validator
上级 0e1928a9
* Fix regression in numericality validator when comparing Decimal and Float input
values with more scale than the schema.
*Bradley Priest*
## Rails 5.1.1 (May 12, 2017) ##
* No changes.
......
......@@ -36,7 +36,9 @@ def validate_each(record, attr_name, value)
return
end
unless raw_value.is_a?(Numeric)
if raw_value.is_a?(Numeric)
value = raw_value
else
value = parse_raw_value_as_a_number(raw_value)
end
......
......@@ -167,6 +167,20 @@ def test_numericality_validation_with_mutation
assert topic.valid?
end
def test_numericality_validation_checks_against_raw_value
klass = Class.new(Topic) do
def self.model_name
ActiveModel::Name.new(self, nil, "Topic")
end
attribute :wibble, :decimal, scale: 2, precision: 9
validates_numericality_of :wibble, greater_than_or_equal_to: BigDecimal.new("97.18")
end
assert_not klass.new(wibble: "97.179").valid?
assert_not klass.new(wibble: 97.179).valid?
assert_not klass.new(wibble: BigDecimal.new("97.179")).valid?
end
def test_acceptance_validator_doesnt_require_db_connection
klass = Class.new(ActiveRecord::Base) do
self.table_name = "posts"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册