Created
January 25, 2009 21:54
-
-
Save lifo/52555 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | |
index 97c6cd4..b99c2c6 100644 | |
--- a/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | |
+++ b/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | |
@@ -147,6 +147,25 @@ module ActiveRecord | |
execute "INSERT INTO #{quote_table_name(table_name)} (#{fixture.key_list}) VALUES (#{fixture.value_list})", 'Fixture Insert' | |
end | |
+ def insert_many_fixtures(fixtures, table_name) | |
+ columns = self.columns(table_name, "#{table_name} Columns") | |
+ column_list = columns.map{|c| self.quote_column_name(c.name)}.join(", ") | |
+ | |
+ value_list = fixtures.map do |f| | |
+ values = columns.map do |c| | |
+ if f.has_key?(c.name) | |
+ self.quote(f[c.name], c).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r") | |
+ else | |
+ 'DEFAULT' | |
+ end | |
+ end | |
+ | |
+ "(#{values.join(", ")})" | |
+ end.join(", ") | |
+ | |
+ execute "INSERT INTO #{quote_table_name(table_name)} (#{column_list}) VALUES #{value_list}", 'Mulitple Fixtures Insert' | |
+ end | |
+ | |
def empty_insert_statement(table_name) | |
"INSERT INTO #{quote_table_name(table_name)} VALUES(DEFAULT)" | |
end | |
diff --git a/vendor/rails/activerecord/lib/active_record/fixtures.rb b/vendor/rails/activerecord/lib/active_record/fixtures.rb | |
index 114141a..74dbb4b 100644 | |
--- a/vendor/rails/activerecord/lib/active_record/fixtures.rb | |
+++ b/vendor/rails/activerecord/lib/active_record/fixtures.rb | |
@@ -574,6 +574,8 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) | |
h[habtm] = HabtmFixtures.new(@connection, habtm.options[:join_table], nil, nil) | |
end | |
+ mass_fixtures = [] | |
+ | |
each do |label, fixture| | |
row = fixture.to_hash | |
@@ -637,9 +639,11 @@ class Fixtures < (RUBY_VERSION < '1.9' ? YAML::Omap : Hash) | |
end | |
end | |
- @connection.insert_fixture(fixture, @table_name) | |
+ mass_fixtures << fixture | |
end | |
+ @connection.insert_many_fixtures(mass_fixtures, @table_name) if mass_fixtures.any? | |
+ | |
# insert any HABTM join tables we discovered | |
habtm_fixtures.values.each do |fixture| | |
fixture.delete_existing_fixtures | |
@@ -811,6 +815,10 @@ class Fixture #:nodoc: | |
raise FixtureClassNotFound, "No class attached to find." | |
end | |
end | |
+ | |
+ def has_key?(key) | |
+ @fixture.has_key?(key) | |
+ end | |
end | |
module Test #:nodoc: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment