[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. 1853ed3ea733da657bbe01fae58f9937cbf76b95

Shawn Moore sartak at bestpractical.com
Wed Feb 9 20:58:38 EST 2011


The branch, master has been updated
       via  1853ed3ea733da657bbe01fae58f9937cbf76b95 (commit)
      from  566d8f4d0c4acf154b00d682b44b933c90a7cb6a (commit)

Summary of changes:
 .../RecordHistory/Mixin/Model/RecordHistory.pm     |   15 +++++++++++++++
 t/TestApp-Plugin-RecordHistory/t/001-basic.t       |   11 ++++++++++-
 2 files changed, 25 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit 1853ed3ea733da657bbe01fae58f9937cbf76b95
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 20:58:26 2011 -0500

    Delete changes and changefields when we delete a record

diff --git a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
index 41e8d92..54319c2 100644
--- a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
@@ -47,6 +47,21 @@ sub import {
             new_value => $args{value},
         );
     });
+
+    # we hook into before_delete so we can still access changes etc
+    $caller->add_trigger(before_delete => sub {
+        my $self = shift;
+
+        my $changes = $self->changes;
+        while (my $change = $changes->next) {
+            my $change_fields = $change->change_fields;
+            while (my $change_field = $change_fields->next) {
+                $change_field->delete;
+            }
+
+            $change->delete;
+        }
+    });
 }
 
 sub changes {
diff --git a/t/TestApp-Plugin-RecordHistory/t/001-basic.t b/t/TestApp-Plugin-RecordHistory/t/001-basic.t
index 6437590..ece28ed 100644
--- a/t/TestApp-Plugin-RecordHistory/t/001-basic.t
+++ b/t/TestApp-Plugin-RecordHistory/t/001-basic.t
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 18;
+use Jifty::Test::Dist tests => 20;
 
 my $book = TestApp::Plugin::RecordHistory::Model::Book->new;
 $book->create(
@@ -40,3 +40,12 @@ TODO: {
     is($change_field->old_value, '1984');
 }
 
+$book->delete;
+
+my $changes = Jifty::Plugin::RecordHistory::Model::ChangeCollection->new;
+$changes->unlimit;
+is($changes->count, 0, 'no more changes since we deleted the record');
+
+my $change_fields = Jifty::Plugin::RecordHistory::Model::ChangeFieldCollection->new;
+$change_fields->unlimit;
+is($change_fields->count, 0, 'no more change fields since we deleted the record');

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list