From 35d52765872eaaf35793c71de699aee3d2bf2a38 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 1 Feb 2025 13:00:39 +0300 Subject: [PATCH] Make api element index paths resourceful --- config/routes.rb | 7 ++++--- test/controllers/api/nodes_controller_test.rb | 10 +++++----- test/controllers/api/relations_controller_test.rb | 10 +++++----- test/controllers/api/ways_controller_test.rb | 10 +++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 19dfc9a77..3079da18f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,6 @@ OpenStreetMap::Application.routes.draw do get "node/:id" => "nodes#show", :as => :api_node, :id => /\d+/ put "node/:id" => "nodes#update", :id => /\d+/ delete "node/:id" => "nodes#delete", :id => /\d+/ - get "nodes" => "nodes#index" put "way/create" => "ways#create" get "way/:id/history" => "old_ways#history", :as => :api_way_history, :id => /\d+/ @@ -50,7 +49,6 @@ OpenStreetMap::Application.routes.draw do get "way/:id" => "ways#show", :as => :api_way, :id => /\d+/ put "way/:id" => "ways#update", :id => /\d+/ delete "way/:id" => "ways#delete", :id => /\d+/ - get "ways" => "ways#index" put "relation/create" => "relations#create" get "relation/:id/relations" => "relations#relations_for_relation", :as => :relation_relations, :id => /\d+/ @@ -61,10 +59,13 @@ OpenStreetMap::Application.routes.draw do get "relation/:id" => "relations#show", :as => :api_relation, :id => /\d+/ put "relation/:id" => "relations#update", :id => /\d+/ delete "relation/:id" => "relations#delete", :id => /\d+/ - get "relations" => "relations#index" end namespace :api, :path => "api/0.6" do + resources :nodes, :only => :index + resources :ways, :only => :index + resources :relations, :only => :index + resource :map, :only => :show resources :tracepoints, :path => "trackpoints", :only => :index diff --git a/test/controllers/api/nodes_controller_test.rb b/test/controllers/api/nodes_controller_test.rb index 9896c34a5..e70b431e6 100644 --- a/test/controllers/api/nodes_controller_test.rb +++ b/test/controllers/api/nodes_controller_test.rb @@ -434,15 +434,15 @@ module Api node5 = create(:node, :deleted, :with_history, :version => 2) # check error when no parameter provided - get nodes_path + get api_nodes_path assert_response :bad_request # check error when no parameter value provided - get nodes_path(:nodes => "") + get api_nodes_path(:nodes => "") assert_response :bad_request # test a working call - get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}") + get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}") assert_response :success assert_select "osm" do assert_select "node", :count => 5 @@ -454,7 +454,7 @@ module Api end # test a working call with json format - get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json") + get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json") js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -467,7 +467,7 @@ module Api assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false }) # check error when a non-existent node is included - get nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0") + get api_nodes_path(:nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0") assert_response :not_found end diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb index 5fb62d29f..2919641a9 100644 --- a/test/controllers/api/relations_controller_test.rb +++ b/test/controllers/api/relations_controller_test.rb @@ -174,15 +174,15 @@ module Api relation4.old_relations.find_by(:version => 1).redact!(create(:redaction)) # check error when no parameter provided - get relations_path + get api_relations_path assert_response :bad_request # check error when no parameter value provided - get relations_path(:relations => "") + get api_relations_path(:relations => "") assert_response :bad_request # test a working call - get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}") + get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}") assert_response :success assert_select "osm" do assert_select "relation", :count => 4 @@ -193,7 +193,7 @@ module Api end # test a working call with json format - get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json") + get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json") js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -205,7 +205,7 @@ module Api assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? }) # check error when a non-existent relation is included - get relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0") + get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0") assert_response :not_found end diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 6aa4bdfa5..b3dab44db 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -98,15 +98,15 @@ module Api way4 = create(:way) # check error when no parameter provided - get ways_path + get api_ways_path assert_response :bad_request # check error when no parameter value provided - get ways_path(:ways => "") + get api_ways_path(:ways => "") assert_response :bad_request # test a working call - get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}") + get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}") assert_response :success assert_select "osm" do assert_select "way", :count => 4 @@ -117,7 +117,7 @@ module Api end # test a working call with json format - get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json") + get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json") js = ActiveSupport::JSON.decode(@response.body) assert_not_nil js @@ -129,7 +129,7 @@ module Api assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? }) # check error when a non-existent way is included - get ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0") + get api_ways_path(:ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0") assert_response :not_found end -- 2.39.5