Added without_versioning method

Signed-off-by: Andy Stewart <boss@airbladesoftware.com>
This commit is contained in:
Edward Tsech 2011-08-25 20:03:42 +07:00 committed by Andy Stewart
parent 6d0148b1df
commit 0a45f6973b
2 changed files with 32 additions and 0 deletions

View File

@ -104,6 +104,13 @@ module PaperTrail
subsequent_version.reify if subsequent_version
end
def without_versioning(method=nil)
paper_trail_was_enabled = self.paper_trail_enabled_for_model
self.class.paper_trail_off
method ? method.to_proc.call(self) : yield
self.class.paper_trail_on if paper_trail_was_enabled
end
private
def version_class

View File

@ -201,6 +201,8 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
end
end
end
end
end
@ -334,6 +336,13 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
end
end
context 'when destroyed "without versioning"' do
should 'leave paper trail off after call' do
@widget.without_versioning :destroy
assert !Widget.paper_trail_enabled_for_model
end
end
context 'and then its paper trail turned on' do
setup { Widget.paper_trail_on }
@ -344,6 +353,22 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
assert_equal @count + 1, @widget.versions.length
end
end
context 'when updated "without versioning"' do
setup do
@widget.without_versioning do
@widget.update_attributes :name => 'Ford'
end
end
should 'not create new version' do
assert_equal 1, @widget.versions.length
end
should 'enable paper trail after call' do
assert Widget.paper_trail_enabled_for_model
end
end
end
end
end