Commit 3035332
Changed files (8)
spec/controllers/gyms_controller_spec.rb
@@ -57,16 +57,18 @@ describe GymsController do
describe "#create" do
context "valid params" do
before :each do
- post :create, gym: {
- name: "SAIT",
- location_attributes: {
- address: "1301 16 Ave NW",
- city: "Calgary",
- region: "AB",
- country: "CA",
- postal_code: "T2M 0L4",
+ VCR.use_cassette("geo-location-sait") do
+ post :create, gym: {
+ name: "SAIT",
+ location_attributes: {
+ address: "1301 16 Ave NW",
+ city: "Calgary",
+ region: "AB",
+ country: "CA",
+ postal_code: "T2M 0L4",
+ }
}
- }
+ end
end
it "redirects to the listing page" do
spec/models/location_spec.rb
@@ -3,11 +3,13 @@ require "rails_helper"
describe Location do
describe ".from" do
it "returns the correct lat/long" do
- latitude, longitude = Location.
- from("1301 16 Ave NW", "Calgary", "AB", "Canada")
+ VCR.use_cassette("geo-location-from-address") do
+ latitude, longitude = Location.
+ from("1301 16 Ave NW", "Calgary", "AB", "Canada")
- expect(latitude).to be_within(0.1).of(51.0647815)
- expect(longitude).to be_within(0.1).of(-114.0927691)
+ expect(latitude).to be_within(0.1).of(51.0647815)
+ expect(longitude).to be_within(0.1).of(-114.0927691)
+ end
end
end
@@ -33,20 +35,24 @@ describe Location do
describe ".build_from_ip" do
it "returns a location from the ip address" do
- result = Location.build_from_ip("70.173.137.232")
- expect(result).to be_instance_of(Location)
- expect(result.address).to include("Las Vegas")
- expect(result.city).to eql("Las Vegas")
- expect(result.region).to eql("NV")
- expect(result.country).to eql("US")
- expect(result.postal_code).to start_with("8910")
- expect(result.latitude).to be_within(0.2).of(36.1)
- expect(result.longitude).to be_within(0.2).of(-115.1)
+ VCR.use_cassette("geo-location-70.173.137.232") do
+ result = Location.build_from_ip("70.173.137.232")
+ expect(result).to be_instance_of(Location)
+ expect(result.address).to include("Las Vegas")
+ expect(result.city).to eql("Las Vegas")
+ expect(result.region).to eql("NV")
+ expect(result.country).to eql("US")
+ expect(result.postal_code).to start_with("8910")
+ expect(result.latitude).to be_within(0.2).of(36.1)
+ expect(result.longitude).to be_within(0.2).of(-115.1)
+ end
end
it "returns a location from the ip address" do
- result = Location.build_from_ip("127.0.0.1")
- expect(result).to be_instance_of(Location)
+ VCR.use_cassette("geo-location-127.0.0.1") do
+ result = Location.build_from_ip("127.0.0.1")
+ expect(result).to be_instance_of(Location)
+ end
end
end
@@ -61,8 +67,10 @@ describe Location do
end
it "returns an empty array" do
- subject = Location.build_from_ip("172.18.0.1")
- expect(subject.coordinates).to be_empty
+ VCR.use_cassette("geo-location-build_from_ip.172.18.0.1") do
+ subject = Location.build_from_ip("172.18.0.1")
+ expect(subject.coordinates).to be_empty
+ end
end
end
end
spec/support/vcr_setup.rb
@@ -1,4 +1,5 @@
VCR.configure do |config|
config.cassette_library_dir = "spec/vcr"
config.hook_into :webmock
+ config.ignore_localhost = true
end
spec/vcr/geo-location-70_173_137_232.yml
@@ -0,0 +1,21 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://freegeoip.io/json/70.173.137.232
+ body:
+ encoding: US-ASCII
+ string: ''
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: UTF-8
+ string: '{"ip":"70.173.137.232","country_code":"US","country_name":"United States","region_code":"NV","region_name":"Nevada","city":"Las
+ Vegas","zip_code":"89107","time_zone":"America/Los_Angeles","latitude":36.172,"longitude":-115.2094,"metro_code":839}
+
+'
+ http_version:
+ recorded_at: Tue, 31 May 2016 02:42:34 GMT
+recorded_with: VCR 3.0.3
spec/vcr/geo-location-build_from_ip_172_18_0_1.yml
@@ -0,0 +1,17 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://freegeoip.io/json/172.18.0.1
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: UTF-8
+ string: '{"ip":"172.18.0.1","country_code":"","country_name":"","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"","latitude":0,"longitude":0,"metro_code":0}
+
+'
+ http_version:
+ recorded_at: Tue, 31 May 2016 02:47:26 GMT
+recorded_with: VCR 3.0.3
spec/vcr/geo-location-from-address.yml
@@ -0,0 +1,163 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://maps.googleapis.com/maps/api/geocode/json?address=1301%2016%20Ave%20NW,%20Calgary,%20AB,%20Canada&language=en&sensor=false
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: ASCII-8BIT
+ string: |
+ {
+ "results" : [
+ {
+ "address_components" : [
+ {
+ "long_name" : "E.H. Crandell Building",
+ "short_name" : "E.H. Crandell Building",
+ "types" : [ "premise" ]
+ },
+ {
+ "long_name" : "1301",
+ "short_name" : "1301",
+ "types" : [ "street_number" ]
+ },
+ {
+ "long_name" : "16 Avenue Northwest",
+ "short_name" : "16 Ave NW",
+ "types" : [ "route" ]
+ },
+ {
+ "long_name" : "Northwest Calgary",
+ "short_name" : "Northwest Calgary",
+ "types" : [ "neighborhood", "political" ]
+ },
+ {
+ "long_name" : "Calgary",
+ "short_name" : "Calgary",
+ "types" : [ "locality", "political" ]
+ },
+ {
+ "long_name" : "Division No. 6",
+ "short_name" : "Division No. 6",
+ "types" : [ "administrative_area_level_2", "political" ]
+ },
+ {
+ "long_name" : "Alberta",
+ "short_name" : "AB",
+ "types" : [ "administrative_area_level_1", "political" ]
+ },
+ {
+ "long_name" : "Canada",
+ "short_name" : "CA",
+ "types" : [ "country", "political" ]
+ },
+ {
+ "long_name" : "T2M 0L4",
+ "short_name" : "T2M 0L4",
+ "types" : [ "postal_code" ]
+ }
+ ],
+ "formatted_address" : "E.H. Crandell Building, 1301 16 Ave NW, Calgary, AB T2M 0L4, Canada",
+ "geometry" : {
+ "location" : {
+ "lat" : 51.0663333,
+ "lng" : -114.0865588
+ },
+ "location_type" : "ROOFTOP",
+ "viewport" : {
+ "northeast" : {
+ "lat" : 51.06768228029149,
+ "lng" : -114.0852098197085
+ },
+ "southwest" : {
+ "lat" : 51.06498431970849,
+ "lng" : -114.0879077802915
+ }
+ }
+ },
+ "place_id" : "ChIJCfK3241vcVMRRI-ORjRNjEM",
+ "types" : [ "premise" ]
+ },
+ {
+ "address_components" : [
+ {
+ "long_name" : "1301",
+ "short_name" : "1301",
+ "types" : [ "street_number" ]
+ },
+ {
+ "long_name" : "16 Avenue Northwest",
+ "short_name" : "16 Ave NW",
+ "types" : [ "route" ]
+ },
+ {
+ "long_name" : "Northwest Calgary",
+ "short_name" : "Northwest Calgary",
+ "types" : [ "neighborhood", "political" ]
+ },
+ {
+ "long_name" : "Calgary",
+ "short_name" : "Calgary",
+ "types" : [ "locality", "political" ]
+ },
+ {
+ "long_name" : "Division No. 6",
+ "short_name" : "Division No. 6",
+ "types" : [ "administrative_area_level_2", "political" ]
+ },
+ {
+ "long_name" : "Alberta",
+ "short_name" : "AB",
+ "types" : [ "administrative_area_level_1", "political" ]
+ },
+ {
+ "long_name" : "Canada",
+ "short_name" : "CA",
+ "types" : [ "country", "political" ]
+ },
+ {
+ "long_name" : "T2M 4W7",
+ "short_name" : "T2M 4W7",
+ "types" : [ "postal_code" ]
+ }
+ ],
+ "formatted_address" : "1301 16 Ave NW, Calgary, AB T2M 4W7, Canada",
+ "geometry" : {
+ "bounds" : {
+ "northeast" : {
+ "lat" : 51.0668709,
+ "lng" : -114.084417
+ },
+ "southwest" : {
+ "lat" : 51.0613607,
+ "lng" : -114.0941751
+ }
+ },
+ "location" : {
+ "lat" : 51.064591,
+ "lng" : -114.0901942
+ },
+ "location_type" : "APPROXIMATE",
+ "viewport" : {
+ "northeast" : {
+ "lat" : 51.0668709,
+ "lng" : -114.084417
+ },
+ "southwest" : {
+ "lat" : 51.0613607,
+ "lng" : -114.0941751
+ }
+ }
+ },
+ "place_id" : "ChIJgZ6maJJvcVMRmTIpIcczF1Y",
+ "types" : [ "premise" ]
+ }
+ ],
+ "status" : "OK"
+ }
+ http_version:
+ recorded_at: Tue, 31 May 2016 02:45:14 GMT
+recorded_with: VCR 3.0.3
spec/vcr/geo-location-sait.yml
@@ -0,0 +1,163 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: http://maps.googleapis.com/maps/api/geocode/json?address=1301%2016%20Ave%20NW,%20Calgary,%20AB,%20CA&language=en&sensor=false
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: ASCII-8BIT
+ string: |
+ {
+ "results" : [
+ {
+ "address_components" : [
+ {
+ "long_name" : "E.H. Crandell Building",
+ "short_name" : "E.H. Crandell Building",
+ "types" : [ "premise" ]
+ },
+ {
+ "long_name" : "1301",
+ "short_name" : "1301",
+ "types" : [ "street_number" ]
+ },
+ {
+ "long_name" : "16 Avenue Northwest",
+ "short_name" : "16 Ave NW",
+ "types" : [ "route" ]
+ },
+ {
+ "long_name" : "Northwest Calgary",
+ "short_name" : "Northwest Calgary",
+ "types" : [ "neighborhood", "political" ]
+ },
+ {
+ "long_name" : "Calgary",
+ "short_name" : "Calgary",
+ "types" : [ "locality", "political" ]
+ },
+ {
+ "long_name" : "Division No. 6",
+ "short_name" : "Division No. 6",
+ "types" : [ "administrative_area_level_2", "political" ]
+ },
+ {
+ "long_name" : "Alberta",
+ "short_name" : "AB",
+ "types" : [ "administrative_area_level_1", "political" ]
+ },
+ {
+ "long_name" : "Canada",
+ "short_name" : "CA",
+ "types" : [ "country", "political" ]
+ },
+ {
+ "long_name" : "T2M 0L4",
+ "short_name" : "T2M 0L4",
+ "types" : [ "postal_code" ]
+ }
+ ],
+ "formatted_address" : "E.H. Crandell Building, 1301 16 Ave NW, Calgary, AB T2M 0L4, Canada",
+ "geometry" : {
+ "location" : {
+ "lat" : 51.0663333,
+ "lng" : -114.0865588
+ },
+ "location_type" : "ROOFTOP",
+ "viewport" : {
+ "northeast" : {
+ "lat" : 51.06768228029149,
+ "lng" : -114.0852098197085
+ },
+ "southwest" : {
+ "lat" : 51.06498431970849,
+ "lng" : -114.0879077802915
+ }
+ }
+ },
+ "place_id" : "ChIJCfK3241vcVMRRI-ORjRNjEM",
+ "types" : [ "premise" ]
+ },
+ {
+ "address_components" : [
+ {
+ "long_name" : "1301",
+ "short_name" : "1301",
+ "types" : [ "street_number" ]
+ },
+ {
+ "long_name" : "16 Avenue Northwest",
+ "short_name" : "16 Ave NW",
+ "types" : [ "route" ]
+ },
+ {
+ "long_name" : "Northwest Calgary",
+ "short_name" : "Northwest Calgary",
+ "types" : [ "neighborhood", "political" ]
+ },
+ {
+ "long_name" : "Calgary",
+ "short_name" : "Calgary",
+ "types" : [ "locality", "political" ]
+ },
+ {
+ "long_name" : "Division No. 6",
+ "short_name" : "Division No. 6",
+ "types" : [ "administrative_area_level_2", "political" ]
+ },
+ {
+ "long_name" : "Alberta",
+ "short_name" : "AB",
+ "types" : [ "administrative_area_level_1", "political" ]
+ },
+ {
+ "long_name" : "Canada",
+ "short_name" : "CA",
+ "types" : [ "country", "political" ]
+ },
+ {
+ "long_name" : "T2M 4W7",
+ "short_name" : "T2M 4W7",
+ "types" : [ "postal_code" ]
+ }
+ ],
+ "formatted_address" : "1301 16 Ave NW, Calgary, AB T2M 4W7, Canada",
+ "geometry" : {
+ "bounds" : {
+ "northeast" : {
+ "lat" : 51.0668709,
+ "lng" : -114.084417
+ },
+ "southwest" : {
+ "lat" : 51.0613607,
+ "lng" : -114.0941751
+ }
+ },
+ "location" : {
+ "lat" : 51.064591,
+ "lng" : -114.0901942
+ },
+ "location_type" : "APPROXIMATE",
+ "viewport" : {
+ "northeast" : {
+ "lat" : 51.0668709,
+ "lng" : -114.084417
+ },
+ "southwest" : {
+ "lat" : 51.0613607,
+ "lng" : -114.0941751
+ }
+ }
+ },
+ "place_id" : "ChIJgZ6maJJvcVMRmTIpIcczF1Y",
+ "types" : [ "premise" ]
+ }
+ ],
+ "status" : "OK"
+ }
+ http_version:
+ recorded_at: Tue, 31 May 2016 02:38:44 GMT
+recorded_with: VCR 3.0.3
spec/vcr/home_gym.yml
@@ -0,0 +1,35 @@
+---
+http_interactions:
+- request:
+ method: get
+ uri: https://api.yelp.com/v2/search?category_filter=gyms,stadiumsarenas&limit=20&location=calgary&offset=0&term=sait
+ body:
+ encoding: US-ASCII
+ string: ''
+ response:
+ status:
+ code: 200
+ message: OK
+ body:
+ encoding: ASCII-8BIT
+ string: '{"region": {"span": {"latitude_delta": 0.0, "longitude_delta": 0.0},
+ "center": {"latitude": 51.0663333, "longitude": -114.0865588}}, "total": 1,
+ "businesses": [{"is_claimed": false, "rating": 4.0, "mobile_url": "http://m.yelp.com/biz/sait-campus-centre-calgary?utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=",
+ "rating_img_url": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/c2f3dd9799a5/ico/stars/v1/stars_4.png",
+ "review_count": 1, "name": "Sait Campus Centre", "rating_img_url_small": "https://s3-media4.fl.yelpcdn.com/assets/2/www/img/f62a5be2f902/ico/stars/v1/stars_small_4.png",
+ "url": "http://www.yelp.com/biz/sait-campus-centre-calgary?utm_campaign=yelp_api\u0026utm_medium=api_v2_search\u0026utm_source=",
+ "categories": [["Stadiums \u0026 Arenas", "stadiumsarenas"], ["Colleges \u0026
+ Universities", "collegeuniv"]], "phone": "4032848357", "snippet_text": "I
+ spend a lot of time at the Campus Centre for events, fitness, and even wait
+ time while family is working out /swimming. It''s a Shaw Open WiFi location
+ so...", "image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/sPLC52Bh5DDpVGFhCjRzYQ/ms.jpg",
+ "snippet_image_url": "http://s3-media4.fl.yelpcdn.com/photo/IhPIcIDEjVaAi4PKrlAyYQ/ms.jpg",
+ "display_phone": "+1-403-284-8357", "rating_img_url_large": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/ccf2b76faa2c/ico/stars/v1/stars_large_4.png",
+ "id": "sait-campus-centre-calgary", "is_closed": false, "location": {"city":
+ "Calgary", "display_address": ["1301 16 Avenue NW", "Calgary, AB T2M 0L4",
+ "Canada"], "geo_accuracy": 8.0, "postal_code": "T2M 0L4", "country_code":
+ "CA", "address": ["1301 16 Avenue NW"], "coordinate": {"latitude": 51.06667,
+ "longitude": -114.08978}, "state_code": "AB"}}]}'
+ http_version:
+ recorded_at: Tue, 31 May 2016 02:34:03 GMT
+recorded_with: VCR 3.0.3