File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ module Rails
25
25
# ActiveRecord::Base.transaction(requires_new: true)
26
26
#
27
27
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 `.'
29
29
RESTRICT_ON_SEND = %i[ transaction ] . freeze
30
30
31
31
# @!method match_transaction_with_joinable(node)
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
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
5
5
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
8
19
RUBY
9
20
end
10
21
11
22
it 'does not register an offense when using only `requires_new: true`' do
12
23
expect_no_offenses ( <<~RUBY )
13
- ActiveRecord::Base.transaction(requires_new: true)
24
+ ActiveRecord::Base.transaction(requires_new: true) do
25
+ # ...
26
+ end
14
27
RUBY
15
28
end
16
29
end
You can’t perform that action at this time.
0 commit comments