Skip to content

Commit

Permalink
Merge pull request #13451 from dmathieu/quoting_non_strings
Browse files Browse the repository at this point in the history
Fix typecasting array of integers
  • Loading branch information
senny committed Dec 22, 2013
1 parent ad9570e commit 44051e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Expand Up @@ -144,7 +144,7 @@ def escape_hstore(value)

def quote_and_escape(value)
case value
when "NULL"
when "NULL", Numeric
value
else
"\"#{value.gsub(/"/,"\\\"")}\""
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/adapters/postgresql/array_test.rb
Expand Up @@ -56,6 +56,12 @@ def test_type_cast_array
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
Expand Down

0 comments on commit 44051e2

Please sign in to comment.