Skip to content
Snippets Groups Projects
Commit 56900af0 authored by Tim Neems's avatar Tim Neems
Browse files

Allow for_storage to be set on a per call basis

parent c077f83d
No related branches found
No related tags found
No related merge requests found
......@@ -41,11 +41,21 @@ module Geocoder::Lookup
params[:text] = query.sanitized_text
end
params[:token] = token
params[:forStorage] = configuration[:for_storage] if configuration[:for_storage]
if for_storage_value = for_storage(query)
params[:forStorage] = for_storage_value
end
params[:sourceCountry] = configuration[:source_country] if configuration[:source_country]
params.merge(super)
end
def for_storage(query)
if query.options.has_key?(:for_storage)
query.options[:for_storage]
else
configuration[:for_storage]
end
end
def token
create_and_save_token! if !valid_token_configured? and configuration.api_key
configuration[:token].to_s unless configuration[:token].nil?
......
......@@ -34,6 +34,34 @@ class EsriTest < GeocoderTestCase
assert_match %r{token=xxxxx}, url
end
def test_query_for_geocode_with_config_for_storage_false
Geocoder.configure(esri: {for_storage: false})
query = Geocoder::Query.new("Bluffton, SC", for_storage: true)
lookup = Geocoder::Lookup.get(:esri)
url = lookup.query_url(query)
assert_match %r{forStorage=true}, url
query = Geocoder::Query.new("Bluffton, SC", for_storage: false)
lookup = Geocoder::Lookup.get(:esri)
url = lookup.query_url(query)
assert_no_match %r{forStorage}, url
end
def test_query_for_geocode_with_config_for_storage_true
Geocoder.configure(esri: {for_storage: true})
query = Geocoder::Query.new("Bluffton, SC", for_storage: true)
lookup = Geocoder::Lookup.get(:esri)
url = lookup.query_url(query)
assert_match %r{forStorage=true}, url
query = Geocoder::Query.new("Bluffton, SC", for_storage: false)
lookup = Geocoder::Lookup.get(:esri)
url = lookup.query_url(query)
assert_no_match %r{forStorage}, url
end
def test_token_generation_doesnt_overwrite_existing_config
Geocoder.configure(esri: {api_key: ['id','secret'], for_storage: true})
......
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