Skip to content

Commit 1f5be64

Browse files
committed
Enhance geocoder configuration for development by adding test stubs for New York and San Francisco
1 parent 2256373 commit 1f5be64

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

config/initializers/geocoder.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# config/initializers/geocoder.rb
44
Geocoder.configure(
5+
# Use test lookup in development/test to avoid external API calls
6+
lookup: Rails.env.production? ? :nominatim : :test,
57
always_raise: :all,
68
# geocoding service request timeout, in seconds (default 3):
79
timeout: 5,
@@ -12,3 +14,48 @@
1214
# caching (see Caching section below for details):
1315
cache: Geocoder::CacheStore::Generic.new(Rails.cache, {})
1416
)
17+
18+
# Configure test geocoding results for development/test environments
19+
unless Rails.env.production?
20+
Geocoder::Lookup::Test.add_stub(
21+
'New York, NY', [
22+
{
23+
'latitude' => 40.7143528,
24+
'longitude' => -74.0059731,
25+
'address' => 'New York, NY, USA',
26+
'state' => 'New York',
27+
'state_code' => 'NY',
28+
'country' => 'United States',
29+
'country_code' => 'US'
30+
}
31+
]
32+
)
33+
34+
Geocoder::Lookup::Test.add_stub(
35+
'San Francisco, CA', [
36+
{
37+
'latitude' => 37.7749295,
38+
'longitude' => -122.4194155,
39+
'address' => 'San Francisco, CA, USA',
40+
'state' => 'California',
41+
'state_code' => 'CA',
42+
'country' => 'United States',
43+
'country_code' => 'US'
44+
}
45+
]
46+
)
47+
48+
# Default stub for any address not specifically configured
49+
Geocoder::Lookup::Test.set_default_stub(
50+
[
51+
{
52+
'latitude' => 0.0,
53+
'longitude' => 0.0,
54+
'address' => 'Test Address',
55+
'state' => 'Test State',
56+
'country' => 'Test Country',
57+
'country_code' => 'TC'
58+
}
59+
]
60+
)
61+
end

0 commit comments

Comments
 (0)