|
@@ -1,26 +1,52 @@
|
|
|
# encoding: utf-8
|
|
|
require 'integration_test_helper'
|
|
|
+require 'webmock/minitest'
|
|
|
|
|
|
class GeoLocationTest < ActiveSupport::TestCase
|
|
|
|
|
|
+ setup do
|
|
|
+ @mock = true
|
|
|
+ #WebMock.allow_net_connect!
|
|
|
+ end
|
|
|
+
|
|
|
# check
|
|
|
test 'check simple results' do
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013,%2010117%20Berlin&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
result = Service::GeoLocation.geocode('Marienstrasse 13, 10117 Berlin')
|
|
|
assert(result)
|
|
|
assert_equal(52.5219143, result[0])
|
|
|
assert_equal(13.3832647, result[1])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013%2010117%20Berlin&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
result = Service::GeoLocation.geocode('Marienstrasse 13 10117 Berlin')
|
|
|
assert(result)
|
|
|
assert_equal(52.5219143, result[0])
|
|
|
assert_equal(13.3832647, result[1])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016%20St.%20Gallen&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
result = Service::GeoLocation.geocode('Martinsbruggstrasse 35, 9016 St. Gallen')
|
|
|
assert(result)
|
|
|
assert_equal(47.4366557, result[0])
|
|
|
assert_equal(9.4098904, result[1])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035%209016%20St.%20Gallen&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
result = Service::GeoLocation.geocode('Martinsbruggstrasse 35 9016 St. Gallen')
|
|
|
assert(result)
|
|
|
assert_equal(47.4366557, result[0])
|
|
@@ -30,6 +56,11 @@ class GeoLocationTest < ActiveSupport::TestCase
|
|
|
|
|
|
test 'check user results' do
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013%2010117%20Berlin&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
user1 = User.create(
|
|
|
login: 'some_geo_login1',
|
|
|
firstname: 'First',
|
|
@@ -47,6 +78,11 @@ class GeoLocationTest < ActiveSupport::TestCase
|
|
|
assert_equal(52.5219143, user1.preferences['lat'])
|
|
|
assert_equal(13.3832647, user1.preferences['lng'])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013,%2010117,%20Berlin&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
user2 = User.create(
|
|
|
login: 'some_geo_login2',
|
|
|
firstname: 'First',
|
|
@@ -66,6 +102,11 @@ class GeoLocationTest < ActiveSupport::TestCase
|
|
|
assert_equal(52.5219143, user2.preferences['lat'])
|
|
|
assert_equal(13.3832647, user2.preferences['lng'])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016%20St.%20Gallen&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
user3 = User.create(
|
|
|
login: 'some_geo_login3',
|
|
|
firstname: 'First',
|
|
@@ -83,6 +124,11 @@ class GeoLocationTest < ActiveSupport::TestCase
|
|
|
assert_equal(47.4366557, user3.preferences['lat'])
|
|
|
assert_equal(9.4098904, user3.preferences['lng'])
|
|
|
|
|
|
+ if @mock
|
|
|
+ stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016,%20St.%20Gallen&sensor=true')
|
|
|
+ .to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
+ end
|
|
|
+
|
|
|
user4 = User.create(
|
|
|
login: 'some_geo_login4',
|
|
|
firstname: 'First',
|