Created
January 13, 2012 21:49
-
-
Save grosser/1608889 to your computer and use it in GitHub Desktop.
Using no transactions for js request specs (may not work, just a prototype I do not want to loose...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# js-request tests cannot use transactions, since they happen in another process | |
# so if we are in js request tests, use the real test database and then clean it afterwards | |
module ActiveRecord | |
module TestFixtures | |
def run_in_transaction_with_js? | |
return false if $disable_transactions | |
run_in_transaction_without_js? | |
end | |
alias_method_chain :run_in_transaction?, :js | |
end | |
end | |
RSpec.configure do |config| | |
config.around do |block| | |
if example.metadata[:js] | |
$disable_transactions = true | |
block.call | |
$disable_transactions = false | |
# kill everything | |
DatabaseCleaner.clean_with(:truncation) | |
# reload all fixtures for next test | |
ActiveRecord::Fixtures.reset_cache | |
fixtures_folder = File.join(Rails.root, 'test', 'fixtures') | |
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f| File.basename(f, '.yml') } | |
ActiveRecord::Fixtures.create_fixtures(fixtures_folder, fixtures) | |
else | |
block.call | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment