Sha256: 6fafd9556fa63cf39626e1583ee2c2b41923c4a0f4d1378ac55856f0ce94e4a6

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

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

class CacheTest < GeocoderTestCase

  def test_second_occurrence_of_request_is_cache_hit
    Geocoder.configure(:cache => {})
    Geocoder::Lookup.all_services_except_test.each do |l|
      next if l == :maxmind_local # local, does not use cache
      Geocoder.configure(:lookup => l)
      set_api_key!(l)
      results = Geocoder.search("Madison Square Garden")
      assert !results.first.cache_hit,
        "Lookup #{l} returned erroneously cached result."
      results = Geocoder.search("Madison Square Garden")
      assert results.first.cache_hit,
        "Lookup #{l} did not return cached result."
    end
  end

  def test_google_over_query_limit_does_not_hit_cache
    Geocoder.configure(:cache => {})
    Geocoder.configure(:lookup => :google)
    set_api_key!(:google)
    Geocoder.configure(:always_raise => :all)
    assert_raises Geocoder::OverQueryLimitError do
      Geocoder.search("over limit")
    end
    lookup = Geocoder::Lookup.get(:google)
    assert_equal false, lookup.instance_variable_get(:@cache_hit)
    assert_raises Geocoder::OverQueryLimitError do
      Geocoder.search("over limit")
    end
    assert_equal false, lookup.instance_variable_get(:@cache_hit)
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
bw-geocoder-1.2.6 test/unit/cache_test.rb
bw-geocoder-1.2.5 test/unit/cache_test.rb
geocoder-1.2.5 test/unit/cache_test.rb
geocoder-1.2.4 test/unit/cache_test.rb
geocoder-1.2.3 test/unit/cache_test.rb
geocoder-1.2.2 test/unit/cache_test.rb
geocoder-1.2.1 test/unit/cache_test.rb
geocoder-1.2.0 test/unit/cache_test.rb