require "test_helper"
-require "geocoder_controller"
class GeocoderControllerTest < ActionController::TestCase
##
##
# Test identification of US zipcodes
def test_identify_us_postcode
- [
- "12345",
- "12345-6789"
+ %w[
+ 12345
+ 12345-6789
].each do |code|
post :search, :params => { :query => code }
assert_response :success
results_check_error "Longitude 180.23 out of range"
end
+ def test_search_latlon_digits
+ get :search_latlon, :params => { :lat => 1.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check({ :name => "1.23, 4.56", :lat => 1.23, :lon => 4.56, :zoom => 16 },
+ { :name => "4.56, 1.23", :lat => 4.56, :lon => 1.23, :zoom => 16 })
+
+ get :search_latlon, :params => { :lat => -91.23, :lon => 4.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check :name => "4.56, -91.23", :lat => 4.56, :lon => -91.23, :zoom => 16
+
+ get :search_latlon, :params => { :lat => -1.23, :lon => 170.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check :name => "-1.23, 170.23", :lat => -1.23, :lon => 170.23, :zoom => 16
+
+ get :search_latlon, :params => { :lat => 91.23, :lon => 94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check_error "Latitude or longitude are out of range"
+
+ get :search_latlon, :params => { :lat => -91.23, :lon => -94.56, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check_error "Latitude or longitude are out of range"
+
+ get :search_latlon, :params => { :lat => 1.23, :lon => -180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check_error "Latitude or longitude are out of range"
+
+ get :search_latlon, :params => { :lat => 1.23, :lon => 180.23, :zoom => 16, :latlon_digits => true }, :xhr => true
+ results_check_error "Latitude or longitude are out of range"
+ end
+
##
# Test the Canadian postcode search
def test_search_ca_postcode
assert_select "ul.results-list", 0
else
assert_select "ul.results-list", 1 do
- assert_select "p.search_results_entry", results.count
+ assert_select "li.search_results_entry", results.count
results.each do |result|
attrs = result.collect { |k, v| "[data-#{k}='#{v}']" }.join("")
- assert_select "p.search_results_entry a.set_position#{attrs}", result[:name]
+ assert_select "li.search_results_entry a.set_position#{attrs}", result[:name]
end
end
end