Skip to content

Commit

Permalink
Merge pull request #2495 from st0012/fix-uses_transaction
Browse files Browse the repository at this point in the history
Fix FixtureSupport#run_in_transaction?
  • Loading branch information
pirj authored and JonRowe committed Apr 29, 2021
1 parent 08544a8 commit 2c15abe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rspec/rails/fixture_support.rb
Expand Up @@ -13,7 +13,8 @@ module FixtureSupport
# Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after
# and let(:method_name) before Rails 6.1.
def run_in_transaction?
use_transactional_tests && !self.class.uses_transaction?(self)
current_example_name = (RSpec.current_example && RSpec.current_example.metadata[:description])
use_transactional_tests && !self.class.uses_transaction?(current_example_name)
end

included do
Expand Down
27 changes: 27 additions & 0 deletions spec/rspec/rails/fixture_support_spec.rb
Expand Up @@ -12,6 +12,33 @@ module RSpec::Rails
end
end

context "with use_transactional_tests set to true" do
it "works with #uses_transaction helper" do
group = RSpec::Core::ExampleGroup.describe do
include FixtureSupport
self.use_transactional_tests = true

uses_transaction "doesn't run in transaction"

it "doesn't run in transaction" do
expect(ActiveRecord::Base.connection.transaction_open?).to eq(false)
end

it "runs in transaction" do
expect(ActiveRecord::Base.connection.transaction_open?).to eq(true)
end
end

expect_to_pass(group)
end

def expect_to_pass(group)
result = group.run(failure_reporter)
failure_reporter.exceptions.map { |e| raise e }
expect(result).to be true
end
end

it "will allow #setup_fixture to run successfully", skip: Rails.version.to_f <= 6.0 do
group = RSpec::Core::ExampleGroup.describe do
include FixtureSupport
Expand Down

0 comments on commit 2c15abe

Please sign in to comment.