Skip to content

Commit 7b4f40b

Browse files
committed
Fix FixtureSupport's run_in_transaction? method
`ActiveRecord::TestFixture`'s `uses_transaction` is designed to be used like this: ```ruby uses_transaction :the_test_method_name ``` And in RSpec, the method name would be the example's name. ```ruby uses_transaction "does someting" it "does someting" {} ``` But in the current implementation, it's passing the example object instead of its name, which would always fail the name comparison in https://github.com/rails/rails/blob/main/activerecord/lib/active_record/test_fixtures.rb#L94-L97 So this commit fixes the issue by passing the example's name instead of the example object.
1 parent f093617 commit 7b4f40b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/rspec/rails/fixture_support.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module FixtureSupport
1313
# Monkey patched to avoid collisions with 'let(:name)' in Rails 6.1 and after
1414
# and let(:method_name) before Rails 6.1.
1515
def run_in_transaction?
16-
use_transactional_tests && !self.class.uses_transaction?(self)
16+
current_example_name = (RSpec.current_example && RSpec.current_example.metadata[:description])
17+
use_transactional_tests && !self.class.uses_transaction?(current_example_name)
1718
end
1819

1920
included do

0 commit comments

Comments
 (0)