Skip to content

Commit 5b8215a

Browse files
committedSep 21, 2011
Make https support really work:
- need to set `use_ssl` to true - also cannot use `get_response` class method for https requests - add a smoke_test that calls out to google for real, to make sure things work end to end (not using test_helper for this, because it's invasive and opens code under test to do it's mocking) - add smoke_test to default test run
1 parent a977760 commit 5b8215a

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed
 

‎Rakefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ Bundler::GemHelper.install_tasks
44
require 'rake/testtask'
55
Rake::TestTask.new(:test) do |test|
66
test.libs << 'lib' << 'test'
7-
test.pattern = 'test/**/*_test.rb'
7+
test.pattern = 'test/*_test.rb'
88
test.verbose = true
99
end
1010

11-
task :default => :test
11+
Rake::TestTask.new(:integration) do |test|
12+
test.libs << 'lib' << 'test'
13+
test.pattern = 'test/integration/*_test.rb'
14+
test.verbose = true
15+
end
16+
17+
task :default => [:test, :integration]
1218

1319
require 'rdoc/task'
1420
Rake::RDocTask.new do |rdoc|

‎lib/geocoder/lookups/base.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ def protocol
141141
def fetch_raw_data(query, reverse = false)
142142
timeout(Geocoder::Configuration.timeout) do
143143
url = query_url(query, reverse)
144+
uri = URI.parse(url)
144145
unless cache and response = cache[url]
145-
response = http_client.get_response(URI.parse(url)).body
146+
client = http_client.new(uri.host, uri.port)
147+
client.use_ssl = true if Geocoder::Configuration.use_https
148+
response = client.get(uri.request_uri).body
146149
if cache
147150
cache[url] = response
148151
end

‎test/integration/smoke_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), *%w[ .. .. lib]))
2+
require 'pathname'
3+
require 'rubygems'
4+
require 'test/unit'
5+
require 'geocoder'
6+
7+
class SmokeTest < Test::Unit::TestCase
8+
9+
def test_simple_zip_code_search
10+
result = Geocoder.search "27701"
11+
assert_equal "Durham", result.first.city
12+
assert_equal "North Carolina", result.first.state
13+
end
14+
15+
def test_simple_zip_code_search_with_ssl
16+
Geocoder::Configuration.use_https = true
17+
result = Geocoder.search "27701"
18+
assert_equal "Durham", result.first.city
19+
assert_equal "North Carolina", result.first.state
20+
ensure
21+
Geocoder::Configuration.use_https = false
22+
end
23+
24+
end

0 commit comments

Comments
 (0)
Please sign in to comment.