aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-10-11 09:27:21 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-10-11 09:27:21 +0100
commit2404b1954614d9cd93c44e42a13449b7a7efaae1 (patch)
treee98ff3989d37c120a7f1294d2bf914dc5e89cae3
parentdfe953289cc7e3c49ee547110b953b48c2948aab (diff)
parent5934b383754a2d298100a674a1ccefc2cb9e50af (diff)
Merge branch 'bit-of-yaml-tidying'
m---------commonlib0
-rw-r--r--perllib/FixMyStreet.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm6
-rw-r--r--perllib/FixMyStreet/App/Controller/Location.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm1
-rw-r--r--perllib/FixMyStreet/Geocode.pm9
-rw-r--r--perllib/FixMyStreet/TestAppProve.pm4
-rw-r--r--t/00-check-config.t51
-rw-r--r--t/Mock/Nominatim.pm5
-rw-r--r--t/cobrand/fixamingata.t10
-rw-r--r--templates/web/base/admin/config_page.html2
12 files changed, 27 insertions, 76 deletions
diff --git a/commonlib b/commonlib
-Subproject b9fdb8ee6614adbe858891afd09da1c6079a66c
+Subproject 35699070f4d889c4aa8d4e472bacd15eeef3212
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index b3d963074..b30f59472 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -12,7 +12,7 @@ use Sub::Override;
use mySociety::Config;
-my $CONF_FILE = $ENV{FMS_OVERRIDE_CONFIG} || 'general';
+my $CONF_FILE = $ENV{FMS_OVERRIDE_CONFIG} || 'general.yml';
# load the config file and store the contents in a readonly hash
mySociety::Config::set_file( __PACKAGE__->path_to("conf/${CONF_FILE}") );
@@ -50,6 +50,9 @@ my $TEST_MODE = undef;
sub test_mode {
my $class = shift;
$TEST_MODE = shift if scalar @_;
+ # Make sure we don't run on live config
+ # uncoverable branch true
+ die "Do not run tests except through run-tests\n" if $TEST_MODE && $CONF_FILE eq 'general.yml';
return $TEST_MODE;
}
@@ -105,8 +108,7 @@ sub override_config($&) {
my ($class, $key) = @_;
return { %CONFIG, %$config } unless $key;
return $config->{$key} if exists $config->{$key};
- my $orig_config = mySociety::Config::load_default();
- return $orig_config->{$key} if exists $orig_config->{$key};
+ return $CONFIG{$key} if exists $CONFIG{$key};
}
);
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 30c023317..6af780c35 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -339,10 +339,8 @@ sub _geocode : Private {
} else {
if ( ref($suggestions) eq 'ARRAY' ) {
foreach (@$suggestions) {
- my $address = $_->{address};
- $address = decode_utf8($address) if !utf8::is_utf8($address);
- push @addresses, $address;
- push @locations, { address => $address, lat => $_->{latitude}, long => $_->{longitude} };
+ push @addresses, $_->{address};
+ push @locations, { address => $_->{address}, lat => $_->{latitude}, long => $_->{longitude} };
}
$response = { suggestions => \@addresses, locations => \@locations };
} else {
diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm
index c457c8fce..cb2077ede 100644
--- a/perllib/FixMyStreet/App/Controller/Location.pm
+++ b/perllib/FixMyStreet/App/Controller/Location.pm
@@ -96,7 +96,6 @@ sub determine_location_from_pc : Private {
if ( ref($error) eq 'ARRAY' ) {
foreach (@$error) {
my $a = $_->{address};
- $a = decode_utf8($a) if !utf8::is_utf8($a);
$a =~ s/, United Kingdom//;
$a =~ s/, UK//;
$_->{address} = $a;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 1258c8bca..b482d7612 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -7,7 +7,6 @@ use FixMyStreet;
use FixMyStreet::DB;
use FixMyStreet::Geocode::Bing;
use DateTime;
-use Encode;
use List::MoreUtils 'none';
use URI;
use Digest::MD5 qw(md5_hex);
@@ -897,9 +896,8 @@ sub _fallback_body_sender {
};
sub example_places {
- my $e = FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ];
- $e = [ map { Encode::decode('UTF-8', $_) } @$e ];
- return $e;
+ # uncoverable branch true
+ FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ];
}
=head2 title_list
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index de4a5262a..4dc95b178 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -994,7 +994,6 @@ sub _admin_send_email {
my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
my $sender_name = $c->cobrand->contact_name;
- utf8::decode($sender_name) unless utf8::is_utf8($sender_name);
$c->send_email( $template, {
to => [ $to ],
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index b5bb7249c..dd1adfe71 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -73,18 +73,19 @@ sub cache {
my $cache_file = $cache_dir->child(md5_hex($url));
my $js;
if (-s $cache_file && -M $cache_file <= 7 && !FixMyStreet->config('STAGING_SITE')) {
- $js = $cache_file->slurp;
+ # uncoverable statement
+ $js = $cache_file->slurp_utf8;
} else {
$url .= '&' . $args if $args;
$ua->timeout(15);
$js = LWP::Simple::get($url);
- $js = encode_utf8($js) if utf8::is_utf8($js);
$cache_dir->mkpath;
if ($js && (!$re || $js !~ $re) && !FixMyStreet->config('STAGING_SITE')) {
- $cache_file->spew($js);
+ # uncoverable statement
+ $cache_file->spew_utf8($js);
}
}
- $js = JSON->new->utf8->allow_nonref->decode($js) if $js;
+ $js = JSON->new->allow_nonref->decode($js) if $js;
return $js;
}
diff --git a/perllib/FixMyStreet/TestAppProve.pm b/perllib/FixMyStreet/TestAppProve.pm
index 7a387547d..d549b0148 100644
--- a/perllib/FixMyStreet/TestAppProve.pm
+++ b/perllib/FixMyStreet/TestAppProve.pm
@@ -86,8 +86,8 @@ sub run {
$config->{FMS_DB_PASS} = '';
}
- my $config_out = "general-test-autogenerated.$$";
- path("conf/$config_out.yml")->spew( YAML::Dump($config) );
+ my $config_out = "general-test-autogenerated.$$.yml";
+ path("conf/$config_out")->spew( YAML::Dump($config) );
local $ENV{FMS_OVERRIDE_CONFIG} = $config_out;
diff --git a/t/00-check-config.t b/t/00-check-config.t
deleted file mode 100644
index 00e782e74..000000000
--- a/t/00-check-config.t
+++ /dev/null
@@ -1,51 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use YAML;
-
-use FixMyStreet;
-
-# check that all the fields listed in general.yml-example are also present in
-# general.yml - helps prevent later test failures due to un-noticed additions to the
-# config file.
-
-# This code will bail_out to prevent the test suite proceeding to save time if
-# issues are found.
-
-# load the config file and store the contents in a readonly hash
-
-my $example_config = YAML::LoadFile( FixMyStreet->path_to("conf/general.yml-example") );
-my $CONF_FILE = $ENV{FMS_OVERRIDE_CONFIG} || 'general';
-my $local_config = YAML::LoadFile( FixMyStreet->path_to("conf/${CONF_FILE}.yml") );
-
-# find all keys missing from each config
-my @missing_from_example = find_missing( $example_config, $local_config );
-my @missing_from_local = find_missing( $local_config, $example_config );
-
-if ( @missing_from_example || @missing_from_local ) {
-
- fail "Missing from 'general.yml': $_" for @missing_from_local;
- fail "Missing from 'general.yml-example': $_" for @missing_from_example;
-
- # bail out to prevent other tests failing due to config issues
- BAIL_OUT( "Config has changed"
- . " - update your 'general.yml' and add/remove the keys listed above" );
-}
-else {
- pass "configs contain the same keys";
-}
-
-done_testing();
-
-sub find_missing {
- my $reference = shift;
- my $config = shift;
- my @missing = ();
-
- foreach my $key ( sort keys %$config ) {
- push @missing, $key unless exists $reference->{$key};
- }
-
- return @missing;
-}
diff --git a/t/Mock/Nominatim.pm b/t/Mock/Nominatim.pm
index 5c8c549d1..5edbc9b30 100644
--- a/t/Mock/Nominatim.pm
+++ b/t/Mock/Nominatim.pm
@@ -13,6 +13,11 @@ has json => (
sub dispatch_request {
my $self = shift;
+ sub (GET + /reverse + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/xml' ], [ '<result></result>' ] ];
+ },
+
sub (GET + /search + ?q=) {
my ($self, $q) = @_;
my $response = $self->query($q);
diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t
index 1e6bd7e65..06b5830e3 100644
--- a/t/cobrand/fixamingata.t
+++ b/t/cobrand/fixamingata.t
@@ -1,13 +1,10 @@
-use Test::MockModule;
-
use mySociety::Locale;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
-# Closest road reverse geocode mock
-my $resolver = Test::MockModule->new('LWP::Simple');
-$resolver->mock('get', sub($) { "<result></result>" });
+use t::Mock::Nominatim;
+LWP::Protocol::PSGI->register(t::Mock::Nominatim->to_psgi_app, host => 'nominatim.openstreetmap.org');
# Front page test
@@ -103,6 +100,9 @@ subtest "Test ajax decimal points" => sub {
$mech->get_ok('/ajax/lookup_location?term=12345');
# We want an actual decimal point in a JSON response...
$mech->content_contains('51.5');
+
+ $mech->get_ok('/ajax/lookup_location?term=high+street');
+ $mech->content_contains('Edinburgh');
};
};
diff --git a/templates/web/base/admin/config_page.html b/templates/web/base/admin/config_page.html
index 87032b0b6..d448d2a63 100644
--- a/templates/web/base/admin/config_page.html
+++ b/templates/web/base/admin/config_page.html
@@ -55,7 +55,7 @@ running version <strong>[% git_version || 'unknown' %]</strong>.
</tr>
[% INCLUDE with_cobrand value="MAP_TYPE" cob=c.cobrand.map_type %]
[% INCLUDE with_cobrand value="EXAMPLE_PLACES"
- conf = decode(c.config.EXAMPLE_PLACES.join(', '))
+ conf = c.config.EXAMPLE_PLACES.join(', ')
cob = c.cobrand.example_places %]
[% INCLUDE with_cobrand value="LANGUAGES"
cob = c.cobrand.languages %]