From: Peter Rabbitson Date: Sun, 16 Nov 2008 22:16:31 +0000 (+0000) Subject: Add new test relationship - a track can have a relates single_cd X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a1cb5921a914f087163914b010ca0c4e72a57dcc;p=dbsrgits%2FDBIx-Class-Historic.git Add new test relationship - a track can have a relates single_cd --- diff --git a/t/50fork.t b/t/50fork.t index 381872d..df6957c 100644 --- a/t/50fork.t +++ b/t/50fork.t @@ -34,7 +34,7 @@ eval { { local $SIG{__WARN__} = sub {}; eval { $dbh->do("DROP TABLE cd") }; - $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);"); + $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);"); } $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 }); diff --git a/t/51threads.t b/t/51threads.t index 45e6247..a7a3a78 100644 --- a/t/51threads.t +++ b/t/51threads.t @@ -44,7 +44,7 @@ eval { { local $SIG{__WARN__} = sub {}; eval { $dbh->do("DROP TABLE cd") }; - $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);"); + $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);"); } $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 }); diff --git a/t/51threadtxn.t b/t/51threadtxn.t index 7af0ff8..3cc6779 100644 --- a/t/51threadtxn.t +++ b/t/51threadtxn.t @@ -44,7 +44,7 @@ eval { { local $SIG{__WARN__} = sub {}; eval { $dbh->do("DROP TABLE cd") }; - $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER);"); + $dbh->do("CREATE TABLE cd (cdid serial PRIMARY KEY, artist INTEGER NOT NULL UNIQUE, title VARCHAR(100) NOT NULL UNIQUE, year VARCHAR(100) NOT NULL, genreid INTEGER, single_track INTEGER);"); } $schema->resultset('CD')->create({ title => 'vacation in antarctica', artist => 123, year => 1901 }); diff --git a/t/60core.t b/t/60core.t index 808b6b4..a46be69 100644 --- a/t/60core.t +++ b/t/60core.t @@ -153,7 +153,7 @@ is($schema->resultset("Artist")->count, 4, 'count ok'); my $cd = $schema->resultset("CD")->find(1); my %cols = $cd->get_columns; -cmp_ok(keys %cols, '==', 5, 'get_columns number of columns ok'); +cmp_ok(keys %cols, '==', 6, 'get_columns number of columns ok'); is($cols{title}, 'Spoonful of bees', 'get_columns values ok'); @@ -169,7 +169,7 @@ $cd->discard_changes; # check whether ResultSource->columns returns columns in order originally supplied my @cd = $schema->source("CD")->columns; -is_deeply( \@cd, [qw/cdid artist title year genreid/], 'column order'); +is_deeply( \@cd, [qw/cdid artist title year genreid single_track/], 'column order'); $cd = $schema->resultset("CD")->search({ title => 'Spoonful of bees' }, { columns => ['title'] })->next; is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly'); @@ -335,9 +335,9 @@ ok(!$@, "stringify to false value doesn't cause error"); # test remove_columns { - is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid/]); + is_deeply([$schema->source('CD')->columns], [qw/cdid artist title year genreid single_track/]); $schema->source('CD')->remove_columns('year'); - is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid/]); + is_deeply([$schema->source('CD')->columns], [qw/cdid artist title genreid single_track/]); ok(! exists $schema->source('CD')->_columns->{'year'}, 'year still exists in _columns'); } diff --git a/t/74mssql.t b/t/74mssql.t index c5b4bb9..238f27a 100644 --- a/t/74mssql.t +++ b/t/74mssql.t @@ -30,7 +30,7 @@ $dbh->do("IF OBJECT_ID('cd', 'U') IS NOT NULL DROP TABLE cd"); $dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(100), rank INT DEFAULT '13', charfield CHAR(10) NULL);"); -$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL);"); +$dbh->do("CREATE TABLE cd (cdid INT IDENTITY PRIMARY KEY, artist INT, title VARCHAR(100), year VARCHAR(100), genreid INT NULL, single_track INT NULL);"); # Just to test compat shim, Auto is in Core $schema->class('Artist')->load_components('PK::Auto::MSSQL'); diff --git a/t/91debug.t b/t/91debug.t index ae059e4..e53a1d5 100644 --- a/t/91debug.t +++ b/t/91debug.t @@ -55,7 +55,7 @@ open(STDERR, '>&STDERRCOPY'); my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } ); like( $sql, - qr/\QSELECT me.cdid, me.artist, me.title, me.year, me.genreid FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/, + qr/\QSELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND cdid BETWEEN ? AND ? ): '1', '1', '3'\E/, 'got correct SQL with all bind parameters' ); } diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index 41ed6bd..68337bb 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -23,6 +23,11 @@ __PACKAGE__->add_columns( 'genreid' => { data_type => 'integer', is_nullable => 1, + }, + 'single_track' => { + data_type => 'integer', + is_nullable => 1, + is_foreign_key => 1, } ); __PACKAGE__->set_primary_key('cdid'); @@ -32,6 +37,9 @@ __PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', undef, { is_deferrable => 1, }); +# in case this is a single-cd it promotes a track from another cd +__PACKAGE__->belongs_to( single_track => 'DBICTest::Schema::Track' ); + __PACKAGE__->has_many( tracks => 'DBICTest::Schema::Track' ); __PACKAGE__->has_many( tags => 'DBICTest::Schema::Tag', undef, diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index 64eb0ee..353cbea 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -35,4 +35,6 @@ __PACKAGE__->add_unique_constraint([ qw/cd title/ ]); __PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD' ); __PACKAGE__->belongs_to( disc => 'DBICTest::Schema::CD' => 'cd'); +__PACKAGE__->might_have( cd_single => 'DBICTest::Schema::CD', 'single_track' ); + 1; diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index 1db9557..b3f0f0f 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -1,6 +1,6 @@ -- -- Created by SQL::Translator::Producer::SQLite --- Created on Mon Nov 10 23:52:55 2008 +-- Created on Sun Nov 16 10:43:11 2008 -- BEGIN TRANSACTION; @@ -58,11 +58,13 @@ CREATE TABLE cd ( artist integer NOT NULL, title varchar(100) NOT NULL, year varchar(100) NOT NULL, - genreid integer + genreid integer, + single_track integer ); CREATE INDEX cd_idx_artist_cd ON cd (artist); CREATE INDEX cd_idx_genreid_cd ON cd (genreid); +CREATE INDEX cd_idx_single_track_cd ON cd (single_track); CREATE UNIQUE INDEX cd_artist_title_cd ON cd (artist, title); --