aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorChris Constantine <cconstan@gmail.com>2013-04-18 12:24:14 -0700
committerChris Constantine <cconstan@gmail.com>2013-04-18 12:24:49 -0700
commit0e34a7efa6992e6771d34dc8163b79dd7df52667 (patch)
treeea69d7e6e88ebdd20e45a64c3087a9139a12c7fe /activerecord
parente62f4404cf35e1606def6853b4450068f0ebc2cb (diff)
downloadrails-0e34a7efa6992e6771d34dc8163b79dd7df52667.tar.gz
rails-0e34a7efa6992e6771d34dc8163b79dd7df52667.tar.bz2
rails-0e34a7efa6992e6771d34dc8163b79dd7df52667.zip
Fix loading of fixtures when the column type is a postgres array of strings.
- 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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb2
-rw-r--r--activerecord/test/cases/adapters/postgresql/array_test.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
index 6329733abc..40a3b82839 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -32,7 +32,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb
index 8774bf626f..61a3a2ba0f 100644
--- a/activerecord/test/cases/adapters/postgresql/array_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/array_test.rb
@@ -81,6 +81,12 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
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