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

The originator property is improperly cached #384

Closed
jonkessler opened this issue Jun 13, 2014 · 1 comment
Closed

The originator property is improperly cached #384

jonkessler opened this issue Jun 13, 2014 · 1 comment
Milestone

Comments

@jonkessler
Copy link

The originator property is permanently cached on model instances that have paper trails. This breaks the behavior shown in the README. Specifically, this does not work:

>> widget = Widget.find 153                    # assume widget has 0 versions
>> PaperTrail.whodunnit = 'Alice'
>> widget.update_attributes :name => 'Yankee'
>> widget.originator                           # 'Alice'
>> PaperTrail.whodunnit = 'Bob'
>> widget.update_attributes :name => 'Zulu'
>> widget.originator                           # 'Bob'

The last widget.originator returns 'Alice', not 'Bob'. This is because the originator method on models is defined like this in has_paper_trail.rb:

# Returns who put the object into its current state.
def originator
  @originator ||= self.class.paper_trail_version_class.with_item_keys(self.class.base_class.name, id).last.try :whodunnit
end

Because of the '||=' in there, originator will never be recomputed for that particular instance. The caching was added in this commit: 43fdce6. I would suggest that that caching either be removed or be invalidated somehow when the originator has actually changed.

Thanks, and thanks for the good work on the gem.

@batter
Copy link
Collaborator

batter commented Jun 17, 2014

Good call on this, I think it probably makes sense just not to cache it. Let me take a crack at a patch this afternoon.

@batter batter added this to the 3.0.3 milestone Jun 17, 2014
@batter batter closed this as completed in e638392 Jun 17, 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