Skip to content

Commit 466f764

Browse files
authored
Merge pull request #1366 from Earlopain/transaction-exit-rails-7.2
[Fix #727] Disable `Rails/TransactionExitStatement` on Rails >= 7.2
2 parents d1b7186 + a171638 commit 466f764

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#727](https://github.com/rubocop/rubocop-rails/issues/727): Disable `Rails/TransactionExitStatement` on Rails >= 7.2. ([@earlopain][])

lib/rubocop/cop/rails/transaction_exit_statement.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module Rails
1515
#
1616
# If you are defining custom transaction methods, you can configure it with `TransactionMethods`.
1717
#
18+
# NOTE: This cop is disabled on Rails >= 7.2 because transactions were restored
19+
# to their historical behavior. In Rails 7.1, the behavior is controlled with
20+
# the config `active_record.commit_transaction_on_non_local_return`.
21+
#
1822
# @example
1923
# # bad
2024
# ApplicationRecord.transaction do
@@ -76,6 +80,7 @@ class TransactionExitStatement < Base
7680
PATTERN
7781

7882
def on_send(node)
83+
return if target_rails_version >= 7.2
7984
return unless in_transaction_block?(node)
8085

8186
exit_statements(node.parent.body).each do |statement_node|

spec/rubocop/cop/rails/transaction_exit_statement_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,14 @@
114114

115115
it_behaves_like 'flags transaction exit statements', :writable_transaction
116116
end
117+
118+
context 'Rails >= 7.2', :rails72 do
119+
it 'registers no offense' do
120+
expect_no_offenses(<<~RUBY)
121+
ApplicationRecord.transaction do
122+
return if user.active?
123+
end
124+
RUBY
125+
end
126+
end
117127
end

spec/support/shared_contexts.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@
3131
RSpec.shared_context 'with Rails 7.1', :rails71 do
3232
let(:rails_version) { 7.1 }
3333
end
34+
35+
RSpec.shared_context 'with Rails 7.2', :rails72 do
36+
let(:rails_version) { 7.2 }
37+
end

0 commit comments

Comments
 (0)