[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. 65f7c6f0c1394edd4732e69247eac67f93817118

Shawn Moore sartak at bestpractical.com
Wed Feb 9 17:44:33 EST 2011


The branch, master has been updated
       via  65f7c6f0c1394edd4732e69247eac67f93817118 (commit)
      from  c5c4eb05fc26cdfeca3b04d446b8b74fef73d92f (commit)

Summary of changes:
 .../RecordHistory/Mixin/Model/RecordHistory.pm     |    2 +
 t/TestApp-Plugin-RecordHistory/t/002-error.t       |   23 ++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100644 t/TestApp-Plugin-RecordHistory/t/002-error.t

- Log -----------------------------------------------------------------
commit 65f7c6f0c1394edd4732e69247eac67f93817118
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 17:44:19 2011 -0500

    Don't create Change records on create fail, and test for that

diff --git a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
index 201ea3f..8e422dc 100644
--- a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
@@ -15,6 +15,8 @@ sub import {
         my $self = shift;
         my $id   = ${ shift @_ };
 
+        return if !$id; # the actual create failed
+
         my $change = Jifty::Plugin::RecordHistory::Model::Change->new;
         $change->create(
             record_class => ref($self),
diff --git a/t/TestApp-Plugin-RecordHistory/t/002-error.t b/t/TestApp-Plugin-RecordHistory/t/002-error.t
new file mode 100644
index 0000000..588ae6e
--- /dev/null
+++ b/t/TestApp-Plugin-RecordHistory/t/002-error.t
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 4;
+
+sub TestApp::Plugin::RecordHistory::Model::Book::__create {
+    return 0;
+}
+
+my $book = TestApp::Plugin::RecordHistory::Model::Book->new;
+$book->create(
+    title => '1984',
+);
+ok(!$book->id, 'did not create a book');
+
+isa_ok($book->changes, 'Jifty::Plugin::RecordHistory::Model::ChangeCollection');
+is($book->changes->count, 0, 'no changes');
+
+my $all_changes = Jifty::Plugin::RecordHistory::Model::ChangeCollection->new;
+$all_changes->unlimit;
+is($all_changes->count, 0, 'no changes at all');
+

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



More information about the Bps-public-commit mailing list