From 4831a8e5e545f2d150bad191a3f90d509c8ce654 Mon Sep 17 00:00:00 2001 From: Aaron Sumner Date: Tue, 10 Jul 2018 21:42:45 -0700 Subject: [PATCH 1/2] Update geocoder gem to version 1.4.9 The Freegeoip service that's the default in our current version of the geocoder gem has been discontinued. Geocoder now uses IPInfo.io as its default. Update the geocoder version to 1.4.9 to use the new default. https://github.com/everydayrails/everydayrails-rspec-2017/issues/84 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 379a7650..fb9beec2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,7 +102,7 @@ GEM faker (1.7.3) i18n (~> 0.5) ffi (1.9.18) - geocoder (1.4.4) + geocoder (1.4.9) globalid (0.4.0) activesupport (>= 4.2.0) hashdiff (0.3.4) From bdfc5c47c22136e652d656a4718b1f3fa7f4224a Mon Sep 17 00:00:00 2001 From: Aaron Sumner Date: Tue, 10 Jul 2018 21:51:07 -0700 Subject: [PATCH 2/2] Re-record VCR cassette following update to Geocoder Geocoder now uses the IPInfo.io service as its default for IP-based geocoding, since the previous default service is no longer available. This breaks test examples in chapter 10 of Everyday Rails Testing with RSpec, which uses a geocoding example to record a VCR cassette of network activity. Re-record the cassette to use IPInfo.io. It looks like this service's response is slightly different than the previous service, so update the expected response to reflect that. IPInfo.io doesn't require an API key for less than 1,000 requests a day, and is limited to non-HTTPS requests only. These limitations should be adequate for the sake of demonstration in the book, but should not be used as-is in a production environment. See IPInfo.io's pricing page to acquire an API key for the service. In addition, you'll want to ensure that secrets like API keys are filtered from cassettes when using VCR to record any service requiring an API key, username/password, or other secret. See https://relishapp.com/vcr/vcr/v/3-0-3/docs/configuration/filter-sensitive-data for details on filtering sensitive data in the version of VCR used in the current version of Everyday Rails Testing with RSpec. https://github.com/everydayrails/everydayrails-rspec-2017/issues/84 --- spec/cassettes/User/performs_geocoding.yml | 47 +++++++++++++--------- spec/models/user_spec.rb | 2 +- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/spec/cassettes/User/performs_geocoding.yml b/spec/cassettes/User/performs_geocoding.yml index e19d43b4..f251d41c 100644 --- a/spec/cassettes/User/performs_geocoding.yml +++ b/spec/cassettes/User/performs_geocoding.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://freegeoip.io/json/161.185.207.20 + uri: http://ipinfo.io/161.185.207.20/geo body: encoding: US-ASCII string: '' @@ -18,28 +18,35 @@ http_interactions: code: 200 message: OK headers: - Server: - - nginx/1.11.8 Date: - - Thu, 07 Sep 2017 22:24:35 GMT + - Wed, 11 Jul 2018 04:46:59 GMT Content-Type: - - application/json - Content-Length: - - '244' - Connection: - - keep-alive + - application/json; charset=utf-8 + Transfer-Encoding: + - chunked Vary: - - Origin - X-Database-Date: - - Thu, 07 Sep 2017 09:08:50 GMT - Strict-Transport-Security: - - max-age=31536000 + - Accept-Encoding + X-Powered-By: + - Express + X-Cloud-Trace-Context: + - 72c73f8f3c50820effc90c4aabb84d58/8793541516014538142;o=0 + Access-Control-Allow-Origin: + - "*" + X-Content-Type-Options: + - nosniff + Via: + - 1.1 google body: - encoding: UTF-8 - string: '{"ip":"161.185.207.20","country_code":"US","country_name":"United States","region_code":"NY","region_name":"New - York","city":"Brooklyn","zip_code":"11201","time_zone":"America/New_York","latitude":40.6944,"longitude":-73.9906,"metro_code":501} - -' + encoding: ASCII-8BIT + string: |- + { + "ip": "161.185.207.20", + "city": "Brooklyn", + "region": "New York", + "country": "US", + "loc": "40.6944,-73.9906", + "postal": "11201" + } http_version: - recorded_at: Thu, 07 Sep 2017 22:24:42 GMT + recorded_at: Wed, 11 Jul 2018 04:46:59 GMT recorded_with: VCR 3.0.3 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ae6eb5dd..a87c2c3b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -38,6 +38,6 @@ user.geocode }.to change(user, :location). from(nil). - to("Brooklyn, New York, United States") + to("Brooklyn, New York, US") end end