Commit d8592ae2 by John Hawthorn

Raise when destroying read only record

parent 56e0f47e
......@@ -107,6 +107,7 @@ module Paranoia
# insert time to paranoia column.
# @param with_transaction [Boolean] exec with ActiveRecord Transactions.
def touch_paranoia_column(with_transaction=false)
raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly?
return self if really_destroyed? || new_record?
# This method is (potentially) called from really_destroy
......
......@@ -291,6 +291,22 @@ class ParanoiaTest < test_framework
assert model.instance_variable_get(:@destroy_callback_called)
end
def test_destroy_on_readonly_record
# Just to demonstrate the AR behaviour
model = NonParanoidModel.create!
model.readonly!
assert_raises ActiveRecord::ReadOnlyRecord do
model.destroy
end
# Mirrors behaviour above
model = ParanoidModel.create!
model.readonly!
assert_raises ActiveRecord::ReadOnlyRecord do
model.destroy
end
end
def test_restore
model = ParanoidModel.new
model.save
......
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