Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.0.0 regression? Inside if proc, the updated_at is already updated #656

Closed
gamov opened this issue Nov 27, 2015 · 3 comments
Closed

v4.0.0 regression? Inside if proc, the updated_at is already updated #656

gamov opened this issue Nov 27, 2015 · 3 comments

Comments

@gamov
Copy link

gamov commented Nov 27, 2015

Given:

class ItemVariant < ActiveRecord::Base
  has_paper_trail :on => [:update, :destroy],
                  :class_name => 'ItemVariantVersion',
                  if: proc {|t| t.changed? && (t.updated_at < Time.current - 1.week)}
end

# then when
iv = ItemVariant.new
iv.save! # no version
iv.updated_at = 2.weeks.ago; iv.save!
iv.first_name = 'this should trigger versioning'
iv.save! # => should create version

Starting with version 4.0.0, new version is never created because attribute 'updated_at' in the if proc is already updated to now. Works fine under 3.0.8.

I'm not familiar enough with the codebase but it might be related to this pull request: #563

@jaredbeck
Copy link
Member

This was a deliberate change in 4.0.0, specifically #375.

You can change your proc as follows:

- if: proc {|t| t.changed? && (t.updated_at < Time.current - 1.week)}
+ if: proc {|t| t.changed? && (t.updated_at_was < Time.current - 1.week)}

This breaking change in 4.0.0 is documented in https://github.com/airblade/paper_trail/blob/master/CHANGELOG.md as follows:

#375 / #374 / #354 / #131 - Versions are now saved with an after_ callback, instead of a before_ callback. This ensures that the timestamp field for a version matches the corresponding timestamp in the model.

Thanks for opening the issue, I can see why you'd think it was a regression, but it was deliberate.

@gamov
Copy link
Author

gamov commented Nov 30, 2015

oic, thanks @jaredbeck! It makes sense now. I find it a bit counter-intuitive though, maybe it would be good to mention it in the doc, especially under 'Choosing When To Save New Versions'.

@jaredbeck
Copy link
Member

.. maybe it would be good to mention it in the doc, especially under 'Choosing When To Save New Versions'.

That would be helpful, thanks. Please submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants