[Bast-commits] r4798 - in DBIx-Class-DynamicDefault/1.000/trunk/t:
. lib/TestSchema
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Wed Sep 10 22:11:06 BST 2008
Author: rafl
Date: 2008-09-10 22:11:05 +0100 (Wed, 10 Sep 2008)
New Revision: 4798
Added:
DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Affe.pm
Modified:
DBIx-Class-DynamicDefault/1.000/trunk/t/basic.t
DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Table.pm
Log:
Tests for always_update.
Modified: DBIx-Class-DynamicDefault/1.000/trunk/t/basic.t
===================================================================
--- DBIx-Class-DynamicDefault/1.000/trunk/t/basic.t 2008-09-10 21:10:57 UTC (rev 4797)
+++ DBIx-Class-DynamicDefault/1.000/trunk/t/basic.t 2008-09-10 21:11:05 UTC (rev 4798)
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More tests => 14;
use DBICx::TestDatabase;
BEGIN { use_ok('DBIx::Class::DynamicDefault') }
@@ -10,24 +10,38 @@
my $schema = DBICx::TestDatabase->new('TestSchema');
my $rs = $schema->resultset('Table');
+my $rs2 = $schema->resultset('Affe');
-my $row = $rs->create({});
+my $row = $rs->create({ fred => 'affe' });
is($row->quux, 1, 'default on create with methodname');
is($row->garply, undef, 'no default on create');
is($row->corge, 'create', 'default on create with coderef');
-$row->update;
+$row->update({ fred => 'moo' });
is($row->quux, 1, 'no default on update');
is($row->garply, $$, 'default on update with coderef');
-is($row->corge, 'update', 'default on update with methodname');
+is($row->corge, 'update2', 'default on update with methodname');
$row->garply(-42);
$row->update;
is($row->garply, -42, 'defaults don\'t get set when a value is specified explicitly on update');
-$row = $rs->create({ quux => -23 });
+$row->update;
+is($row->corge, 'update3', 'no default on update without changes');
+$row = $rs->create({ quux => -23, fred => 'zomtec' });
+
is($row->quux, -23, 'defaults don\'t get set when a value is specified explicitly on create');
+
+$row = $rs2->create({ moo => 0, kooh => '123' });
+
+is($row->moo, 0, 'no default on create');
+is($row->kooh, '123', 'no default on create');
+
+$row->update;
+
+is($row->moo, 1, 'default on update without changes and always_update');
+is($row->kooh, 'zomtec', 'on update default without always_update if another col is changed due to always_update');
Added: DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Affe.pm
===================================================================
--- DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Affe.pm (rev 0)
+++ DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Affe.pm 2008-09-10 21:11:05 UTC (rev 4798)
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+
+package TestSchema::Affe;
+
+use parent qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/DynamicDefault Core/);
+__PACKAGE__->table('affe');
+
+__PACKAGE__->add_columns(
+ moo => {
+ data_type => 'integer',
+ dynamic_default_on_update => 'moo_default',
+ always_update => 1,
+ },
+ kooh => {
+ data_type => 'text',
+ dynamic_default_on_update => 'kooh_default',
+ },
+);
+
+__PACKAGE__->set_primary_key(qw/moo/);
+
+{
+ my $i = 0;
+
+ sub moo_default {
+ return ++$i;
+ }
+}
+
+sub kooh_default {
+ return 'zomtec';
+}
+
+1;
Modified: DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Table.pm
===================================================================
--- DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Table.pm 2008-09-10 21:10:57 UTC (rev 4797)
+++ DBIx-Class-DynamicDefault/1.000/trunk/t/lib/TestSchema/Table.pm 2008-09-10 21:11:05 UTC (rev 4798)
@@ -24,6 +24,7 @@
dynamic_default_on_create => \&corge_default,
dynamic_default_on_update => 'corge_default',
},
+ fred => { data_type => 'text' },
);
__PACKAGE__->set_primary_key(qw/quux/);
@@ -34,13 +35,13 @@
sub quux_default {
return ++$i;
}
-}
-sub corge_default {
- my ($self) = @_;
+ sub corge_default {
+ my ($self) = @_;
- return 'update' if $self->in_storage;
- return 'create';
+ return 'update' . ++$i if $self->in_storage;
+ return 'create';
+ }
}
1;
More information about the Bast-commits
mailing list