aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2013-09-13 10:46:54 +0100
committerMatthew Somerville <matthew@mysociety.org>2013-09-13 10:46:54 +0100
commit94ac7786132a538a5742ba325eb7fe9eff89cfc9 (patch)
treea2d34378e69ba30dfe26118d947459ed739c67bc /t/cobrand
parentce1978dc64b37f9335b08abaf5db6665ac6377bb (diff)
Have a central config-override function.
You only need to pass in the values you wish to be different.
Diffstat (limited to 't/cobrand')
-rw-r--r--t/cobrand/fixmybarangay.t6
-rw-r--r--t/cobrand/zurich.t74
2 files changed, 20 insertions, 60 deletions
diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t
index c0823eac4..2d9276dc0 100644
--- a/t/cobrand/fixmybarangay.t
+++ b/t/cobrand/fixmybarangay.t
@@ -80,7 +80,11 @@ $mech->get_ok( '/report/' . $dps_report->id );
$mech->email_count_is(0);
-FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay');
+FixMyStreet::override_config {
+ SEND_REPORTS_ON_STAGING => 1,
+}, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay');
+};
# Check BGY one sent by email
my $email = $mech->get_email;
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index fb9b24678..0876be582 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -5,7 +5,6 @@ use strict;
use warnings;
use DateTime;
use Test::More;
-use Sub::Override;
plan skip_all => 'Skipping Zurich test without Zurich cobrand'
unless FixMyStreet::Cobrand->exists('zurich');
@@ -26,37 +25,15 @@ plan skip_all => 'Skipping Zurich test without Zurich cobrand'
#
# commonlib/bin/gettext-makemo FixMyStreet
+use FixMyStreet;
# This is a helper method that will send the reports but with the config
# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true.
sub send_reports_for_zurich {
-
- # Capture the bits of the original config that the following code will use
- my %config =
- map {$_ => mySociety::Config::get($_)}
- qw(BASE_URL STAGING_SITE CONTACT_EMAIL SEND_REPORTS_ON_STAGING);
-
- # Change the SEND_REPORTS_ON_STAGING value to true for this test
- $config{SEND_REPORTS_ON_STAGING} = 1;
-
- # Override the get function to return values from our captured config. This
- # override will be cleared at the end of this block when the $override guard
- # falls out of scope.
- my $override_guard = Sub::Override->new(
- "mySociety::Config::get",
- sub ($;$) {
- my ($key, $default) = @_;
- exists $config{$key}
- ? return $config{$key}
- : die "Need to cache config key '$key' here";
- }
- );
-
- # Actually send the report
- FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
-
- # tidy up explicitly
- $override_guard->restore();
+ FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub {
+ # Actually send the report
+ FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+ };
}
use FixMyStreet::TestMech;
@@ -349,37 +326,16 @@ subtest "only superuser can see 'Add body' form" => sub {
};
subtest "phone number is mandatory" => sub {
- # Capture the bits of the original config that the following code will use
- my %config =
- map {$_ => FixMyStreet->config($_)}
- qw(ALLOWED_COBRANDS BASE_URL FMS_DB_NAME MAPIT_ID_WHITELIST STAGING_SITE);
-
- # Change the MAPIT_TYPES and MAPIT_URL values for this test
- $config{MAPIT_TYPES} = [ 'O08' ];
- $config{MAPIT_URL} = 'http://global.mapit.mysociety.org/';
- mySociety::MaPit::configure($config{MAPIT_URL});
-
- # Override the get function to return values from our captured config. This
- # override will be cleared at the end of this block when the $override guard
- # falls out of scope.
- my $override_guard = Sub::Override->new(
- "FixMyStreet::config",
- sub {
- my ($self, $key, $default) = @_;
- exists $config{$key}
- ? return $config{$key}
- : die "Need to cache config key '$key' here";
- }
- );
-
- $user = $mech->log_in_ok( 'dm1@example.org' );
- $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
- $mech->submit_form( with_fields => { phone => "" } );
- $mech->content_contains( 'Diese Information wird ben&ouml;tigt' );
- $mech->log_out_ok;
-
- $override_guard->restore();
- mySociety::MaPit::configure();
+ FixMyStreet::override_config {
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ }, sub {
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
+ $mech->submit_form( with_fields => { phone => "" } );
+ $mech->content_contains( 'Diese Information wird ben&ouml;tigt' );
+ $mech->log_out_ok;
+ };
};
subtest "problems can't be assigned to deleted bodies" => sub {