From a517bc333c96b6fd51f414cb5683840b4a3b2e54 Mon Sep 17 00:00:00 2001 From: Jon Larkowski and Sandro Turriate Date: Mon, 13 Aug 2012 16:09:45 -0700 Subject: [PATCH] Support conditional paper trail on destroy --- lib/paper_trail/has_paper_trail.rb | 2 +- test/unit/model_test.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/paper_trail/has_paper_trail.rb b/lib/paper_trail/has_paper_trail.rb index 640ca609..f9cb22ac 100644 --- a/lib/paper_trail/has_paper_trail.rb +++ b/lib/paper_trail/has_paper_trail.rb @@ -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. diff --git a/test/unit/model_test.rb b/test/unit/model_test.rb index 70f42c52..706c0ba6 100644 --- a/test/unit/model_test.rb +++ b/test/unit/model_test.rb @@ -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