Skip to content

Commit 7e71ea4

Browse files
wata727pirj
andauthored
Apply suggestions from code review
Co-authored-by: Phil Pirozhkov <[email protected]>
1 parent e861a14 commit 7e71ea4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/rubocop/cop/rails/private_transaction_option.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Rails
2525
# ActiveRecord::Base.transaction(requires_new: true)
2626
#
2727
class PrivateTransactionOption < Base
28-
MSG = 'Do not use `ActiveRecord::Base.transaction(joinable: _)`.'
28+
MSG = 'Use a negated `requires_new` option instead of the internal `joinable`.'
2929
RESTRICT_ON_SEND = %i[transaction].freeze
3030

3131
# @!method match_transaction_with_joinable(node)

spec/rubocop/cop/rails/private_transaction_option_spec.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33
RSpec.describe RuboCop::Cop::Rails::PrivateTransactionOption, :config do
44
it 'registers an offense when using `joinable: false`' do
55
expect_offense(<<~RUBY)
6-
ActiveRecord::Base.transaction(requires_new: true, joinable: false)
7-
^^^^^^^^^^^^^^^ Do not use `ActiveRecord::Base.transaction(joinable: _)`.
6+
ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
7+
^^^^^^^^^^^^^^^ Use a negated `requires_new` option instead of the internal `joinable`.
8+
# ...
9+
end
810
RUBY
911
end
1012

13+
it 'registers an offense when using `joinable: false`' do
14+
expect_offense(<<~RUBY)
15+
account.transaction(requires_new: true, joinable: false) do
16+
^^^^^^^^^^^^^^^ Use a negated `requires_new` option instead of the internal `joinable`.
17+
# ...
18+
end
19+
RUBY
20+
end
1121
it 'does not register an offense when using only `requires_new: true`' do
1222
expect_no_offenses(<<~RUBY)
13-
ActiveRecord::Base.transaction(requires_new: true)
23+
ActiveRecord::Base.transaction(requires_new: true) do
24+
# ...
25+
end
1426
RUBY
1527
end
1628
end

0 commit comments

Comments
 (0)