Skip to content

Commit

Permalink
Fix loading of fixtures when the column type is a postgres array of s…
Browse files Browse the repository at this point in the history
…trings.

 - A string in an array of strings that has a quote char (') needs to have that quote char escaped if the array is getting wrapped in quote chars.
  • Loading branch information
cconstantine committed Apr 18, 2013
1 parent e62f440 commit 0e34a7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def quote(value, column = nil) #:nodoc:
when 'point' then super(PostgreSQLColumn.point_to_string(value))
else
if column.array
"'#{PostgreSQLColumn.array_to_string(value, column, self)}'"
"'#{PostgreSQLColumn.array_to_string(value, column, self).gsub(/'/, "''")}'"
else
super
end
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/adapters/postgresql/array_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def test_contains_nils
assert_cycle(['1',nil,nil])
end

def test_insert_fixture
tag_values = ["val1", "val2", "val3_with_'_multiple_quote_'_chars"]
@connection.insert_fixture({"tags" => tag_values}, "pg_arrays" )
assert_equal(PgArray.last.tags, tag_values)
end

private
def assert_cycle array
# test creation
Expand Down

0 comments on commit 0e34a7e

Please sign in to comment.