Commit c9728e18 by Ben A. Morgan Committed by GitHub

Merge pull request #377 from rbr/touch_on_destroy

Touch record on paranoia-destroy. Fixes #296
parents 6972b229 2bc73cb4
...@@ -110,7 +110,6 @@ module Paranoia ...@@ -110,7 +110,6 @@ module Paranoia
if (noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen if (noop_if_frozen && !@attributes.frozen?) || !noop_if_frozen
write_attribute paranoia_column, paranoia_sentinel_value write_attribute paranoia_column, paranoia_sentinel_value
update_columns(paranoia_restore_attributes) update_columns(paranoia_restore_attributes)
touch
end end
restore_associated_records if opts[:recursive] restore_associated_records if opts[:recursive]
end end
...@@ -154,13 +153,17 @@ module Paranoia ...@@ -154,13 +153,17 @@ module Paranoia
def paranoia_restore_attributes def paranoia_restore_attributes
{ {
paranoia_column => paranoia_sentinel_value paranoia_column => paranoia_sentinel_value
} }.merge(timestamp_attributes_with_current_time)
end end
def paranoia_destroy_attributes def paranoia_destroy_attributes
{ {
paranoia_column => current_time_from_proper_timezone 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 end
# restore associated records that have been soft deleted when # restore associated records that have been soft deleted when
......
...@@ -774,6 +774,13 @@ class ParanoiaTest < test_framework ...@@ -774,6 +774,13 @@ class ParanoiaTest < test_framework
refute b.valid? refute b.valid?
end 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 def test_updated_at_modification_on_restore
parent1 = ParentModel.create parent1 = ParentModel.create
pt1 = ParanoidModelWithTimestamp.create(:parent_model => parent1) 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