aboutsummaryrefslogtreecommitdiffstats
path: root/t/MapIt.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-01-22 15:57:45 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-02-13 11:44:07 +0000
commitda63f72c27e16d491f9103b9a8cbdb2fd96d2b59 (patch)
treecfd6df35b4c41028943d8a1e669345b81be41913 /t/MapIt.pm
parent04117b8be30b5d82d50cdc047ac4e7c19864f8ed (diff)
Make sure all co-ordinates are stringified.
This includes MapIt postcode lookups, geocoding, query parameters, tile clicks. Stringifying truncates them to six decimal places, which means we no longer need any "short" versions anywhere, and the JSON response will always uses a decimal point regardless of locale.
Diffstat (limited to 't/MapIt.pm')
-rw-r--r--t/MapIt.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/t/MapIt.pm b/t/MapIt.pm
new file mode 100644
index 000000000..ebef934e1
--- /dev/null
+++ b/t/MapIt.pm
@@ -0,0 +1,36 @@
+package t::MapIt;
+
+use JSON;
+use Web::Simple;
+
+use mySociety::Locale;
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /postcode/*) {
+ my ($self, $postcode) = @_;
+ my $response = $self->postcode($postcode);
+ # We must make sure we output correctly for testing purposes, we might
+ # be within a different locale here...
+ my $json = mySociety::Locale::in_gb_locale {
+ $self->json->encode($response) };
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+sub postcode {
+ my ($self, $postcode) = @_;
+ return {
+ wgs84_lat => 51.5, wgs84_lon => 2.1, postcode => $postcode,
+ };
+}
+
+__PACKAGE__->run_if_script;