-- added support for belongs_to type relationships and better support for when the...
[dbsrgits/DBIx-Class.git] / t / 101populate_rs.t
index 7d25d78..c1f497f 100644 (file)
@@ -5,12 +5,12 @@ use Test::More;
 use lib qw(t/lib);
 use DBICTest;
 
-plan tests => 40;
+plan tests => 53;
 
 my $schema = DBICTest->init_schema();
 my $rs = $schema->resultset('Artist');
 
-RETURN_RESULTSETS: {
+RETURN_RESULTSETS_HAS_MANY: {
 
        my ($crap, $girl, $damn, $xxxaaa) = $rs->populate( [
          { artistid => 4, name => 'Manufactured Crap', cds => [ 
@@ -47,7 +47,7 @@ RETURN_RESULTSETS: {
        ok( $girl->cds->count == 3, "got Expected Number of Cds");
 }
 
-RETURN_VOID: {
+RETURN_VOID_HAS_MANY: {
 
        $rs->populate( [
          { artistid => 8, name => 'Manufactured CrapB', cds => [ 
@@ -63,7 +63,7 @@ RETURN_VOID: {
                ]
          },
          { artistid =>10,  name => 'XXXX' },
-         { artistid =>11, name => 'wart', cds =>{ title => 'xxxaaa' ,year => 2005 }, },
+         { artistid =>11, name => 'wart', cds =>[{ title => 'xxxaaa' ,year => 2005 }], },
        ] );
        
        my $artist = $rs->find(8);
@@ -148,3 +148,76 @@ RETURN_RESULTSETS_AUTOPK: {
        ok( $girl->cds->count == 3, "got Expected Number of Cds");
 }
 
+RETURN_RESULTSETS_BELONGS_TO: {
+
+       ## Test from a belongs_to perspective, should create artist first, then CD with artistid in:
+       
+       my $cds = [
+               {
+                       title => 'Some CD1',
+                       year => '1997',
+                       artist => { name => 'Fred BloggsA'},
+               },
+               {
+                       title => 'Some CD2',
+                       year => '1997',
+                       artist => { name => 'Fred BloggsB'},
+               },              
+       ];
+       
+       my $cd_rs = $schema->resultset('CD');
+       
+       my @ret = $cd_rs->populate($cds);
+       
+       my $cdA = $schema->resultset('CD')->find({title => 'Some CD1'});
+
+       isa_ok($cdA, 'DBICTest::CD', 'Created CD');
+       isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist');
+       is($cdA->artist->name, 'Fred BloggsA', 'Set Artist to FredA');
+
+       my $cdB = $schema->resultset('CD')->find({title => 'Some CD2'});
+       
+       isa_ok($cdB, 'DBICTest::CD', 'Created CD');
+       isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist');
+       is($cdB->artist->name, 'Fred BloggsB', 'Set Artist to FredB');
+}
+
+RETURN_VOID_BELONGS_TO: {
+
+       ## Test from a belongs_to perspective, should create artist first, then CD with artistid in:
+       
+       my $cds = [
+               {
+                       title => 'Some CD3',
+                       year => '1997',
+                       artist => { name => 'Fred BloggsC'},
+               },
+               {
+                       title => 'Some CD4',
+                       year => '1997',
+                       artist => { name => 'Fred BloggsD'},
+               },              
+       ];
+       
+       my $cd_rs = $schema->resultset('CD');
+       
+       ok( $cd_rs, 'Got Good CD Resultset');
+       
+       $cd_rs->populate($cds);
+       
+       my $cdA = $schema->resultset('CD')->find({title => 'Some CD3'});
+
+       isa_ok($cdA, 'DBICTest::CD', 'Created CD');
+       isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist');
+       is($cdA->artist->name, 'Fred BloggsC', 'Set Artist to FredC');
+
+       my $cdB = $schema->resultset('CD')->find({title => 'Some CD4'});
+       
+       isa_ok($cdB, 'DBICTest::CD', 'Created CD');
+       isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist');
+       is($cdB->artist->name, 'Fred BloggsD', 'Set Artist to FredD');
+}
+
+
+
+