提交 efc436df 编写于 作者: S Sean Griffin

Remove unneccessary special case for money in quoting

上级 03c9c0e2
......@@ -41,13 +41,6 @@ def quote(value, column = nil) #:nodoc:
else
super
end
when Numeric
if sql_type == 'money' || [:string, :text].include?(column.type)
# Not truly string input, so doesn't require (or allow) escape string syntax.
"'#{value}'"
else
super
end
when String
case sql_type
when 'xml' then "xml '#{quote_string(value)}'"
......
......@@ -16,10 +16,10 @@ def changed_in_place?(raw_old_value, new_value)
end
def type_cast_for_database(value)
if value.is_a?(::String)
::String.new(value)
else
super
case value
when ::Numeric then value.to_s
when ::String then ::String.new(value)
else super
end
end
......
......@@ -70,4 +70,28 @@ def test_create_and_update_money
money.reload
assert_equal new_value, money.wealth
end
def test_update_all_with_money_string
money = PostgresqlMoney.create!
PostgresqlMoney.update_all(wealth: "987.65")
money.reload
assert_equal 987.65, money.wealth
end
def test_update_all_with_money_big_decimal
money = PostgresqlMoney.create!
PostgresqlMoney.update_all(wealth: '123.45'.to_d)
money.reload
assert_equal 123.45, money.wealth
end
def test_update_all_with_money_numeric
money = PostgresqlMoney.create!
PostgresqlMoney.update_all(wealth: 123.45)
money.reload
assert_equal 123.45, money.wealth
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册