Skip to content

Commit

Permalink
fix: switch to after_save since before_commit is not always allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRiedler authored Nov 29, 2023
1 parent 2ecc229 commit 86f2b63
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 0.13.0 - 2023-11-27
### Added
- Disallow `after_commit` as it has no transactional guarantee, switch to `before_commit`.
- Disallow `after_commit` as it has no transactional guarantee, switch to `after_save`.

## 0.12.1 - 2023-08-01
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/vendor/disallow_after_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DisallowAfterCommit < Base

NO_METH_MSG = "Do not not use `%<old>s` %<desc>s"
NO_METHS = {
after_commit: "use `before_commit` because after_commit is non-transactional an may not run",
after_commit: "use `after_save` because `after_commit` is non-transactional an may not run",
}.freeze

def on_send(node)
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/vendor/disallow_after_commit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
it 'registers an offense when using `after_commit` with no args' do
expect_offense(<<~RUBY)
after_commit
^^^^^^^^^^^^ Do not not use `after_commit` use `before_commit` because after_commit is non-transactional an may not run
^^^^^^^^^^^^ Do not not use `after_commit` use `after_save` because after_commit is non-transactional an may not run
RUBY
end

it 'registers an offense when using `after_commit` with args' do
expect_offense(<<~RUBY)
after_commit :foo_bar
^^^^^^^^^^^^^^^^^^^^^ Do not not use `after_commit` use `before_commit` because after_commit is non-transactional an may not run
^^^^^^^^^^^^^^^^^^^^^ Do not not use `after_commit` use `after_save` because after_commit is non-transactional an may not run
RUBY
end
end

0 comments on commit 86f2b63

Please sign in to comment.