Permalink
Browse files

Merge pull request #3098 from sharetribe/fixed-location-spec

Fixed location spec
  • Loading branch information...
valdis committed Oct 12, 2017
2 parents a36080e + a9c3820 commit 80394d9e28fa78d21270a1687386190882082a17
Showing with 32 additions and 1 deletion.
  1. +31 −0 spec/models/location_spec.rb
  2. +1 −1 spec/support/webmock.rb
@@ -26,6 +26,7 @@
describe Location, type: :model do
describe "#search_and_fill_latlng" do
it "should store correct lat long coordinates" do
stub_maps_googleapis
l = Location.new(:address => "Bulevardi 14, Helsinki, Finland")
expect(l).to be_valid
@@ -37,4 +38,34 @@
expect(l.longitude.to_s).to eq("24.939939")
end
end
def stub_maps_googleapis
results = {
"results"=>
[{"address_components"=>
[{"long_name"=>"14", "short_name"=>"14", "types"=>["street_number"]},
{"long_name"=>"Bulevardi",
"short_name"=>"Bulevardi",
"types"=>["route"]},
{"long_name"=>"Helsinki",
"short_name"=>"HKI",
"types"=>["locality", "political"]},
{"long_name"=>"Finland",
"short_name"=>"FI",
"types"=>["country", "political"]},
{"long_name"=>"00120", "short_name"=>"00120", "types"=>["postal_code"]}],
"formatted_address"=>"Bulevardi 14, 00120 Helsinki, Finland",
"geometry"=>
{"location"=>{"lat"=>60.1651848, "lng"=>24.939939},
"location_type"=>"ROOFTOP",
"viewport"=>
{"northeast"=>{"lat"=>60.1665337802915, "lng"=>24.9412879802915},
"southwest"=>{"lat"=>60.16383581970849, "lng"=>24.9385900197085}}},
"place_id"=>"ChIJ6YBSzMsLkkYRIOsikn7B4eM",
"types"=>["street_address"]}],
"status"=>"OK"
}
stub_request(:get, "http://maps.googleapis.com/maps/api/geocode/json?address=Bulevardi%2014,%20Helsinki,%20Finland")
.to_return(status: 200, body: results.to_json, headers: {})
end
end
View
@@ -4,7 +4,7 @@
require 'webmock/rspec'
allowed_sites = lambda do |uri|
whitelist = ['127.0.0.1', '::1', 'localhost', 'graph.facebook.com', 'scontent.xx.fbcdn.net', 'maps.googleapis.com']
whitelist = ['127.0.0.1', '::1', 'localhost', 'graph.facebook.com', 'scontent.xx.fbcdn.net']
if ENV['REAL_STRIPE']
whitelist << 'api.stripe.com'
whitelist << 'js.stripe.com'

0 comments on commit 80394d9

Please sign in to comment.