From: Anton Khorev Date: Sun, 8 Dec 2024 13:02:51 +0000 (+0300) Subject: Use resourceful routes for api trace create X-Git-Tag: live~2^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/db3debdd9e5dd09717a7ed144b34158619c85e08?ds=sidebyside Use resourceful routes for api trace create --- diff --git a/config/routes.rb b/config/routes.rb index cf5a38066..3fe62dcb3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,12 +87,12 @@ OpenStreetMap::Application.routes.draw do post "/user/messages/:id" => "messages#update", :as => :api_message_update - post "gpx/create" => "traces#create" get "gpx/:id/data" => "traces#data", :as => :api_trace_data end namespace :api, :path => "api/0.6" do - resources :traces, :path => "gpx", :only => [:show, :update, :destroy], :id => /\d+/ + resources :traces, :path => "gpx", :only => [:create, :show, :update, :destroy], :id => /\d+/ + post "gpx/create" => "traces#create", :id => /\d+/, :as => :trace_create get "gpx/:id/details" => "traces#show", :id => /\d+/, :as => :trace_details # Map notes API diff --git a/test/controllers/api/traces_controller_test.rb b/test/controllers/api/traces_controller_test.rb index 6ce35bc7c..0bc5a8d36 100644 --- a/test/controllers/api/traces_controller_test.rb +++ b/test/controllers/api/traces_controller_test.rb @@ -6,9 +6,13 @@ module Api # test all routes which lead to this controller def test_routes assert_routing( - { :path => "/api/0.6/gpx/create", :method => :post }, + { :path => "/api/0.6/gpx", :method => :post }, { :controller => "api/traces", :action => "create" } ) + assert_recognizes( + { :controller => "api/traces", :action => "create" }, + { :path => "/api/0.6/gpx/create", :method => :post } + ) assert_routing( { :path => "/api/0.6/gpx/1", :method => :get }, { :controller => "api/traces", :action => "show", :id => "1" } @@ -186,7 +190,7 @@ module Api user = create(:user) # First with no auth - post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" } + post api_traces_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" } assert_response :unauthorized # Rewind the file @@ -200,7 +204,7 @@ module Api # Create trace and import tracepoints in background job perform_enqueued_jobs do - post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" }, :headers => auth_header + post api_traces_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :visibility => "trackable" }, :headers => auth_header end assert_response :success @@ -232,7 +236,7 @@ module Api # Now authenticated, with the legacy public flag assert_not_equal "public", user.preferences.find_by(:k => "gps.trace.visibility").v auth_header = bearer_authorization_header user - post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :public => 1 }, :headers => auth_header + post api_traces_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :public => 1 }, :headers => auth_header assert_response :success trace = Trace.find(response.body.to_i) assert_equal "a.gpx", trace.name @@ -251,7 +255,7 @@ module Api second_user = create(:user) assert_nil second_user.preferences.find_by(:k => "gps.trace.visibility") auth_header = bearer_authorization_header second_user - post gpx_create_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :public => 0 }, :headers => auth_header + post api_traces_path, :params => { :file => file, :description => "New Trace", :tags => "new,trace", :public => 0 }, :headers => auth_header assert_response :success trace = Trace.find(response.body.to_i) assert_equal "a.gpx", trace.name