aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand/restriction.t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-12-02 17:33:48 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-12-15 17:02:11 +0000
commit92dfeac83378cd49fbb59591685e5bf849d317e6 (patch)
treef87175f6539728e319dc5bd027b1b94fd7eaa26b /t/cobrand/restriction.t
parent64d24b8627879fc68f9f883d6e24a9c7cb72449f (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/restriction.t')
-rw-r--r--t/cobrand/restriction.t55
1 files changed, 55 insertions, 0 deletions
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();