[Bast-commits] r8595 - in DBIx-Class/0.08/branches: .
multi_update/t multi_update/t/multi_update
gshank at dev.catalyst.perl.org
gshank at dev.catalyst.perl.org
Wed Feb 10 00:46:43 GMT 2010
Author: gshank
Date: 2010-02-10 00:46:43 +0000 (Wed, 10 Feb 2010)
New Revision: 8595
Added:
DBIx-Class/0.08/branches/multi_update/
DBIx-Class/0.08/branches/multi_update/t/multi_update/
DBIx-Class/0.08/branches/multi_update/t/multi_update/cd_single.t
DBIx-Class/0.08/branches/multi_update/t/multi_update/has_many.t
Log:
start adding tests for multi update
Copied: DBIx-Class/0.08/branches/multi_update (from rev 8593, DBIx-Class/0.08/trunk)
Added: DBIx-Class/0.08/branches/multi_update/t/multi_update/cd_single.t
===================================================================
--- DBIx-Class/0.08/branches/multi_update/t/multi_update/cd_single.t (rev 0)
+++ DBIx-Class/0.08/branches/multi_update/t/multi_update/cd_single.t 2010-02-10 00:46:43 UTC (rev 8595)
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+my $cd = $schema->resultset('CD')->first;
+my $track = {
+ cd => $cd,
+ title => 'Multicreate rocks',
+ cd_single => {
+ artist => $cd->artist,
+ year => 2008,
+ title => 'Disemboweling MultiCreate',
+ },
+};
+
+my $cd = $schema->resultset('CD')->first;
+my $track = $schema->resultset('Track')->new_result($track);
+
+isa_ok( $track, 'DBICTest::Track', 'Main Track object created' );
+$track->insert;
+ok( 1, 'created track' );
+
+is( $track->title, 'Multicreate rocks', 'Correct Track title' );
+is( $track->cd_single->title, 'Disemboweling MultiCreate' );
+
+delete $track->{cd};
+$track->{cd_single}->{title} = 'Disemboweling MultiUpdate';
+$track->update($track);
+is( $track->cd_single->title, 'Disemboweling MultiUpdate', 'correct cd_single title' );
+
+done_testing;
Added: DBIx-Class/0.08/branches/multi_update/t/multi_update/has_many.t
===================================================================
--- DBIx-Class/0.08/branches/multi_update/t/multi_update/has_many.t (rev 0)
+++ DBIx-Class/0.08/branches/multi_update/t/multi_update/has_many.t 2010-02-10 00:46:43 UTC (rev 8595)
@@ -0,0 +1,56 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan tests => 2;
+
+my $schema = DBICTest->init_schema();
+
+my $track_no_lyrics = $schema->resultset ('Track')
+ ->search ({ 'lyrics.lyric_id' => undef }, { join => 'lyrics' })
+ ->first;
+
+my $lyric = $track_no_lyrics->create_related ('lyrics', {
+ lyric_versions => [
+ { text => 'english doubled' },
+ { text => 'english doubled' },
+ ],
+});
+is ($lyric->lyric_versions->count, 2, "Two identical has_many's created");
+
+# should the lyric_versions have pks? just replace them all?
+$track_no_lyrics->update( {
+ title => 'Titled Updated by Multi Update',
+ lyrics => {
+ lyric_versions => [
+ { text => 'Some new text' },
+ { text => 'Other text' },
+ ],
+ },
+});
+is( $track_no_lyrics->title, 'Title Updated by Multi Update', 'title updated' );
+is( $track_no_lyrics->lyrics->search_related('lyric_versions', { text => 'Other text' } )->count, 1, 'related record updated' );
+
+
+my $link = $schema->resultset ('Link')->create ({
+ url => 'lolcats!',
+ bookmarks => [
+ {},
+ {},
+ ]
+});
+is ($link->bookmarks->count, 2, "Two identical default-insert has_many's created");
+
+# what should happen?
+$link->update( {
+ url => 'lolkittens!',
+ bookmarks => [
+ {}
+ ]
+});
+is( $link->url, 'lolkittens!', 'url updated' );
+is( $link->bookmarks->count, 1, 'One default bookmark' );
More information about the Bast-commits
mailing list