Skip to content

Commit

Permalink
Fix FixtureSupport's run_in_transaction? method
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
st0012 committed Apr 20, 2021
1 parent 008eab7 commit 11db9fc
Showing 1 changed file with 2 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

0 comments on commit 11db9fc

Please sign in to comment.