diff options
author | Jamis Buck <jamis@37signals.com> | 2005-06-10 14:58:02 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-06-10 14:58:02 +0000 |
commit | 2c0fa3208859aed2c1fd0ce54c8d5215d11d0c75 (patch) | |
tree | b65523d2f9c2d0b79bc0b65157e966ee36ebd1a2 /activerecord/lib | |
parent | 7f9ffb2ebf1a0230368f54a6372cb7196c90177e (diff) | |
download | rails-2c0fa3208859aed2c1fd0ce54c8d5215d11d0c75.tar.gz rails-2c0fa3208859aed2c1fd0ce54c8d5215d11d0c75.tar.bz2 rails-2c0fa3208859aed2c1fd0ce54c8d5215d11d0c75.zip |
Do not use instantiated fixtures (in general) in tests. Also, support the use of transactional fixtures by setting the AR_TX_FIXTURES environment variable to "yes".
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1399 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index c32d3d78e4..3aa8920815 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -441,6 +441,20 @@ module Test #:nodoc: end end + def self.uses_transaction(*methods) + @uses_transaction ||= [] + @uses_transaction.concat methods.map { |m| m.to_s } + end + + def self.uses_transaction?(method) + @uses_transaction && @uses_transaction.include?(method.to_s) + end + + def use_transactional_fixtures? + use_transactional_fixtures && + !self.class.uses_transaction?(method_name) + end + def setup_with_fixtures if pre_loaded_fixtures && !use_transactional_fixtures raise RuntimeError, 'pre_loaded_fixtures requires use_transactional_fixtures' @@ -449,7 +463,7 @@ module Test #:nodoc: @fixture_cache = Hash.new # Load fixtures once and begin transaction. - if use_transactional_fixtures + if use_transactional_fixtures? if @@already_loaded_fixtures[self.class] @loaded_fixtures = @@already_loaded_fixtures[self.class] else @@ -461,6 +475,7 @@ module Test #:nodoc: # Load fixtures for every test. else + @@already_loaded_fixtures[self.class] = nil load_fixtures end @@ -472,7 +487,7 @@ module Test #:nodoc: def teardown_with_fixtures # Rollback changes. - if use_transactional_fixtures + if use_transactional_fixtures? ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.unlock_mutex end |