Skip to content

Commit

Permalink
close #307, close #326, close #328; Make Model.paper_trail_enabled_fo…
Browse files Browse the repository at this point in the history
…r_model? thread-safe
  • Loading branch information
batter committed Feb 20, 2014
1 parent 95a50ae commit 0359704
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.

Expand Down
8 changes: 6 additions & 2 deletions lib/paper_trail/has_paper_trail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ def next_version
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
Expand Down Expand Up @@ -334,7 +338,7 @@ def changed_and_not_ignored
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?
Expand Down
12 changes: 6 additions & 6 deletions spec/models/widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
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

Expand All @@ -54,10 +54,10 @@

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

Expand Down

0 comments on commit 0359704

Please sign in to comment.