Sha256: 0ba155da1420e6590e458e95c1dfb6e3f3ac5a176ad94a35bf0d82b4ed68a17c

Contents?: true

Size: 1.89 KB

Versions: 11

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
$: << File.join(File.dirname(__FILE__), "..", "..")
require 'test_helper'

class MapquestTest < GeocoderTestCase

  def setup
    Geocoder.configure(lookup: :mapquest)
    set_api_key!(:mapquest)
  end

  def test_url_contains_api_key
    Geocoder.configure(mapquest: {api_key: "abc123"})
    query = Geocoder::Query.new("Bluffton, SC")
    assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC", query.url
  end

  def test_url_for_version_2
    Geocoder.configure(mapquest: {api_key: "abc123", version: 2})
    query = Geocoder::Query.new("Bluffton, SC")
    assert_equal "http://www.mapquestapi.com/geocoding/v2/address?key=abc123&location=Bluffton%2C+SC", query.url
  end

  def test_url_for_open_street_maps
    Geocoder.configure(mapquest: {api_key: "abc123", open: true})
    query = Geocoder::Query.new("Bluffton, SC")
    assert_equal "http://open.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC", query.url
  end

  def test_result_components
    result = Geocoder.search("Madison Square Garden, New York, NY").first
    assert_equal "10001", result.postal_code
    assert_equal "46 West 31st Street, New York, NY, 10001, US", result.address
  end

  def test_no_results
    assert_equal [], Geocoder.search("no results")
  end

  def test_raises_exception_when_invalid_request
    Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
    assert_raises Geocoder::InvalidRequest do
      Geocoder.search("invalid request")
    end
  end

  def test_raises_exception_when_invalid_api_key
    Geocoder.configure(always_raise: [Geocoder::InvalidApiKey])
    assert_raises Geocoder::InvalidApiKey do
      Geocoder.search("invalid api key")
    end
  end

  def test_raises_exception_when_error
    Geocoder.configure(always_raise: [Geocoder::Error])
    assert_raises Geocoder::Error do
      Geocoder.search("error")
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
geocoder-1.2.7 test/unit/lookups/mapquest_test.rb
geocoder-kb-1.2.6 test/unit/lookups/mapquest_test.rb
geocoder-1.2.6 test/unit/lookups/mapquest_test.rb
bw-geocoder-1.2.6 test/unit/lookups/mapquest_test.rb
bw-geocoder-1.2.5 test/unit/lookups/mapquest_test.rb
geocoder-1.2.5 test/unit/lookups/mapquest_test.rb
geocoder-1.2.4 test/unit/lookups/mapquest_test.rb
geocoder-1.2.3 test/unit/lookups/mapquest_test.rb
geocoder-1.2.2 test/unit/lookups/mapquest_test.rb
geocoder-1.2.1 test/unit/lookups/mapquest_test.rb
geocoder-1.2.0 test/unit/lookups/mapquest_test.rb