X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi%2F12-filter.t;h=109c876c93038540f3a72a0f5d7a1651da96543b;hb=6c925c721b4fefc6f8e3b3c2ad82c7f3efa268a3;hp=e82b5799fbe5f1ba00b624d6a65d5d71a2ab4472;hpb=50891152d0b24649bfd67bdba97feec86b11c064;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi/12-filter.t b/t/cdbi/12-filter.t index e82b579..109c876 100644 --- a/t/cdbi/12-filter.t +++ b/t/cdbi/12-filter.t @@ -7,8 +7,7 @@ BEGIN { plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); next; } - eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 50); + plan tests => 50; } use lib 't/cdbi/testlib'; @@ -22,76 +21,76 @@ my $film = Film->create({ Title => 'MY Film' }); my $film2 = Film->create({ Title => 'Another Film' }); my @act = ( - Actor->create( - { - name => 'Actor 1', - film => $film, - salary => 10, - } - ), - Actor->create( - { - name => 'Actor 2', - film => $film, - salary => 20, - } - ), - Actor->create( - { - name => 'Actor 3', - film => $film, - salary => 30, - } - ), - Actor->create( - { - name => 'Actor 4', - film => $film2, - salary => 50, - } - ), + Actor->create( + { + name => 'Actor 1', + film => $film, + salary => 10, + } + ), + Actor->create( + { + name => 'Actor 2', + film => $film, + salary => 20, + } + ), + Actor->create( + { + name => 'Actor 3', + film => $film, + salary => 30, + } + ), + Actor->create( + { + name => 'Actor 4', + film => $film2, + salary => 50, + } + ), ); eval { - my @actors = $film->actors(name => 'Actor 1'); - is @actors, 1, "Got one actor from restricted has_many"; - is $actors[0]->name, "Actor 1", "Correct name"; + my @actors = $film->actors(name => 'Actor 1'); + is @actors, 1, "Got one actor from restricted has_many"; + is $actors[0]->name, "Actor 1", "Correct name"; }; is $@, '', "No errors"; { - my @actors = Actor->double_search("Actor 1", 10); - is @actors, 1, "Got one actor"; - is $actors[0]->name, "Actor 1", "Correct name"; + my @actors = Actor->double_search("Actor 1", 10); + is @actors, 1, "Got one actor"; + is $actors[0]->name, "Actor 1", "Correct name"; } { - ok my @actors = Actor->salary_between(0, 100), "Range 0 - 100"; - is @actors, 4, "Got all"; + ok my @actors = Actor->salary_between(0, 100), "Range 0 - 100"; + is @actors, 4, "Got all"; } { - my @actors = Actor->salary_between(100, 200); - is @actors, 0, "None in Range 100 - 200"; + my @actors = Actor->salary_between(100, 200); + is @actors, 0, "None in Range 100 - 200"; } { - ok my @actors = Actor->salary_between(0, 10), "Range 0 - 10"; - is @actors, 1, "Got 1"; - is $actors[0]->name, $act[0]->name, "Actor 1"; + ok my @actors = Actor->salary_between(0, 10), "Range 0 - 10"; + is @actors, 1, "Got 1"; + is $actors[0]->name, $act[0]->name, "Actor 1"; } { - ok my @actors = Actor->salary_between(20, 30), "Range 20 - 20"; - @actors = sort { $a->salary <=> $b->salary } @actors; - is @actors, 2, "Got 2"; - is $actors[0]->name, $act[1]->name, "Actor 2"; - is $actors[1]->name, $act[2]->name, "and Actor 3"; + ok my @actors = Actor->salary_between(20, 30), "Range 20 - 20"; + @actors = sort { $a->salary <=> $b->salary } @actors; + is @actors, 2, "Got 2"; + is $actors[0]->name, $act[1]->name, "Actor 2"; + is $actors[1]->name, $act[2]->name, "and Actor 3"; } { - ok my @actors = Actor->search(Film => $film), "Search by object"; - is @actors, 3, "3 actors in film 1"; + ok my @actors = Actor->search(Film => $film), "Search by object"; + is @actors, 3, "3 actors in film 1"; } #---------------------------------------------------------------------- @@ -101,55 +100,51 @@ is $@, '', "No errors"; my $it_class = 'DBIx::Class::ResultSet'; sub test_normal_iterator { - my $it = $film->actors; - isa_ok $it, $it_class; - is $it->count, 3, " - with 3 elements"; - my $i = 0; - while (my $film = $it->next) { - is $film->name, $act[ $i++ ]->name, "Get $i"; - } - ok !$it->next, "No more"; - is $it->first->name, $act[0]->name, "Get first"; + my $it = $film->actors; + isa_ok $it, $it_class; + is $it->count, 3, " - with 3 elements"; + my $i = 0; + while (my $film = $it->next) { + is $film->name, $act[ $i++ ]->name, "Get $i"; + } + ok !$it->next, "No more"; + is $it->first->name, $act[0]->name, "Get first"; } test_normal_iterator; { - Film->has_many(actor_ids => [ Actor => 'id' ]); - my $it = $film->actor_ids; - isa_ok $it, $it_class; - is $it->count, 3, " - with 3 elements"; - my $i = 0; - while (my $film_id = $it->next) { - is $film_id, $act[ $i++ ]->id, "Get id $i"; - } - ok !$it->next, "No more"; - is $it->first, $act[0]->id, "Get first"; + Film->has_many(actor_ids => [ Actor => 'id' ]); + my $it = $film->actor_ids; + isa_ok $it, $it_class; + is $it->count, 3, " - with 3 elements"; + my $i = 0; + while (my $film_id = $it->next) { + is $film_id, $act[ $i++ ]->id, "Get id $i"; + } + ok !$it->next, "No more"; + is $it->first, $act[0]->id, "Get first"; } # make sure nothing gets clobbered; test_normal_iterator; -SKIP: { - #skip "dbic iterators don't support slice yet", 12; - - { - my @acts = $film->actors->slice(1, 2); - is @acts, 2, "Slice gives 2 actor"; - is $acts[0]->name, "Actor 2", "Actor 2"; - is $acts[1]->name, "Actor 3", "and actor 3"; + my @acts = $film->actors->slice(1, 2); + is @acts, 2, "Slice gives 2 actor"; + is $acts[0]->name, "Actor 2", "Actor 2"; + is $acts[1]->name, "Actor 3", "and actor 3"; } { - my @acts = $film->actors->slice(1); - is @acts, 1, "Slice of 1 actor"; - is $acts[0]->name, "Actor 2", "Actor 2"; + my @acts = $film->actors->slice(1); + is @acts, 1, "Slice of 1 actor"; + is $acts[0]->name, "Actor 2", "Actor 2"; } { - my @acts = $film->actors->slice(2, 8); - is @acts, 1, "Slice off the end"; - is $acts[0]->name, "Actor 3", "Gets last actor only"; + my @acts = $film->actors->slice(2, 8); + is @acts, 1, "Slice off the end"; + is $acts[0]->name, "Actor 3", "Gets last actor only"; } package Class::DBI::My::Iterator; @@ -167,15 +162,13 @@ Actor->iterator_class('Class::DBI::My::Iterator'); delete $film->{related_resultsets}; { - my @acts = $film->actors->slice(1, 2); - is @acts, 2, "Slice gives 2 results"; - ok eq_set(\@acts, [qw/fred barney/]), "Fred and Barney"; + my @acts = $film->actors->slice(1, 2); + is @acts, 2, "Slice gives 2 results"; + ok eq_set(\@acts, [qw/fred barney/]), "Fred and Barney"; - ok $film->actors->delete_all, "Can delete via iterator"; - is $film->actors, 0, "no actors left"; + ok $film->actors->delete_all, "Can delete via iterator"; + is $film->actors, 0, "no actors left"; - eval { $film->actors->delete_all }; - is $@, '', "Deleting again does no harm"; + eval { $film->actors->delete_all }; + is $@, '', "Deleting again does no harm"; } - -} # end SKIP block