Support conditional paper trail on destroy

This commit is contained in:
Jon Larkowski and Sandro Turriate 2012-08-13 16:09:45 -07:00 committed by Jon Larkowski
parent e870e0d561
commit a517bc333c
2 changed files with 19 additions and 1 deletions

View File

@ -72,7 +72,7 @@ module PaperTrail
after_create :record_create, :if => :save_version? if !options[:on] || options[:on].include?(:create)
before_update :record_update, :if => :save_version? if !options[:on] || options[:on].include?(:update)
after_destroy :record_destroy if !options[:on] || options[:on].include?(:destroy)
after_destroy :record_destroy, :if => :save_version? if !options[:on] || options[:on].include?(:destroy)
end
# Switches PaperTrail off for this class.

View File

@ -79,6 +79,15 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
setup { @translation.update_attributes :content => 'Content' }
should_not_change('the number of versions') { Version.count }
end
context 'after destroy' do
setup do
@translation.save!
@translation.destroy
end
should_not_change('the number of versions') { Version.count }
end
end
context 'for US translations' do
@ -107,6 +116,15 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
setup { @translation.update_attributes :content => 'Content' }
should_change('the number of versions', :by => 1) { Version.count }
end
context 'after destroy' do
setup do
@translation.save!
@translation.destroy
end
should_change('the number of versions', :by => 1) { Version.count }
end
end
end
end