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

Ignoring attributes is not working #414

Closed
nneal opened this issue Aug 29, 2014 · 7 comments
Closed

Ignoring attributes is not working #414

nneal opened this issue Aug 29, 2014 · 7 comments
Assignees
Milestone

Comments

@nneal
Copy link

nneal commented Aug 29, 2014

Using paper_trail 3.0.3 and rails 4.1.5

In my model, I've tried all three of the following:

has_paper_trail ignore: [:score]

has_paper_trail ignore: [:score], skip: [:score]    

has_paper_trail skip: [:score]

My test is as such:

it 'does not add version for update score' do
  PaperTrail.enabled = true
  conversation = create(:conversation)

  # passes
  expect(PaperTrail::Version.count).to eq 1

  conversation.update_attribute(:score, 10)
  conversation.save

  # fails
  expect(PaperTrail::Version.count).to eq 1
end

Am I doing something funky or is this feature not working? Any troubleshooting ideas?

@nneal
Copy link
Author

nneal commented Aug 29, 2014

Okay, I solved this myself. the answer is to do:

has_paper_trail ignore: [:score, :updated_at]

A bit confusing though, would be nice to add this to docs.

@batter
Copy link
Collaborator

batter commented Oct 2, 2014

Apologies for the delayed response. Seems like it may be a bug in ActiveRecord 4.1.5, I can't reproduce with ActiveRecord 4.1.1, and we definitely have a bunch of test cases in our repo that should flesh that out.. Are you sure there's not something else going on here?

@batter batter self-assigned this Oct 2, 2014
@batter
Copy link
Collaborator

batter commented Oct 2, 2014

Nevermind, I think I can reproduce this locally. Seems like it may be a change in the way ActiveModel::Dirty reports the timestamps into the changes hash. Either way, we are definitely going to need to fix this for 3.1.0 since the callbacks are now using after_ instead of before_ (see #374). Actually this probably warrants a 3.0.6 release with an immediate fix. Ugh!

@batter batter added this to the 3.1.0 milestone Oct 2, 2014
@batter
Copy link
Collaborator

batter commented Oct 2, 2014

After some additional testing I can confirm that this is a change in the way that datestamps get inserted into the changes hash via ActiveModel::Dirty between 3.x and 4.x.

Here is evidence:

#  id                     :integer          not null, primary key
#  name                   :string(255)
class Model < ActiveRecord::Base
  before_update { p changed }
  after_update { p changed }
end

# ActiveRecord 3
> model.update_attribute(:name, 'foo')
(0.1ms)  SAVEPOINT active_record_1
['name']
(0.3ms)  UPDATE "models" SET "name" = 'foo', "updated_at" = '2014-10-02 06:39:10.113930' WHERE "models"."id" = 1
['name', 'updated_at']
(0.0ms)  RELEASE SAVEPOINT active_record_1
=> true

# ActiveRecord 4
> model.update_attribute(:name, 'foo')
(0.1ms)  SAVEPOINT active_record_1
['name', 'updated_at']
(0.3ms)  UPDATE "models" SET "name" = 'foo', "updated_at" = '2014-10-02 06:39:10.113930' WHERE "models"."id" = 1
['name', 'updated_at']
(0.0ms)  RELEASE SAVEPOINT active_record_1
=> true

@nneal
Copy link
Author

nneal commented Oct 3, 2014

Thanks! Will be much more straightforward to ignore updated_at

@batter batter closed this as completed in b551e3c Oct 8, 2014
batter added a commit that referenced this issue Oct 8, 2014
batter added a commit that referenced this issue Oct 9, 2014
@batter
Copy link
Collaborator

batter commented Oct 9, 2014

Just released version 3.0.6 which has the fix for this backported to it

@nneal
Copy link
Author

nneal commented Oct 9, 2014

👍

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