Skip to content

Instantly share code, notes, and snippets.

@phoet
Created October 16, 2013 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phoet/7009340 to your computer and use it in GitHub Desktop.
Save phoet/7009340 to your computer and use it in GitHub Desktop.
example for stubbing geocoder calls
require 'geocoder'
Geocoder.configure(:lookup => :test)
Geocoder::Lookup::Test.add_stub(
"Nantes, France", [
{
'latitude' => 47.218371,
'longitude' => -1.553621,
'address' => '4 Rue de la Commune, 44000 Nantes, France',
'state' => 'Pays de la Loire',
'state_code' => 'Pays de la Loire',
'country' => 'France',
'country_code' => 'FR'
}
]
)
Geocoder::Lookup::Test.set_default_stub(
[
{
'latitude' => 45.1891676,
'longitude' => 5.6997775,
'address' => '8 Avenue Aristide Briand, 38600 Fontaine, France',
'state' => 'Rhone-Alpes',
'state_code' => 'RA',
'country' => 'France',
'country_code' => 'FR'
}
]
)
puts Geocoder.search("Nantes, France").first.state
# => Pays de la Loire
puts Geocoder.search("Use the fallback").first.state
# => Rhone-Alpes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment