X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi%2F09-has_many.t;h=a19500ab385bf6a0f943c6d1aae16302903bec33;hb=5c505cafa292b25dbbfb0df53ac30e73069834a2;hp=0c1c8453cf61b51cadca33ba98f42f52c00a0da7;hpb=50891152d0b24649bfd67bdba97feec86b11c064;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi/09-has_many.t b/t/cdbi/09-has_many.t index 0c1c845..a19500a 100644 --- a/t/cdbi/09-has_many.t +++ b/t/cdbi/09-has_many.t @@ -1,14 +1,9 @@ -use strict; -use Test::More; +use DBIx::Class::Optional::Dependencies -skip_all_without => 'cdbicompat'; +use strict; +use warnings; -BEGIN { - eval "use DBIx::Class::CDBICompat;"; - plan skip_all => 'Class::Trigger and DBIx::ContextualFetch required' if $@; - eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 31); -} - +use Test::More; use lib 't/cdbi/testlib'; use Film; @@ -25,14 +20,14 @@ Film->create_test_film; ok(my $btaste = Film->retrieve('Bad Taste'), "We have Bad Taste"); ok( - my $pvj = Actor->create( - { - Name => 'Peter Vere-Jones', - Film => undef, - Salary => '30_000', # For a voice! - } - ), - 'create Actor' + my $pvj = Actor->create( + { + Name => 'Peter Vere-Jones', + Film => undef, + Salary => '30_000', # For a voice! + } + ), + 'create Actor' ); is $pvj->Name, "Peter Vere-Jones", "PVJ name ok"; is $pvj->Film, undef, "No film"; @@ -40,54 +35,54 @@ ok $pvj->set_Film($btaste), "Set film"; $pvj->update; is $pvj->Film->id, $btaste->id, "Now film"; { - my @actors = $btaste->actors; - is(@actors, 1, "Bad taste has one actor"); - is($actors[0]->Name, $pvj->Name, " - the correct one"); + my @actors = $btaste->actors; + is(@actors, 1, "Bad taste has one actor"); + is($actors[0]->Name, $pvj->Name, " - the correct one"); } my %pj_data = ( - Name => 'Peter Jackson', - Salary => '0', # it's a labour of love + Name => 'Peter Jackson', + Salary => '0', # it's a labour of love ); eval { my $pj = Film->add_to_actors(\%pj_data) }; like $@, qr/class/, "add_to_actors must be object method"; eval { my $pj = $btaste->add_to_actors(%pj_data) }; -like $@, qr/needs/, "add_to_actors takes hash"; +like $@, qr/Result object instantiation requires a hashref as argument/, "add_to_actors takes hash"; ok( - my $pj = $btaste->add_to_actors( - { - Name => 'Peter Jackson', - Salary => '0', # it's a labour of love - } - ), - 'add_to_actors' + my $pj = $btaste->add_to_actors( + { + Name => 'Peter Jackson', + Salary => '0', # it's a labour of love + } + ), + 'add_to_actors' ); is $pj->Name, "Peter Jackson", "PJ ok"; is $pvj->Name, "Peter Vere-Jones", "PVJ still ok"; { - my @actors = $btaste->actors; - is @actors, 2, " - so now we have 2"; - is $actors[0]->Name, $pj->Name, "PJ first"; - is $actors[1]->Name, $pvj->Name, "PVJ first"; + my @actors = $btaste->actors; + is @actors, 2, " - so now we have 2"; + is $actors[0]->Name, $pj->Name, "PJ first"; + is $actors[1]->Name, $pvj->Name, "PVJ first"; } eval { - my @actors = $btaste->actors(Name => $pj->Name); - is @actors, 1, "One actor from restricted (sorted) has_many"; - is $actors[0]->Name, $pj->Name, "It's PJ"; + my @actors = $btaste->actors(Name => $pj->Name); + is @actors, 1, "One actor from restricted (sorted) has_many"; + is $actors[0]->Name, $pj->Name, "It's PJ"; }; is $@, '', "No errors"; my $as = Actor->create( - { - Name => 'Arnold Schwarzenegger', - Film => 'Terminator 2', - Salary => '15_000_000' - } + { + Name => 'Arnold Schwarzenegger', + Film => 'Terminator 2', + Salary => '15_000_000' + } ); eval { $btaste->actors($pj, $pvj, $as) }; @@ -125,3 +120,5 @@ is($as->Name, 'Arnold Schwarzenegger', "Arnie's still Arnie"); is_deeply [sort map { $_->id } $other_thing->things], [1,2]; } + +done_testing;