]> git.openstreetmap.org Git - rails.git/commitdiff
Make api element index paths resourceful
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Feb 2025 10:00:39 +0000 (13:00 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 2 Feb 2025 09:17:47 +0000 (12:17 +0300)
config/routes.rb
test/controllers/api/nodes_controller_test.rb
test/controllers/api/relations_controller_test.rb
test/controllers/api/ways_controller_test.rb

index 19dfc9a7729519c26285160ff1d3d68a36c157c7..3079da18f1abd6fe4673aaf13a19d505ab51ff57 100644 (file)
@@ -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
index 9896c34a5a70ac491e27e600694237cc22e7abc6..e70b431e6bfd4ba5806421c1fbfebf8f61bf1b07 100644 (file)
@@ -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
 
index 5fb62d29f52550b5329581569b2329c035fcedbd..2919641a977b958313a34a8cfe9a52fee26d0786 100644 (file)
@@ -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
 
index 6aa4bdfa5d3b17173edfe8f7abbe8fa3f08c148a..b3dab44db7c41590bfacc94989c5233a3a74e9ec 100644 (file)
@@ -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