[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. 0.03-3-gb4025a2

Shawn Moore sartak at bestpractical.com
Fri Feb 18 16:50:45 EST 2011


The branch, master has been updated
       via  b4025a281f9eb30713e18ecc87c8de651c1e11f9 (commit)
      from  8252a58ced1ea2e2165c481bd1ee30d06b9ea4d1 (commit)

Summary of changes:
 .../Plugin/RecordHistory/Model/{Book.pm => CD.pm}  |    8 ++-
 .../t/006-no-cascaded-delete.t                     |   57 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 3 deletions(-)
 copy t/TestApp-Plugin-RecordHistory/lib/TestApp/Plugin/RecordHistory/Model/{Book.pm => CD.pm} (53%)
 create mode 100644 t/TestApp-Plugin-RecordHistory/t/006-no-cascaded-delete.t

- Log -----------------------------------------------------------------
commit b4025a281f9eb30713e18ecc87c8de651c1e11f9
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Feb 18 16:49:45 2011 -0500

    Test for cascaded_delete => 0

diff --git a/t/TestApp-Plugin-RecordHistory/lib/TestApp/Plugin/RecordHistory/Model/CD.pm b/t/TestApp-Plugin-RecordHistory/lib/TestApp/Plugin/RecordHistory/Model/CD.pm
new file mode 100644
index 0000000..70889fd
--- /dev/null
+++ b/t/TestApp-Plugin-RecordHistory/lib/TestApp/Plugin/RecordHistory/Model/CD.pm
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+
+package TestApp::Plugin::RecordHistory::Model::CD;
+use Jifty::DBI::Schema;
+
+use TestApp::Plugin::RecordHistory::Record schema {
+    column title =>
+        type is 'varchar';
+    column artist =>
+        type is 'varchar';
+};
+
+use Jifty::Plugin::RecordHistory::Mixin::Model::RecordHistory (
+    cascaded_delete => 0,
+);
+
+1;
+
diff --git a/t/TestApp-Plugin-RecordHistory/t/006-no-cascaded-delete.t b/t/TestApp-Plugin-RecordHistory/t/006-no-cascaded-delete.t
new file mode 100644
index 0000000..378b581
--- /dev/null
+++ b/t/TestApp-Plugin-RecordHistory/t/006-no-cascaded-delete.t
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+use Jifty::Test::Dist tests => 27;
+
+my $cd = TestApp::Plugin::RecordHistory::Model::CD->new;
+$cd->create(
+    title => 'The King of Limbs',
+);
+ok($cd->id, 'created a cd');
+
+isa_ok($cd->changes, 'Jifty::Plugin::RecordHistory::Model::ChangeCollection');
+is($cd->changes->count, 1, 'one change');
+my $change = $cd->changes->first;
+is($change->record_id, $cd->id, 'record id');
+is($change->record_class, 'TestApp::Plugin::RecordHistory::Model::CD', 'record class');
+is($change->type, 'create', 'change has type create');
+is($change->record->title, 'The King of Limbs', 'change->record');
+
+isa_ok($change->change_fields, 'Jifty::Plugin::RecordHistory::Model::ChangeFieldCollection', 'change field collection');
+is($change->change_fields->count, 0, 'generate no ChangeFields for create');
+
+$cd->set_title('OK Computer');
+
+isa_ok($cd->changes, 'Jifty::Plugin::RecordHistory::Model::ChangeCollection');
+is($cd->changes->count, 2, 'two changes');
+is($cd->changes->first->type, 'create', 'first change is the create');
+$change = $cd->changes->last;
+is($change->type, 'update', 'second change is the update');
+is($change->change_fields->count, 1, 'one field updated');
+
+my $change_field = $change->change_fields->first;
+is($change_field->change->id, $change->id, 'associated with the right change');
+is($change_field->field, 'title');
+is($change_field->new_value, 'OK Computer');
+is($change_field->old_value, 'The King of Limbs');
+
+$cd->delete;
+
+my $changes = Jifty::Plugin::RecordHistory::Model::ChangeCollection->new;
+$changes->unlimit;
+is($changes->count, 2, 'two changes');
+is($changes->first->type, 'create', 'first change is the create');
+$change = $changes->last;
+is($change->type, 'update', 'second change is the update');
+is($change->change_fields->count, 1, 'one field updated');
+
+my $change_fields = Jifty::Plugin::RecordHistory::Model::ChangeFieldCollection->new;
+$change_fields->unlimit;
+is($change_fields->count, 1);
+$change_field = $change->change_fields->first;
+is($change_field->change->id, $change->id, 'associated with the right change');
+is($change_field->field, 'title');
+is($change_field->new_value, 'OK Computer');
+is($change_field->old_value, 'The King of Limbs');
+

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



More information about the Bps-public-commit mailing list