use warnings;
use lib 't/lib';
use Test::More;
+use Test::Fatal;
use My::Schema;
my $schema = My::Schema->connect('dbi:SQLite:dbname=:memory:');
);
};
-# 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');
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;