Commit 2bc73cb4 by rbr Committed by rbr

Touch record on paranoia-destroy. Fixes #296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
parent 6972b229
......@@ -110,7 +110,6 @@ module Paranoia
if (noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen
write_attribute paranoia_column, paranoia_sentinel_value
update_columns(paranoia_restore_attributes)
touch
end
restore_associated_records if opts[:recursive]
end
......@@ -154,13 +153,17 @@ module Paranoia
def paranoia_restore_attributes
{
paranoia_column => paranoia_sentinel_value
}
}.merge(timestamp_attributes_with_current_time)
end
def paranoia_destroy_attributes
{
paranoia_column => current_time_from_proper_timezone
}
}.merge(timestamp_attributes_with_current_time)
end
def timestamp_attributes_with_current_time
timestamp_attributes_for_update_in_model.each_with_object({}) { |attr,hash| hash[attr] = current_time_from_proper_timezone }
end
# restore associated records that have been soft deleted when
......
......@@ -774,6 +774,13 @@ class ParanoiaTest < test_framework
refute b.valid?
end
def test_updated_at_modification_on_destroy
paranoid_model = ParanoidModelWithTimestamp.create(:parent_model => ParentModel.create, :updated_at => 1.day.ago)
assert paranoid_model.updated_at < 10.minutes.ago
paranoid_model.destroy
assert paranoid_model.updated_at > 10.minutes.ago
end
def test_updated_at_modification_on_restore
parent1 = ParentModel.create
pt1 = ParanoidModelWithTimestamp.create(:parent_model => parent1)
......
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