# If trash_at is updated without touching delete_at, automatically
# update delete_at to a sensible value.
def default_trash_interval
- if trash_at && trash_at_changed? && !delete_at_changed?
- self.delete_at = trash_at + Rails.configuration.default_trash_lifetime.seconds
- elsif trash_at.nil? && trash_at_changed? && !delete_at_changed?
- self.delete_at = nil
+ if trash_at_changed? && !delete_at_changed?
+ if trash_at.nil?
+ self.delete_at = nil
+ else
+ self.delete_at = trash_at + Rails.configuration.default_trash_lifetime.seconds
+ end
end
end
def validate_trash_and_delete_timing
if trash_at.nil? != delete_at.nil?
- errors.add :delete_at, "must be nil if and only if trash_at is nil"
+ errors.add :delete_at, "must be set if trash_at is set, and must be nil otherwise"
end
earliest_delete = ([@validation_timestamp, trash_at_was].compact.min +