diff options
Diffstat (limited to 'activerecord/lib/active_record/fixtures.rb')
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 36e134ea17..60ece6bd13 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -362,6 +362,7 @@ module ActiveRecord # geeksomnia: # name: Geeksomnia's Account # subdomain: $LABEL + # email: $LABEL@email.com # # Also, sometimes (like when porting older join table fixtures) you'll need # to be able to get a hold of the identifier for a given label. ERB @@ -463,7 +464,7 @@ module ActiveRecord @class_names.delete_if { |k,klass| unless klass.is_a? Class klass = klass.safe_constantize - ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name will be removed in Rails 4.2, consider using the class itself instead.") + ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name to `set_fixture_class` will be removed in Rails 4.2. Use the class itself instead.") end !insert_class(@class_names, k, klass) } @@ -522,8 +523,16 @@ module ActiveRecord connection.transaction(:requires_new => true) do fixture_sets.each do |fs| conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection - fs.fixture_sql(conn).each do |stmt| - conn.execute stmt + table_rows = fs.table_rows + + table_rows.keys.each do |table| + conn.delete "DELETE FROM #{conn.quote_table_name(table)}", 'Fixture Delete' + end + + table_rows.each do |fixture_set_name, rows| + rows.each do |row| + conn.insert_fixture(row, fixture_set_name) + end end end @@ -542,7 +551,7 @@ module ActiveRecord end # Returns a consistent, platform-independent identifier for +label+. - # Integer identifiers are values less than 2^32. UUIDs are RFC 4122 version 5 SHA-1 hashes. + # Integer identifiers are values less than 2^30. UUIDs are RFC 4122 version 5 SHA-1 hashes. def self.identify(label, column_type = :integer) if column_type == :uuid SecureRandom.uuid_v5(SecureRandom::UUID_OID_NAMESPACE, label.to_s) @@ -565,7 +574,7 @@ module ActiveRecord @model_class = nil if class_name.is_a?(String) - ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name will be removed in Rails 4.2, consider using the class itself instead.") + ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name to `FixtureSet.new` will be removed in Rails 4.2. Use the class itself instead.") end if class_name.is_a?(Class) # TODO: Should be an AR::Base type class, or any? @@ -599,16 +608,6 @@ module ActiveRecord fixtures.size end - def fixture_sql(conn) - table_rows = self.table_rows - - table_rows.keys.map { |table| - "DELETE FROM #{conn.quote_table_name(table)}" - }.concat table_rows.flat_map { |fixture_set_name, rows| - rows.map { |row| conn.fixture_sql(row, fixture_set_name) } - } - end - # Returns a hash of rows to be inserted. The key is the table, the value is # a list of rows to insert to that table. def table_rows @@ -634,7 +633,7 @@ module ActiveRecord # interpolate the fixture label row.each do |key, value| - row[key] = label if "$LABEL" == value + row[key] = value.gsub("$LABEL", label) if value.is_a?(String) end # generate a primary key if necessary |