[Bast-commits] r5153 - in DBIx-Class/0.08/trunk/t: .
lib/DBICTest/Schema
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Mon Nov 17 01:00:28 GMT 2008
Author: ribasushi
Date: 2008-11-17 01:00:28 +0000 (Mon, 17 Nov 2008)
New Revision: 5153
Modified:
DBIx-Class/0.08/trunk/t/96multi_create.t
DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Producer.pm
Log:
One more (passing) multicreate test and a bit of cleanup
Modified: DBIx-Class/0.08/trunk/t/96multi_create.t
===================================================================
--- DBIx-Class/0.08/trunk/t/96multi_create.t 2008-11-17 00:33:51 UTC (rev 5152)
+++ DBIx-Class/0.08/trunk/t/96multi_create.t 2008-11-17 01:00:28 UTC (rev 5153)
@@ -6,7 +6,7 @@
use lib qw(t/lib);
use DBICTest;
-plan tests => 69;
+plan tests => 72;
my $schema = DBICTest->init_schema();
@@ -26,7 +26,7 @@
};
diag $@ if $@;
-# same as above but the child and parent have no values,
+# same as above but the child and parent have no values,
# except for an explicit parent pk
eval {
my $bm_rs = $schema->resultset('Bookmark');
@@ -51,25 +51,19 @@
# create over > 1 levels of has_many create (A => { has_many => { B => has_many => C } } )
eval {
- my $artist = $schema->resultset('Artist')->create(
- { name => 'Fred 2',
- cds => [
- { title => 'Music to code by',
- year => 2007,
- tags => [
- { 'tag' => 'rock' },
- ],
- },
- ],
- }
- );
+ my $artist = $schema->resultset('Artist')->first;
+ my $cd = $artist->create_related (cds => {
+ title => 'Music to code by',
+ year => 2007,
+ tags => [
+ { 'tag' => 'rock' },
+ ],
+ });
- isa_ok($artist, 'DBICTest::Artist', 'Created Artist');
- is($artist->name, 'Fred 2', 'Artist created correctly');
- is($artist->cds->count, 1, 'One CD created for artist');
- is($artist->cds->first->title, 'Music to code by', 'CD created correctly');
- is($artist->cds->first->tags->count, 1, 'One tag created for CD');
- is($artist->cds->first->tags->first->tag, 'rock', 'Tag created correctly');
+ isa_ok($cd, 'DBICTest::CD', 'Created CD');
+ is($cd->title, 'Music to code by', 'CD created correctly');
+ is($cd->tags->count, 1, 'One tag created for CD');
+ is($cd->tags->first->tag, 'rock', 'Tag created correctly');
};
diag $@ if $@;
@@ -89,6 +83,36 @@
'create via update of multi relationships throws an exception'
);
+# Create m2m while originating in the linker table
+eval {
+ my $artist = $schema->resultset('Artist')->first;
+ my $c2p = $schema->resultset('CD_to_Producer')->create ({
+ cd => {
+ artist => $artist,
+ title => 'Bad investment',
+ year => 2008,
+ tracks => [
+ { position => 1, title => 'Just buy' },
+ { position => 2, title => 'Why did we do it' },
+ { position => 3, title => 'Burn baby burn' },
+ ],
+ },
+ producer => {
+ name => 'Lehman Bros.',
+ },
+ });
+
+ isa_ok ($c2p, 'DBICTest::CD_to_Producer', 'Linker object created');
+ my $prod = $schema->resultset ('Producer')->find ({ name => 'Lehman Bros.' });
+ isa_ok ($prod, 'DBICTest::Producer', 'Producer row found');
+ is ($prod->cds->count, 1, 'Producer has one production');
+ my $cd = $prod->cds->first;
+ is ($cd->title, 'Bad investment', 'CD created correctly');
+ is ($cd->tracks->count, 3, 'CD has 3 tracks');
+
+};
+diag $@ if $@;
+
# create over > 1 levels of might_have (A => { might_have => { B => has_many => C } } )
eval {
my $artist = $schema->resultset('Artist')->first;
@@ -569,3 +593,5 @@
);
};
diag $@ if $@;
+
+1;
Modified: DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Producer.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Producer.pm 2008-11-17 00:33:51 UTC (rev 5152)
+++ DBIx-Class/0.08/trunk/t/lib/DBICTest/Schema/Producer.pm 2008-11-17 01:00:28 UTC (rev 5153)
@@ -20,5 +20,5 @@
__PACKAGE__->has_many(
producer_to_cd => 'DBICTest::Schema::CD_to_Producer' => 'producer'
);
-
+__PACKAGE__->many_to_many('cds', 'producer_to_cd', 'cd');
1;
More information about the Bast-commits
mailing list