]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5545'
authorTom Hughes <tom@compton.nu>
Fri, 24 Jan 2025 15:10:03 +0000 (15:10 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 24 Jan 2025 15:10:03 +0000 (15:10 +0000)
app/controllers/api/maps_controller.rb [moved from app/controllers/api/map_controller.rb with 98% similarity]
app/controllers/export_controller.rb
app/views/api/maps/_bounds.json.jbuilder [moved from app/views/api/map/_bounds.json.jbuilder with 100% similarity]
app/views/api/maps/_bounds.xml.builder [moved from app/views/api/map/_bounds.xml.builder with 100% similarity]
app/views/api/maps/show.json.jbuilder [moved from app/views/api/map/index.json.jbuilder with 100% similarity]
app/views/api/maps/show.xml.builder [moved from app/views/api/map/index.xml.builder with 100% similarity]
config/routes.rb
test/controllers/api/maps_controller_test.rb [moved from test/controllers/api/map_controller_test.rb with 91% similarity]
test/controllers/export_controller_test.rb

similarity index 98%
rename from app/controllers/api/map_controller.rb
rename to app/controllers/api/maps_controller.rb
index da8138597ae7b269fbb983a7eda8a4347c8a9ae7..2aa25fdd74611ecb2e3323af46ede63b8f72e5fe 100644 (file)
@@ -1,5 +1,5 @@
 module Api
-  class MapController < ApiController
+  class MapsController < ApiController
     authorize_resource :class => false
 
     before_action :set_request_formats
@@ -13,7 +13,7 @@ module Api
     # Then all the relations that reference the already found nodes and ways are
     # fetched. All the nodes and ways that are referenced by those ways are then
     # fetched. Finally all the xml is returned.
-    def index
+    def show
       # Figure out the bbox
       # check boundary is sane and area within defined
       # see /config/application.yml
index 5a2b159ef6f991b96992367b3fd69e7c074de5a2..fdae75b9a5cee812b137a82ad947c627498f5c31 100644 (file)
@@ -19,7 +19,7 @@ class ExportController < ApplicationController
     case style
     when "osm"
       # redirect to API map get
-      redirect_to :controller => "api/map", :action => "index", :bbox => bbox
+      redirect_to api_map_path(:bbox => bbox)
 
     when "mapnik"
       # redirect to a special 'export' cgi script
index d8e83b97b3838cdb725249dd0824b9f312af5a8f..84e5e861947075ad2af5f7f77aea6ea0c37f1d27 100644 (file)
@@ -62,11 +62,11 @@ OpenStreetMap::Application.routes.draw do
     put "relation/:id" => "relations#update", :id => /\d+/
     delete "relation/:id" => "relations#delete", :id => /\d+/
     get "relations" => "relations#index"
-
-    get "map" => "map#index"
   end
 
   namespace :api, :path => "api/0.6" do
+    resource :map, :only => :show
+
     resources :tracepoints, :path => "trackpoints", :only => :index
 
     resources :users, :only => :index
similarity index 91%
rename from test/controllers/api/map_controller_test.rb
rename to test/controllers/api/maps_controller_test.rb
index c050100ae0c56a0fbbbaf7906089d306367e06f6..f61a1fac2925499c3f210c52a353ddcf7d2eec20 100644 (file)
@@ -1,7 +1,7 @@
 require "test_helper"
 
 module Api
-  class MapControllerTest < ActionDispatch::IntegrationTest
+  class MapsControllerTest < ActionDispatch::IntegrationTest
     def setup
       super
       @badbigbbox = %w[-0.1,-0.1,1.1,1.1 10,10,11,11]
@@ -21,11 +21,11 @@ module Api
     def test_routes
       assert_routing(
         { :path => "/api/0.6/map", :method => :get },
-        { :controller => "api/map", :action => "index" }
+        { :controller => "api/maps", :action => "show" }
       )
       assert_routing(
         { :path => "/api/0.6/map.json", :method => :get },
-        { :controller => "api/map", :action => "index", :format => "json" }
+        { :controller => "api/maps", :action => "show", :format => "json" }
       )
     end
 
@@ -42,67 +42,67 @@ module Api
 
       # Accept: XML format -> use XML
       accept_header = accept_format_header("text/xml")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: Any format -> use XML
       accept_header = accept_format_header("*/*")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: Any format, .json URL suffix -> use json
       accept_header = accept_format_header("*/*")
-      get map_path(:bbox => bbox, :format => "json"), :headers => accept_header
+      get api_map_path(:bbox => bbox, :format => "json"), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: Firefox header -> use XML
       accept_header = accept_format_header("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: JOSM header text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 -> use XML
       # Note: JOSM's header does not comply with RFC 7231, section 5.3.1
       accept_header = accept_format_header("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: text/plain, */* -> use XML
       accept_header = accept_format_header("text/plain, */*")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: text/* -> use XML
       accept_header = accept_format_header("text/*")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: json, */* format -> use json
       accept_header = accept_format_header("application/json, */*")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
 
       # Accept: json format -> use json
       accept_header = accept_format_header("application/json")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :success, "Expected success with the map call"
       assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
 
       # text/json is in invalid format, return HTTP 406 Not acceptable
       accept_header = accept_format_header("text/json")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :not_acceptable, "text/json should fail"
 
       # image/jpeg is a format which we don't support, return HTTP 406 Not acceptable
       accept_header = accept_format_header("image/jpeg")
-      get map_path(:bbox => bbox), :headers => accept_header
+      get api_map_path(:bbox => bbox), :headers => accept_header
       assert_response :not_acceptable, "text/json should fail"
     end
 
@@ -124,7 +124,7 @@ module Api
       maxlon = node.lon + 0.1
       maxlat = node.lat + 0.1
       bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
-      get map_path(:bbox => bbox)
+      get api_map_path(:bbox => bbox)
       if $VERBOSE
         print @request.to_yaml
         print @response.body
@@ -167,7 +167,7 @@ module Api
       maxlon = node.lon + 0.1
       maxlat = node.lat + 0.1
       bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
-      get map_path(:bbox => bbox, :format => "json")
+      get api_map_path(:bbox => bbox, :format => "json")
       if $VERBOSE
         print @request.to_yaml
         print @response.body
@@ -211,7 +211,7 @@ module Api
       relation = create(:relation_member, :member => node).relation
 
       bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
-      get map_path(:bbox => bbox)
+      get api_map_path(:bbox => bbox)
       assert_response :success, "The map call should have succeeded"
       assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='#{node.lon}']" \
@@ -248,7 +248,7 @@ module Api
       relation = create(:relation_member, :member => way1).relation
 
       bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
-      get map_path(:bbox => bbox)
+      get api_map_path(:bbox => bbox)
       assert_response :success, "The map call should have succeeded"
       assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
@@ -265,7 +265,7 @@ module Api
     end
 
     def test_map_empty
-      get map_path(:bbox => "179.998,89.998,179.999.1,89.999")
+      get api_map_path(:bbox => "179.998,89.998,179.999.1,89.999")
       assert_response :success, "The map call should have succeeded"
       assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='179.9980000'][minlat='89.9980000'][maxlon='179.9990000'][maxlat='89.9990000']", :count => 1
@@ -276,14 +276,14 @@ module Api
     end
 
     def test_map_without_bbox
-      get map_path
+      get api_map_path
       assert_response :bad_request
       assert_equal "The parameter bbox is required", @response.body, "A bbox param was expected"
     end
 
     def test_bbox_too_big
       @badbigbbox.each do |bbox|
-        get map_path(:bbox => bbox)
+        get api_map_path(:bbox => bbox)
         assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
         assert_equal "The maximum bbox size is #{Settings.max_request_area}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
       end
@@ -291,7 +291,7 @@ module Api
 
     def test_bbox_malformed
       @badmalformedbbox.each do |bbox|
-        get map_path(:bbox => bbox)
+        get api_map_path(:bbox => bbox)
         assert_response :bad_request, "The bbox:#{bbox} was expected to be malformed"
         assert_equal "The parameter bbox must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "bbox: #{bbox}"
       end
@@ -299,7 +299,7 @@ module Api
 
     def test_bbox_lon_mixedup
       @badlonmixedbbox.each do |bbox|
-        get map_path(:bbox => bbox)
+        get api_map_path(:bbox => bbox)
         assert_response :bad_request, "The bbox:#{bbox} was expected to have the longitude mixed up"
         assert_equal "The minimum longitude must be less than the maximum longitude, but it wasn't", @response.body, "bbox: #{bbox}"
       end
@@ -307,7 +307,7 @@ module Api
 
     def test_bbox_lat_mixedup
       @badlatmixedbbox.each do |bbox|
-        get map_path(:bbox => bbox)
+        get api_map_path(:bbox => bbox)
         assert_response :bad_request, "The bbox:#{bbox} was expected to have the latitude mixed up"
         assert_equal "The minimum latitude must be less than the maximum latitude, but it wasn't", @response.body, "bbox: #{bbox}"
       end
index 64d5a686615e9d23988f759865eb872643b8bc4a..7f7b4ee8ce6cd2e27b267b483747a55476c7980a 100644 (file)
@@ -18,7 +18,7 @@ class ExportControllerTest < ActionDispatch::IntegrationTest
   # test the finish action for raw OSM data
   def test_finish_osm
     post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm")
-    assert_redirected_to "controller" => "api/map", "action" => "index", "bbox" => "0.0,50.0,1.0,51.0"
+    assert_redirected_to api_map_path(:bbox => "0.0,50.0,1.0,51.0")
   end
 
   ###