Skip to content
Snippets Groups Projects
Commit f4e956a3 authored by Alexey Kuleshov's avatar Alexey Kuleshov
Browse files

Allow arbitrary attributes on Geocoder::Result::Test

parent c7002e3a
No related branches found
No related tags found
No related merge requests found
......@@ -4,12 +4,26 @@ module Geocoder
module Result
class Test < Base
def self.add_result_attribute(attr)
return if respond_to?(attr.to_sym)
define_method(attr) do
@data[attr.to_s] || @data[attr.to_sym]
end
end
%w[latitude longitude neighborhood city state state_code sub_state
sub_state_code province province_code postal_code country
country_code address street_address street_number route geometry].each do |attr|
define_method(attr) do
@data[attr.to_s] || @data[attr.to_sym]
add_result_attribute(attr)
end
def initialize(data)
data.keys.each do |attr|
Test.add_result_attribute(attr)
end
super
end
end
end
......
......@@ -42,6 +42,15 @@ class TestModeTest < Test::Unit::TestCase
end
end
def test_search_with_custom_attributes
custom_attributes = mock_attributes.merge(:custom => 'NY, NY')
Geocoder::Lookup::Test.add_stub("New York, NY", [custom_attributes])
result = Geocoder.search("New York, NY").first
assert_equal 'NY, NY', result.custom
end
private
def mock_attributes
coordinates = [40.7143528, -74.0059731]
......
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