diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-12-22 09:14:06 -0800 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-12-22 09:14:06 -0800 |
commit | c0a6ffb799c2516f8ff76a9b4bf58b2ad1b9235b (patch) | |
tree | 67b591620285f3cffa8fbb9a3e6e598baf45addc | |
parent | 7432d32f527f9a06ed51f576985987a1f87c5c78 (diff) | |
parent | 1f6a9b50ee26d6c4520a416c66ef999d92570698 (diff) | |
download | rails-c0a6ffb799c2516f8ff76a9b4bf58b2ad1b9235b.tar.gz rails-c0a6ffb799c2516f8ff76a9b4bf58b2ad1b9235b.tar.bz2 rails-c0a6ffb799c2516f8ff76a9b4bf58b2ad1b9235b.zip |
Merge pull request #13451 from dmathieu/quoting_non_strings
Fix typecasting array of integers
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/cast.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb index bf34f2bdae..35ce881302 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/cast.rb @@ -144,7 +144,7 @@ module ActiveRecord def quote_and_escape(value) case value - when "NULL" + when "NULL", Numeric value else "\"#{value.gsub(/"/,"\\\"")}\"" diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index 06901a8990..114d5b6cc6 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -66,6 +66,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase assert_equal([nil], @column.type_cast('{NULL}')) end + def test_type_cast_integers + x = PgArray.new(ratings: ['1', '2']) + assert x.save! + assert_equal(['1', '2'], x.ratings) + end + def test_rewrite @connection.execute "insert into pg_arrays (tags) VALUES ('{1,2,3}')" x = PgArray.first |