Added without_versioning method
Signed-off-by: Andy Stewart <boss@airbladesoftware.com>
This commit is contained in:
parent
6d0148b1df
commit
0a45f6973b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue