From: Robert Sedlacek Date: Wed, 30 Sep 2015 03:06:42 +0000 (+0000) Subject: more tests X-Git-Tag: v0.000001~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bfd248ed899ccfb5838b4616e66767c5bd844826;p=dbsrgits%2FDBIx-Class-ParameterizedJoinHack.git more tests --- diff --git a/t/00basic.t b/t/00basic.t index 23fe945..fa997e3 100644 --- a/t/00basic.t +++ b/t/00basic.t @@ -2,6 +2,7 @@ use strict; use warnings; use lib 't/lib'; use Test::More; +use Test::Fatal; use My::Schema; my $schema = My::Schema->connect('dbi:SQLite:dbname=:memory:'); @@ -35,26 +36,27 @@ subtest 'has_many' => sub { ); }; -# my $join_with_range = sub { -# return shift->with_parameterized_join( -# tasks_in_urgency_range => { -# min => $_[0], -# max => $_[1], -# }, -# ); -# }; + my $join_with_range = sub { + return shift->with_parameterized_join( + tasks_in_urgency_range => { + min => $_[0], + max => $_[1], + }, + ); + }; - my $search = sub { + my $search_count = sub { return scalar shift->search( { 'me.name' => { -like => 'Bob%' } }, { '+select' => [{ - count => \['urgent_assigned_tasks.id'], + count => \[shift], }], '+as' => ['task_count'], }, ); }; + my $search = sub { $search_count->(shift, 'urgent_assigned_tasks.id') }; my $fetch_count = sub { return shift->next->get_column('task_count'); @@ -78,17 +80,42 @@ subtest 'has_many' => sub { subtest 'overrides' => sub { is $people - ->$join_with_min(190) ->$join_with_min(19) + ->$join_with_min(29) ->$search ->$fetch_count, - 2, 'overridden parameter'; + 1, 'overridden parameter'; }; -# subtest 'multi parameter' => sub { -# is $people->$join_with_range(10, 30)->$search->$fetch_count, -# 3, 'full range'; -# }; + subtest 'multi parameter' => sub { + my $search = sub { + $search_count->(shift, 'tasks_in_urgency_range.id'); + }; + is $people->$join_with_range(10, 30)->$search->$fetch_count, + 3, 'full range'; + }; + + subtest 'multi join' => sub { + is $people + ->$join_with_min(19) + ->$join_with_range(10, 30) + ->$search + ->$fetch_count, + 2*3, 'full count'; + }; + + subtest 'errors' => sub { + like exception { + $people->with_parameterized_join(urgent_assigned_tasks => {}) + ->$search + ->$fetch_count; + }, qr{urgent_assigned_tasks.+urgency_threshold}, 'missing parameter'; + like exception { + $people->with_parameterized_join(__invalid__ => {}) + ->$search + ->$fetch_count; + }, qr{__invalid__}, 'unknown relation'; + }; }; done_testing;