Skip to content

Commit c22574f

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

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
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)
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
# frozen_string_literal: true
22

33
RSpec.describe RuboCop::Cop::Rails::PrivateTransactionOption, :config do
4-
it 'registers an offense when using `joinable: false`' do
4+
it 'registers an offense when using `ActiveRecord::Base.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
10+
RUBY
11+
end
12+
13+
it 'registers an offense when using `Account.transaction(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
819
RUBY
920
end
1021

1122
it 'does not register an offense when using only `requires_new: true`' do
1223
expect_no_offenses(<<~RUBY)
13-
ActiveRecord::Base.transaction(requires_new: true)
24+
ActiveRecord::Base.transaction(requires_new: true) do
25+
# ...
26+
end
1427
RUBY
1528
end
1629
end

0 commit comments

Comments
 (0)