Module: FixtureBot::FixtureCreator
- Extended by:
- FactoryBot::Syntax::Methods, Helpers
- Defined in:
- lib/fixture_bot/fixture_creator.rb
Class Attribute Summary collapse
-
.fixtures ⇒ Object
Returns the value of attribute fixtures.
-
.fixtures_with_id ⇒ Object
Returns the value of attribute fixtures_with_id.
-
.record_ids ⇒ Object
Returns the value of attribute record_ids.
-
.tables ⇒ Object
Returns the value of attribute tables.
Class Method Summary collapse
Methods included from Helpers
Class Attribute Details
.fixtures ⇒ Object
Returns the value of attribute fixtures.
9 10 11 |
# File 'lib/fixture_bot/fixture_creator.rb', line 9 def fixtures @fixtures end |
.fixtures_with_id ⇒ Object
Returns the value of attribute fixtures_with_id.
9 10 11 |
# File 'lib/fixture_bot/fixture_creator.rb', line 9 def fixtures_with_id @fixtures_with_id end |
.record_ids ⇒ Object
Returns the value of attribute record_ids.
9 10 11 |
# File 'lib/fixture_bot/fixture_creator.rb', line 9 def record_ids @record_ids end |
.tables ⇒ Object
Returns the value of attribute tables.
9 10 11 |
# File 'lib/fixture_bot/fixture_creator.rb', line 9 def tables @tables end |
Class Method Details
.load_to_db ⇒ Object
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 |
# File 'lib/fixture_bot/fixture_creator.rb', line 17 def load_to_db tmp_fixtures = [] tmp_fixtures_with_id = [] tables.each do |table, blocks| table_preload = TableLoader.new(table) blocks.each do |block| table_preload.instance_eval(&block) end tmp_fixtures.concat(table_preload.fixtures) tmp_fixtures_with_id.concat(table_preload.fixtures_with_id) end self.fixtures = tmp_fixtures.to_h self.fixtures_with_id = tmp_fixtures_with_id.to_h ::ActiveRecord::Base.connection.transaction requires_new: true do fixtures_with_id.each do |key, block| table, fixture_name = key.split("/") fixture_with_id(table.to_sym, fixture_name.to_sym, &block) end fixtures.each do |key, block| table, fixture_name = key.split("/") fixture(table.to_sym, fixture_name.to_sym, &block) end end end |