Module: Mongoid::TestFixtures

Extended by:
ActiveSupport::Concern
Included in:
ActiveSupport::TestCase
Defined in:
lib/mongoid_rails_fixtures/mongoid_ext/fixtures.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#run_in_transaction?Boolean

Returns:

  • (Boolean)


911
912
913
914
915
# File 'lib/mongoid_rails_fixtures/mongoid_ext/fixtures.rb', line 911

def run_in_transaction?
  # use_transactional_fixtures &&
  #         !self.class.uses_transaction?(method_name)
  false
end

#setup_fixturesObject



917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'lib/mongoid_rails_fixtures/mongoid_ext/fixtures.rb', line 917

def setup_fixtures
  return unless defined?(Mongoid) && !Mongoid.config.blank?

  if pre_loaded_fixtures && !use_transactional_fixtures
    raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures'
  end

  @fixture_cache = {}
  @@already_loaded_fixtures ||= {}

  # Load fixtures files once for all tests.
  if use_instantiated_fixtures && Fixtures.class_variable_get(:@@all_cached_fixtures).size == 0
    Fixtures.reset_cache
    @@already_loaded_fixtures[self.class] = nil
    load_fixtures && instantiate_fixtures
  end

end

#teardown_fixturesObject



936
937
938
939
940
941
942
943
944
# File 'lib/mongoid_rails_fixtures/mongoid_ext/fixtures.rb', line 936

def teardown_fixtures
  return unless defined?(Mongoid) && !Mongoid.config.blank?

  unless run_in_transaction?
    Fixtures.reset_cache
  end

  # ActiveRecord::Base.clear_active_connections!
end