Skip to content
Snippets Groups Projects
Commit 539e911b authored by jlhonora's avatar jlhonora
Browse files

Better naming of aliases and test for http(s) request

parent 3ccd77f4
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,9 @@ module Geocoder ...@@ -120,7 +120,9 @@ module Geocoder
fixture_exists?(filename) ? filename : default_fixture_filename fixture_exists?(filename) ? filename : default_fixture_filename
end end
alias_method :make_api_http_request, :make_api_request # This alias allows us to use this method in further tests
# to actually test http requests
alias_method :actual_make_api_request, :make_api_request
remove_method(:make_api_request) remove_method(:make_api_request)
def make_api_request(query) def make_api_request(query)
......
...@@ -160,19 +160,4 @@ class LookupTest < GeocoderTestCase ...@@ -160,19 +160,4 @@ class LookupTest < GeocoderTestCase
assert_equal :google, Geocoder::Lookup::Google.new.handle assert_equal :google, Geocoder::Lookup::Google.new.handle
assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle assert_equal :geocoder_ca, Geocoder::Lookup::GeocoderCa.new.handle
end end
def test_http_request
Geocoder.configure(use_https: true)
require 'webmock/test_unit'
WebMock.enable!
stub_all = WebMock.stub_request(:any, /.*/).to_return(status: 200)
g = Geocoder::Lookup::Google.new
g.send(:make_api_http_request, Geocoder::Query.new('test location'))
assert_requested(stub_all)
WebMock.reset!
WebMock.disable!
end
end end
...@@ -111,4 +111,19 @@ class GoogleTest < GeocoderTestCase ...@@ -111,4 +111,19 @@ class GoogleTest < GeocoderTestCase
query = Geocoder::Query.new("Madison Square Garden, New York, NY") query = Geocoder::Query.new("Madison Square Garden, New York, NY")
assert_match(/^https:/, query.url) assert_match(/^https:/, query.url)
end end
def test_actual_make_api_request_with_https
Geocoder.configure(use_https: true, lookup: :google)
require 'webmock/test_unit'
WebMock.enable!
stub_all = WebMock.stub_request(:any, /.*/).to_return(status: 200)
g = Geocoder::Lookup::Google.new
g.send(:actual_make_api_request, Geocoder::Query.new('test location'))
assert_requested(stub_all)
WebMock.reset!
WebMock.disable!
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment