From 035970475163c4ca60961e8b306e396afc94e456 Mon Sep 17 00:00:00 2001 From: Ben Atkins Date: Thu, 20 Feb 2014 11:40:52 -0500 Subject: [PATCH] close #307, close #326, close #328; Make Model.paper_trail_enabled_for_model? thread-safe --- CHANGELOG.md | 9 ++++++--- lib/paper_trail/has_paper_trail.rb | 8 ++++++-- spec/models/widget_spec.rb | 12 ++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6952e4c..0b131bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 3.0.1 (Unreleased) + - [#328](https://github.com/airblade/paper_trail/pull/328) / [#326](https://github.com/airblade/paper_trail/issues/326)/ + [#307](https://github.com/airblade/paper_trail/issues/307) - `Model.paper_trail_enabled_for_model?` and + `model_instance.without_versioning` is now thread-safe. - [#316](https://github.com/airblade/paper_trail/issues/316) - `user_for_paper_trail` should default to `current_user.try(:id)` instead of `current_user` (if `current_user` is defined). - [#313](https://github.com/airblade/paper_trail/pull/313) - Make the `Rails::Controller` helper compatible with @@ -44,11 +47,11 @@ ## 2.7.2 - [#228](https://github.com/airblade/paper_trail/issues/228) - Refactored default `user_for_paper_trail` method implementation - so that `current_user` only gets invoked if it is defined. + so that `current_user` only gets invoked if it is defined. - [#219](https://github.com/airblade/paper_trail/pull/219) - Fixed issue where attributes stored with `nil` value might not get - reified properly depending on the way the serializer worked. + reified properly depending on the way the serializer worked. - [#213](https://github.com/airblade/paper_trail/issues/213) - Added a `version_limit` option to the `PaperTrail::Config` options - that can be used to restrict the number of versions PaperTrail will store per object instance. + that can be used to restrict the number of versions PaperTrail will store per object instance. - [#187](https://github.com/airblade/paper_trail/pull/187) - Confirmed JRuby support. - [#174](https://github.com/airblade/paper_trail/pull/174) - The `event` field on the versions table can now be customized. diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 96f5ddd3..8efd0720 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -203,9 +203,13 @@ module PaperTrail nil end + def paper_trail_enabled_for_model? + self.class.paper_trail_enabled_for_model? + end + # Executes the given method or block without creating a new version. def without_versioning(method = nil) - paper_trail_was_enabled = self.class.paper_trail_enabled_for_model? + paper_trail_was_enabled = self.paper_trail_enabled_for_model? self.class.paper_trail_off! method ? method.to_proc.call(self) : yield ensure @@ -334,7 +338,7 @@ module PaperTrail end def paper_trail_switched_on? - PaperTrail.enabled? && PaperTrail.enabled_for_controller? && self.class.paper_trail_enabled_for_model? + PaperTrail.enabled? && PaperTrail.enabled_for_controller? && self.paper_trail_enabled_for_model? end def save_version? diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index b0e45d64..576e771d 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -27,10 +27,10 @@ describe Widget do describe :paper_trail_off! do it { should respond_to(:paper_trail_off!) } - it 'should set the `paper_trail_enabled_for_model` to `false`' do - subject.paper_trail_enabled_for_model.should be_true + it 'should set the `paper_trail_enabled_for_model?` to `false`' do + subject.paper_trail_enabled_for_model?.should be_true subject.paper_trail_off! - subject.paper_trail_enabled_for_model.should be_false + subject.paper_trail_enabled_for_model?.should be_false end end @@ -54,10 +54,10 @@ describe Widget do it { should respond_to(:paper_trail_on!) } - it 'should set the `paper_trail_enabled_for_model` to `true`' do - subject.paper_trail_enabled_for_model.should be_false + it 'should set the `paper_trail_enabled_for_model?` to `true`' do + subject.paper_trail_enabled_for_model?.should be_false subject.paper_trail_on! - subject.paper_trail_enabled_for_model.should be_true + subject.paper_trail_enabled_for_model?.should be_true end end