Module: ActiveRecord::TestFixtures
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
append_features, extended, included
Instance Method Details
#enlist_fixture_connections ⇒ Object
889
890
891
|
# File 'activerecord/lib/active_record/fixtures.rb', line 889
def enlist_fixture_connections
ActiveRecord::Base.connection_handler.connection_pools.values.map(&:connection)
end
|
#run_in_transaction? ⇒ Boolean
828
829
830
831
|
# File 'activerecord/lib/active_record/fixtures.rb', line 828
def run_in_transaction?
use_transactional_fixtures &&
!self.class.uses_transaction?(method_name)
end
|
#setup_fixtures ⇒ Object
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
# File 'activerecord/lib/active_record/fixtures.rb', line 833
def setup_fixtures
return unless !ActiveRecord::Base.configurations.blank?
if pre_loaded_fixtures && !use_transactional_fixtures
raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
end
@fixture_cache = {}
@fixture_connections = []
@@already_loaded_fixtures ||= {}
if run_in_transaction?
if @@already_loaded_fixtures[self.class]
@loaded_fixtures = @@already_loaded_fixtures[self.class]
else
@loaded_fixtures = load_fixtures
@@already_loaded_fixtures[self.class] = @loaded_fixtures
end
@fixture_connections = enlist_fixture_connections
@fixture_connections.each do |connection|
connection.increment_open_transactions
connection.transaction_joinable = false
connection.begin_db_transaction
end
else
ActiveRecord::Fixtures.reset_cache
@@already_loaded_fixtures[self.class] = nil
@loaded_fixtures = load_fixtures
end
instantiate_fixtures if use_instantiated_fixtures
end
|