# test all routes which lead to this controller
def test_routes
assert_routing(
- { :path => "/geocoder/search", :method => :post },
+ { :path => "/search", :method => :get },
{ :controller => "geocoder", :action => "search" }
)
assert_routing(
- { :path => "/geocoder/search_latlon", :method => :get },
- { :controller => "geocoder", :action => "search_latlon" }
+ { :path => "/geocoder/search_latlon", :method => :get },
+ { :controller => "geocoder", :action => "search_latlon" }
)
assert_routing(
{ :path => "/geocoder/search_us_postcode", :method => :get },
{ :path => "/geocoder/search_geonames", :method => :get },
{ :controller => "geocoder", :action => "search_geonames" }
)
-
- assert_routing(
- { :path => "/geocoder/description", :method => :post },
- { :controller => "geocoder", :action => "description" }
- )
assert_routing(
- { :path => "/geocoder/description_osm_nominatim", :method => :get },
- { :controller => "geocoder", :action => "description_osm_nominatim" }
+ { :path => "/geocoder/search_osm_nominatim_reverse", :method => :get },
+ { :controller => "geocoder", :action => "search_osm_nominatim_reverse" }
)
assert_routing(
- { :path => "/geocoder/description_geonames", :method => :get },
- { :controller => "geocoder", :action => "description_geonames" }
+ { :path => "/geocoder/search_geonames_reverse", :method => :get },
+ { :controller => "geocoder", :action => "search_geonames_reverse" }
)
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal code, assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "50.06773, 14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "50.06773, -14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "-50.06773, 14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "-50.06773, -14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_latlon_equal_round "50.06773, 14.37742", assigns(:query), 5
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_latlon_equal_round "50.06773, -14.37742", assigns(:query), 5
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_latlon_equal_round "-50.06773, 14.37742", assigns(:query), 5
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_latlon_equal_round "-50.06773, -14.37742", assigns(:query), 5
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "50.06773, 14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "50.06773, -14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta 50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "-50.06773, 14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta 14.37742, @controller.params[:lon]
end
end
].each do |code|
post :search, :query => code
assert_response :success
- assert_equal ['latlon'], assigns(:sources)
- assert_equal "-50.06773, -14.37742", assigns(:query)
+ assert_equal ['latlon' ,'osm_nominatim_reverse', 'geonames_reverse'], assigns(:sources)
+ assert_nil @controller.params[:query]
+ assert_in_delta -50.06773, @controller.params[:lat]
+ assert_in_delta -14.37742, @controller.params[:lon]
end
end
assert_response :success
assert_equal ['osm_nominatim'], assigns(:sources)
end
-
-private
-
- ##
- # this is a test helper for rounding latlon strings to a specified precision, e.g., at a precision
- # of 5, "50.06773333333334, -14.377416666666667" will become "50.06773, -14.37742"
- def assert_latlon_equal_round(expected, actual, precision)
- assert_equal expected.split(',').map {|i| i.to_f.round(precision)}.join(', '), actual.split(',').map {|i| i.to_f.round(precision)}.join(', ')
- end
end