Commit e780b4e7 by Emanuel Evans

Don't try to add to null transactions

Fixes https://github.com/rubysherpas/paranoia/issues/274

It looks like ActiveRecord refactored the Transaction class hierarchy in
a non-backwards-compatible
way (https://github.com/rails/rails/pull/16363), which breaks
`add_to_transaction` for null transactions (I think it probably
qualifies as a bug). The workaround is to not try to use
`add_to_transaction` in null transactions.
parent 3502f452
......@@ -93,7 +93,7 @@ module Paranoia
if persisted?
# if a transaction exists, add the record so that after_commit
# callbacks can be run
add_to_transaction
add_to_transaction unless self.class.connection.current_transaction.closed?
update_columns(paranoia_destroy_attributes)
elsif !frozen?
assign_attributes(paranoia_destroy_attributes)
......
......@@ -88,6 +88,14 @@ class ParanoiaTest < test_framework
assert_equal to_param, model.to_param
end
def test_paranoid_model_delete_outside_transaction
model = ParanoidModel.new
model.save!
model.delete
assert model.to_param
end
def test_destroy_behavior_for_plain_models
model = PlainModel.new
assert_equal 0, model.class.count
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment