From 62cfbe32369103f7b36700a919c195e0fee7435e Mon Sep 17 00:00:00 2001 From: Thu Trang Pham <thuutrangpham@gmail.com> Date: Tue, 27 Jan 2015 12:54:57 -0500 Subject: [PATCH] MockHttpResponse should return headers how net/http response does --- lib/geocoder/lookups/bing.rb | 2 +- test/test_helper.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb index 02860123..ce305f5d 100644 --- a/lib/geocoder/lookups/bing.rb +++ b/lib/geocoder/lookups/bing.rb @@ -58,7 +58,7 @@ module Geocoder::Lookup def check_response_for_errors!(response) super - if response.headers['X-MS-BM-WS-INFO'] == 1 + if response['x-ms-bm-ws-info'].to_i == 1 # Occasionally, the servers processing service requests can be overloaded, # and you may receive some responses that contain no results for queries that # you would normally receive a result. To identify this situation, diff --git a/test/test_helper.rb b/test/test_helper.rb index e00638be..6b8fac89 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -124,7 +124,7 @@ module Geocoder if file == "bing_service_unavailable" filepath = File.join("test", "fixtures", file) s = File.read(filepath).strip.gsub(/\n\s*/, "") - MockHttpResponse.new(body: s, code: "200", headers: {'X-MS-BM-WS-INFO' => 1}) + MockHttpResponse.new(body: s, code: "200", headers: {'x-ms-bm-ws-info' => "1"}) else super end @@ -424,7 +424,7 @@ class GeocoderTestCase < Test::Unit::TestCase end class MockHttpResponse - attr_reader :code, :body, :headers + attr_reader :code, :body def initialize(options = {}) @code = options[:code].to_s @body = options[:body] @@ -432,6 +432,6 @@ class MockHttpResponse end def [](key) - send key if respond_to?(key) + @headers[key] end end -- GitLab