Skip to content

Commit

Permalink
Merge pull request #39 from goatapp/rescue-exception
Browse files Browse the repository at this point in the history
Rescue from Exception, not just StandardError
  • Loading branch information
grosser authored Oct 11, 2023
2 parents 356ac79 + a0d5d78 commit ff94ddc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/ar_after_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def transaction_with_after(**args)
clean = false
raise
end
rescue StandardError
rescue Exception
clean = false
raise
ensure
Expand Down
12 changes: 11 additions & 1 deletion spec/ar_after_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def oops
def raise_rollback
raise ActiveRecord::Rollback
end

def sigterm
raise SignalException.new('TERM')
end
end

describe ARAfterTransaction do
Expand All @@ -54,12 +58,18 @@ def raise_rollback
expect(User.test_stack).to eq [:normal, :after]
end

it 'does not execute when transaction was rolled back' do
it 'does not execute when transaction was rolled back by a StandardError' do
User.test_callbacks = [:do_after, :do_normal, :oops]
expect(-> { User.create! }).to raise_error(AnExpectedError)
expect(User.test_stack).to eq [:normal]
end

it 'does not execute when transaction was rolled back by an Exception' do
User.test_callbacks = [:do_after, :do_normal, :sigterm]
expect(-> { User.create! }).to raise_error(SignalException)
expect(User.test_stack).to eq [:normal]
end

it 'does not execute when transaction gets rolled back by ActiveRecord::Rollback '\
'raised in an after_create callback' do
User.test_callbacks = [:do_after, :do_normal, :raise_rollback]
Expand Down

0 comments on commit ff94ddc

Please sign in to comment.