diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-07-03 07:40:14 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-07-03 13:12:41 -0600 |
commit | efc436df2092bacc896dbf66ddc332aeafe42e72 (patch) | |
tree | c8942f2c160cdf7c2966da4fd5789b46a56b8e66 /activerecord | |
parent | 03c9c0e2fa83e4ccaefb3b06970b9c3efe170be5 (diff) | |
download | rails-efc436df2092bacc896dbf66ddc332aeafe42e72.tar.gz rails-efc436df2092bacc896dbf66ddc332aeafe42e72.tar.bz2 rails-efc436df2092bacc896dbf66ddc332aeafe42e72.zip |
Remove unneccessary special case for money in quoting
Diffstat (limited to 'activerecord')
3 files changed, 28 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb index 60b0ee526e..10b16fbd7f 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb @@ -41,13 +41,6 @@ module ActiveRecord 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)}'" diff --git a/activerecord/lib/active_record/type/string.rb b/activerecord/lib/active_record/type/string.rb index 14b03dcb2d..8cc533bc41 100644 --- a/activerecord/lib/active_record/type/string.rb +++ b/activerecord/lib/active_record/type/string.rb @@ -16,10 +16,10 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/adapters/postgresql/money_test.rb b/activerecord/test/cases/adapters/postgresql/money_test.rb index cf2a4ab6ea..fa5e3cc281 100644 --- a/activerecord/test/cases/adapters/postgresql/money_test.rb +++ b/activerecord/test/cases/adapters/postgresql/money_test.rb @@ -70,4 +70,28 @@ class PostgresqlMoneyTest < ActiveRecord::TestCase 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 |