From: Anton Khorev Date: Tue, 17 Dec 2024 14:09:47 +0000 (+0300) Subject: Add patch/put api message update X-Git-Tag: live~11^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/79c306ad06155549ff6e5929ff20a1149b4862c4?ds=inline;hp=8551db4c82df7458632d4aa30e9344d60e0774dc Add patch/put api message update --- diff --git a/config/routes.rb b/config/routes.rb index 871fef1bf..77b439865 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,14 +78,13 @@ OpenStreetMap::Application.routes.draw do end end - resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :destroy], :controller => "messages", :as => :api_messages do + resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :update, :destroy], :controller => "messages", :as => :api_messages do collection do get "inbox" get "outbox" end end - - post "/user/messages/:id" => "messages#update", :as => :api_message_update + post "/user/messages/:id" => "messages#update" end namespace :api, :path => "api/0.6" do diff --git a/test/controllers/api/messages_controller_test.rb b/test/controllers/api/messages_controller_test.rb index cbf8dc870..2e7639395 100644 --- a/test/controllers/api/messages_controller_test.rb +++ b/test/controllers/api/messages_controller_test.rb @@ -46,9 +46,13 @@ module Api { :controller => "api/messages", :action => "create" } ) assert_routing( - { :path => "/api/0.6/user/messages/1", :method => :post }, + { :path => "/api/0.6/user/messages/1", :method => :put }, { :controller => "api/messages", :action => "update", :id => "1" } ) + assert_recognizes( + { :controller => "api/messages", :action => "update", :id => "1" }, + { :path => "/api/0.6/user/messages/1", :method => :post } + ) assert_routing( { :path => "/api/0.6/user/messages/1", :method => :delete }, { :controller => "api/messages", :action => "destroy", :id => "1" } @@ -253,27 +257,27 @@ module Api msg = create(:message, :unread, :sender => sender, :recipient => recipient) # attempt to mark message as read by recipient, not authenticated - post api_message_path(:id => msg.id), :params => { :read_status => true } + put api_message_path(:id => msg.id), :params => { :read_status => true } assert_response :unauthorized # attempt to mark message as read by recipient, not allowed - post api_message_path(:id => msg.id), :params => { :read_status => true }, :headers => user3_auth + put api_message_path(:id => msg.id), :params => { :read_status => true }, :headers => user3_auth assert_response :forbidden # missing parameter - post api_message_path(:id => msg.id), :headers => recipient_auth + put api_message_path(:id => msg.id), :headers => recipient_auth assert_response :bad_request # wrong type of parameter - post api_message_path(:id => msg.id), - :params => { :read_status => "not a boolean" }, - :headers => recipient_auth + put api_message_path(:id => msg.id), + :params => { :read_status => "not a boolean" }, + :headers => recipient_auth assert_response :bad_request # mark message as read by recipient - post api_message_path(:id => msg.id, :format => "json"), - :params => { :read_status => true }, - :headers => recipient_auth + put api_message_path(:id => msg.id, :format => "json"), + :params => { :read_status => true }, + :headers => recipient_auth assert_response :success assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -292,9 +296,9 @@ module Api assert_equal msg.body, jsm["body"] # mark message as unread by recipient - post api_message_path(:id => msg.id, :format => "json"), - :params => { :read_status => false }, - :headers => recipient_auth + put api_message_path(:id => msg.id, :format => "json"), + :params => { :read_status => false }, + :headers => recipient_auth assert_response :success assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body)