From 7b4f40bc761b0ae0ee590f145854e47e2d73fc12 Mon Sep 17 00:00:00 2001 From: st0012 Date: Mon, 19 Apr 2021 21:41:25 +0800 Subject: [PATCH] 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. --- lib/rspec/rails/fixture_support.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/fixture_support.rb b/lib/rspec/rails/fixture_support.rb index 63334b793..9c7d1eeb5 100644 --- a/lib/rspec/rails/fixture_support.rb +++ b/lib/rspec/rails/fixture_support.rb @@ -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