diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-10-20 11:51:11 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-10-20 11:51:11 +0100 |
commit | c51d8e6b5ed134521dbdd376271481029b605aaf (patch) | |
tree | 052cd3882866e2ff3c14522e2739c5556f8a257c | |
parent | 92d76f79e62d98f89f77e6f6d5b8f1bef67d8b42 (diff) | |
parent | 51a83fee9ff77c9a0c9eea1ce10ac43793118d0e (diff) |
Merge branch 'issues/forcouncils/100-fix-template-list'
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 10 | ||||
-rw-r--r-- | t/app/model/problem.t | 14 |
2 files changed, 20 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 13fd74807..69dc17e44 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -658,13 +658,15 @@ order of title. =cut sub response_templates { - my $problem = shift; - return $problem->result_source->schema->resultset('ResponseTemplate')->search( + my $self = shift; + return $self->result_source->schema->resultset('ResponseTemplate')->search( { - body_id => $problem->bodies_str_ids + 'me.body_id' => $self->bodies_str_ids, + 'contact.category' => [ $self->category, undef ], }, { - order_by => 'title' + order_by => 'title', + join => { 'contact_response_templates' => 'contact' }, } ); } diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 836e8a047..bd7d0e55c 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -749,6 +749,20 @@ subtest 'check reports from abuser not sent' => sub { ok $abuse->delete(), 'user removed from abuse table'; }; +subtest 'check response templates' => sub { + my $c1 = $mech->create_contact_ok(category => 'Potholes', body_id => $body_ids{2651}, email => 'p'); + my $c2 = $mech->create_contact_ok(category => 'Graffiti', body_id => $body_ids{2651}, email => 'g'); + my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body_ids{2651}, title => "Title 1", text => "Text 1" }); + my $t2 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body_ids{2651}, title => "Title 2", text => "Text 2" }); + my $t3 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body_ids{2651}, title => "Title 3", text => "Text 3" }); + $t1->add_to_contacts($c1); + $t2->add_to_contacts($c2); + my ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE'); + is $problem->response_templates, 1, 'Only the global template returned'; + ($problem) = $mech->create_problems_for_body(1, $body_ids{2651}, 'TITLE', { category => 'Potholes' }); + is $problem->response_templates, 2, 'Global and pothole templates returned'; +}; + END { $problem->comments->delete if $problem; $problem->delete if $problem; |