Module: DisableTestFixtures

Defined in:
lib/disable_test_fixtures.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

Fixtures =
defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures : Fixtures
@@last_test_loaded_fixtures =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/disable_test_fixtures.rb', line 9

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#fixtures_disabled?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/disable_test_fixtures.rb', line 84

def fixtures_disabled?
  self.class.fixtures_disabled?(method_name)
end

#setup_fixturesObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/disable_test_fixtures.rb', line 88

def setup_fixtures
  unless fixtures_disabled?
    self.last_test_loaded_fixtures = true
    return super # default (real) setup_fixtures from TestFixtures
  end

  if last_test_loaded_fixtures?
    # need to reset all loaded fixtures - empty the tables :
    unless (loaded_fixtures = already_loaded_fixtures).blank?
      clear_loaded_fixtures(loaded_fixtures)
    end
  end

  self.last_test_loaded_fixtures = false
  @fixture_cache = {} # fixture helpers should work and return nothing
  @fixture_connections = [] if enlist = respond_to?(:enlist_fixture_connections)

  # begin transaction :
  if use_transactional_fixtures? #run_in_transaction?
    if enlist
      @fixture_connections = enlist_fixture_connections
      @fixture_connections.each do |connection|
        connection.increment_open_transactions
        connection.transaction_joinable = false
        connection.begin_db_transaction
      end
    else
      connection = ActiveRecord::Base.connection
      connection.increment_open_transactions
      connection.transaction_joinable = false if connection.respond_to?(:transaction_joinable=)
      connection.begin_db_transaction
    end
  else
    Fixtures.reset_cache # just to be sure ...
  end
end