diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-12-02 17:33:48 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-12-15 17:02:11 +0000 |
commit | 92dfeac83378cd49fbb59591685e5bf849d317e6 (patch) | |
tree | f87175f6539728e319dc5bd027b1b94fd7eaa26b /t/cobrand | |
parent | 64d24b8627879fc68f9f883d6e24a9c7cb72449f (diff) |
Fix cobrand restriction of My/Nearby.
5c79337 simplified a bit too far, as after then a particular cobrand
could in Nearby and My only filter reports to a particular body, not
any other criteria. To fix this, introduce more generic functions in
the default cobrand to allow more flexibility.
Make sure a few tests delete their bodies fully so that new tests
pass when run as part of the suite.
Fixes #1289.
Diffstat (limited to 't/cobrand')
-rw-r--r-- | t/cobrand/bromley.t | 2 | ||||
-rw-r--r-- | t/cobrand/fixamingata.t | 2 | ||||
-rw-r--r-- | t/cobrand/fixmybarangay.t | 5 | ||||
-rw-r--r-- | t/cobrand/restriction.t | 55 | ||||
-rw-r--r-- | t/cobrand/two_tier.t | 4 |
5 files changed, 62 insertions, 6 deletions
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t index 91b34a289..1f61cd3de 100644 --- a/t/cobrand/bromley.t +++ b/t/cobrand/bromley.t @@ -58,5 +58,5 @@ subtest 'testing special Open311 behaviour', sub { # Clean up $mech->delete_user($user); -$mech->delete_problems_for_body( $body->id ); +$mech->delete_body($body); done_testing(); diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t index 65236e6e1..ea3c2da92 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -115,7 +115,7 @@ subtest "Test ajax decimal points" => sub { }; END { - $mech->delete_problems_for_body(1); + $mech->delete_body($body); ok $mech->host("www.fixmystreet.com"), "change host back"; done_testing(); } diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t index 00e792341..2f99b8c1e 100644 --- a/t/cobrand/fixmybarangay.t +++ b/t/cobrand/fixmybarangay.t @@ -141,8 +141,9 @@ is $luz_report->state, 'hidden', 'should be hidden'; $mech->delete_user($fmb_test_email); -$mech->delete_problems_for_body( $luz->id ); -$mech->delete_problems_for_body( $dps->id ); +$mech->delete_body($luz); +$mech->delete_body($bsn); +$mech->delete_body($dps); ok $mech->host("www.fixmystreet.com"), "change host back"; diff --git a/t/cobrand/restriction.t b/t/cobrand/restriction.t new file mode 100644 index 000000000..873a396b7 --- /dev/null +++ b/t/cobrand/restriction.t @@ -0,0 +1,55 @@ +use strict; +use warnings; + +package FixMyStreet::Cobrand::Tester; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub problems_restriction { + my ($self, $rs) = @_; + return $rs->search({ cobrand => 'tester' }); +} + +sub updates_restriction { + my ($self, $rs) = @_; + return $rs->search({ 'problem.cobrand' => 'tester' }, { join => 'problem' }); +} + +package main; + +use Test::More; +use FixMyStreet::TestMech; + +my $c = FixMyStreet::App->new; +my $cobrand = FixMyStreet::Cobrand::Tester->new({c => $c}); +$c->stash->{cobrand} = $cobrand; + +my $mech = FixMyStreet::TestMech->new; + +my ($prob1) = $mech->create_problems_for_body(1, 1234, 'Title'); +my ($prob2) = $mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester' }); +$mech->create_problems_for_body(1, 1234, 'Title', { latitude => 0, longitude => 0 }); +$mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester', latitude => 0, longitude => 0 }); + +for (1..2) { + $c->model('DB::Comment')->create({ + problem_id => $_ == 1 ? $prob1->id : $prob2->id, + user_id => $prob2->user_id, + name => 'User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + cobrand => 'tester', + anonymous => 'f', + }); +} + +is($c->model('DB::Problem')->count, 4, 'Four reports in database'); +is($cobrand->problems->count, 2, 'Two reports in the right cobrand'); +is($cobrand->updates->count, 1, 'One update in the right cobrand'); + +my $nearby = $c->model('DB::Nearby')->nearby($c, 5, [], 10, 0.003, 0.004); +is(@$nearby, 1, 'One report close to the origin point'); + +$mech->delete_problems_for_body(1234); +done_testing(); diff --git a/t/cobrand/two_tier.t b/t/cobrand/two_tier.t index b3d6ca7db..f52e66abc 100644 --- a/t/cobrand/two_tier.t +++ b/t/cobrand/two_tier.t @@ -20,8 +20,8 @@ FixMyStreet::override_config { for my $c (@cobrands) { my ($m, $id) = @$c; my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($m); - my $body_restriction = $cobrand->body_restriction; - is $body_restriction, $id, "body_restriction for $m"; + my $council_id = $cobrand->council_id; + is $council_id, $id, "council_id for $m"; } }; |