Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Pirozhkov <[email protected]>
  • Loading branch information
wata727 and pirj authored Jul 27, 2024
1 parent e861a14 commit 7e71ea4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/private_transaction_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Rails
# ActiveRecord::Base.transaction(requires_new: true)
#
class PrivateTransactionOption < Base
MSG = 'Do not use `ActiveRecord::Base.transaction(joinable: _)`.'
MSG = 'Use a negated `requires_new` option instead of the internal `joinable`.'
RESTRICT_ON_SEND = %i[transaction].freeze

# @!method match_transaction_with_joinable(node)
Expand Down
18 changes: 15 additions & 3 deletions spec/rubocop/cop/rails/private_transaction_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
RSpec.describe RuboCop::Cop::Rails::PrivateTransactionOption, :config do
it 'registers an offense when using `joinable: false`' do
expect_offense(<<~RUBY)
ActiveRecord::Base.transaction(requires_new: true, joinable: false)
^^^^^^^^^^^^^^^ Do not use `ActiveRecord::Base.transaction(joinable: _)`.
ActiveRecord::Base.transaction(requires_new: true, joinable: false) do
^^^^^^^^^^^^^^^ Use a negated `requires_new` option instead of the internal `joinable`.
# ...
end
RUBY
end

it 'registers an offense when using `joinable: false`' do
expect_offense(<<~RUBY)
account.transaction(requires_new: true, joinable: false) do
^^^^^^^^^^^^^^^ Use a negated `requires_new` option instead of the internal `joinable`.
# ...
end
RUBY
end
it 'does not register an offense when using only `requires_new: true`' do
expect_no_offenses(<<~RUBY)
ActiveRecord::Base.transaction(requires_new: true)
ActiveRecord::Base.transaction(requires_new: true) do
# ...
end
RUBY
end
end

0 comments on commit 7e71ea4

Please sign in to comment.