diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-18 10:16:58 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-18 10:16:58 -0700 |
commit | 521035af530482d6d9ad2dae568eaeb0ab188e1c (patch) | |
tree | 1bc00d452ff3f0098f7cee4bc3dd94bfa681202a /activerecord | |
parent | 222011dbee842bbc60d3aaaa3145356b90a30fd1 (diff) | |
parent | f6c4cded2f066db42ef83b30f6c353e2958f81fb (diff) | |
download | rails-521035af530482d6d9ad2dae568eaeb0ab188e1c.tar.gz rails-521035af530482d6d9ad2dae568eaeb0ab188e1c.tar.bz2 rails-521035af530482d6d9ad2dae568eaeb0ab188e1c.zip |
Merge pull request #10043 from cconstantine/master
DB with postgres string array column doesn't load fixtures well
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb | 15 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index 9b5170f657..a16e7facce 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -44,6 +44,21 @@ module ActiveRecord end end + + # Inserts the given fixture into the table. + def insert_fixture(fixture, table_name) + columns = schema_cache.columns_hash(table_name) + + key_list = [] + value_list = fixture.map do |name, value| + key_list << quote_column_name(name) + [columns[name], value] + end + + insert_statement = "INSERT INTO #{quote_table_name(table_name)} (#{key_list.join(", ")}) VALUES (#{key_list.count.times.map{|i| "$#{i+1}" }.join(", ")})" + exec_insert(insert_statement, 'Fixture Insert', value_list) + end + # Executes a SELECT query and returns an array of rows. Each row is an # array of field values. def select_rows(sql, name = nil) diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index 8774bf626f..5c629aed3d 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_quote_'_char"] + @connection.insert_fixture({"tags" => ["val1", "val2", "val3_with_quote_'_char"]}, "pg_arrays" ) + assert_equal(PgArray.last.tags, tag_values) + end + private def assert_cycle array # test creation |