Class: ActiveRecord::FixtureSet
- Inherits:
-
Object
- Object
- ActiveRecord::FixtureSet
- Extended by:
- Turntable::Util
- Defined in:
- lib/active_record/turntable/active_record_ext/fixtures.rb
Class Method Summary collapse
Methods included from Turntable::Util
ar51?, ar51_or_later?, ar52_or_later?, ar_version, ar_version_earlier_than?, ar_version_equals_or_later?, ar_version_satisfy?, earlier_than_ar51?
Class Method Details
.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/active_record/turntable/active_record_ext/fixtures.rb', line 13 def self.create_fixtures(fixtures_directory, fixture_set_names, class_names = {}, config = ActiveRecord::Base) fixture_set_names = Array(fixture_set_names).map(&:to_s) class_names = ClassCache.new class_names, config # FIXME: Apparently JK uses this. connection = block_given? ? yield : ActiveRecord::Base.connection files_to_read = fixture_set_names.reject { |fs_name| fixture_is_cached?(connection, fs_name) } unless files_to_read.empty? connection.disable_referential_integrity do fixtures_map = {} fixture_sets = files_to_read.map do |fs_name| klass = class_names[fs_name] conn = klass ? klass.connection : connection fixtures_map[fs_name] = new( # ActiveRecord::FixtureSet.new conn, fs_name, klass, ::File.join(fixtures_directory, fs_name)) end update_all_loaded_fixtures fixtures_map ActiveRecord::Base.force_transaction_all_shards!(requires_new: true) do deleted_tables = Hash.new { |h, k| h[k] = Set.new } fixture_sets.each do |fs| conn = fs.model_class.respond_to?(:connection) ? fs.model_class.connection : connection table_rows = fs.table_rows table_rows.each_key do |table| unless deleted_tables[conn].include? table conn.delete "DELETE FROM #{conn.quote_table_name(table)}", "Fixture Delete" end deleted_tables[conn] << table end table_rows.each do |fixture_set_name, rows| rows.each do |row| conn.insert_fixture(row, fixture_set_name) end end # Cap primary key sequences to max(pk). if connection.respond_to?(:reset_pk_sequence!) connection.reset_pk_sequence!(fs.table_name) end end end cache_fixtures(connection, fixtures_map) end end cached_fixtures(connection, fixture_set_names) end |