提交 7098c908 编写于 作者: M Mariano Valles

Change class evaluation for Rationals in cast_value

上级 a4802e21
......@@ -14,14 +14,16 @@ def type_cast_for_schema(value)
private
def cast_value(value)
if value.class == Rational
BigDecimal.new(value, precision.to_i)
elsif value.respond_to?(:to_d)
case value
when Numeric, String, Rational
BigDecimal(value, precision.to_i)
when proc { value.respond_to?(:to_d) }
value.to_d
else
value.to_s.to_d
cast_value(value.to_s)
end
end
end
end
end
......@@ -103,7 +103,7 @@ def test_type_cast_decimal
end
def test_type_cast_rational_to_decimal_with_precision
type = Type::Decimal.new(:precision => 2)
type = Type::Decimal.new(precision: 2)
assert_equal BigDecimal("0.33"), type.type_cast_from_user(Rational(1, 3))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册