Skip to content

Commit 812251d

Browse files
authored
Merge pull request #1509 from Earlopain/transaction-exit-method-chain
[Fix #1508] Fix an error for `Rails/TransactionExitStatement` when method is chained
2 parents ab16693 + abfe2f0 commit 812251d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1508](https://github.com/rubocop/rubocop-rails/issues/1508): Fix an error for `Rails/TransactionExitStatement` when `transaction` is part of a method chain. ([@earlopain][])

lib/rubocop/cop/rails/transaction_exit_statement.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def on_send(node)
9797

9898
def in_transaction_block?(node)
9999
return false unless transaction_method_name?(node.method_name)
100-
return false unless node.parent&.body
100+
return false unless (parent = node.parent)
101+
return false unless parent.any_block_type? && parent.body
101102

102103
node.right_siblings.none? do |sibling|
103104
sibling.respond_to?(:loop_keyword?) && sibling.loop_keyword?

spec/rubocop/cop/rails/transaction_exit_statement_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,18 @@
189189
end
190190
RUBY
191191
end
192+
193+
it 'does not register an offense when a method call is chained' do
194+
expect_no_offenses(<<~RUBY)
195+
#{method}.foo
196+
RUBY
197+
end
198+
199+
it 'does not register an offense when no receiver and no block' do
200+
expect_no_offenses(<<~RUBY)
201+
#{method}
202+
RUBY
203+
end
192204
end
193205

194206
it_behaves_like 'flags transaction exit statements', :transaction

0 commit comments

Comments
 (0)