Permalink
Browse files

Fix loading of string arrays in postgres

  • Loading branch information...
cconstantine committed Apr 7, 2013
1 parent 436d918 commit f6c4cded2f066db42ef83b30f6c353e2958f81fb
@@ -44,6 +44,21 @@ def pp(result)
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)
@@ -81,6 +81,12 @@ def test_contains_nils
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

0 comments on commit f6c4cde

Please sign in to comment.