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 committed Jul 27, 2024
1 parent e861a14 commit c22574f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 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
21 changes: 17 additions & 4 deletions spec/rubocop/cop/rails/private_transaction_option_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Rails::PrivateTransactionOption, :config do
it 'registers an offense when using `joinable: false`' do
it 'registers an offense when using `ActiveRecord::Base.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 `Account.transaction(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 c22574f

Please sign in to comment.