Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 5b8215a7e5fab821cf776876f6027e276383eba2 1 parent a977760
Rob Sanheim authored September 21, 2011
10  Rakefile
@@ -4,11 +4,17 @@ Bundler::GemHelper.install_tasks
4 4
 require 'rake/testtask'
5 5
 Rake::TestTask.new(:test) do |test|
6 6
   test.libs << 'lib' << 'test'
7  
-  test.pattern = 'test/**/*_test.rb'
  7
+  test.pattern = 'test/*_test.rb'
8 8
   test.verbose = true
9 9
 end
10 10
 
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]
12 18
 
13 19
 require 'rdoc/task'
14 20
 Rake::RDocTask.new do |rdoc|
5  lib/geocoder/lookups/base.rb
@@ -141,8 +141,11 @@ def protocol
141 141
       def fetch_raw_data(query, reverse = false)
142 142
         timeout(Geocoder::Configuration.timeout) do
143 143
           url = query_url(query, reverse)
  144
+          uri = URI.parse(url)
144 145
           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
146 149
             if cache
147 150
               cache[url] = response
148 151
             end
24  test/integration/smoke_test.rb
... ...
@@ -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 notes on commit 5b8215a

Please sign in to comment.
Something went wrong with that request. Please try again.