X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/4d221fd7a6f2914cd7403a19d0f507a8e43ba5c6..8aeb16a50c3cd55c953aaec8dcc2b881fb132c88:/test/controllers/api/messages_controller_test.rb diff --git a/test/controllers/api/messages_controller_test.rb b/test/controllers/api/messages_controller_test.rb index cbf8dc870..91dbd42de 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" } @@ -161,19 +165,19 @@ module Api msg = create(:message, :unread, :sender => sender, :recipient => recipient) # fail if not authorized - get api_message_path(:id => msg.id) + get api_message_path(msg) assert_response :unauthorized # only recipient and sender can read the message - get api_message_path(:id => msg.id), :headers => user3_auth + get api_message_path(msg), :headers => user3_auth assert_response :forbidden # message does not exist - get api_message_path(:id => 99999), :headers => user3_auth + get api_message_path(99999), :headers => user3_auth assert_response :not_found # verify xml output - get api_message_path(:id => msg.id), :headers => recipient_auth + get api_message_path(msg), :headers => recipient_auth assert_equal "application/xml", response.media_type assert_select "message", :count => 1 do assert_select "[id='#{msg.id}']" @@ -190,7 +194,7 @@ module Api end # verify json output - get api_message_path(:id => msg.id, :format => "json"), :headers => recipient_auth + get api_message_path(msg, :format => "json"), :headers => recipient_auth assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body) jsm = js["message"] @@ -207,7 +211,7 @@ module Api assert_equal "markdown", jsm["body_format"] assert_equal msg.body, jsm["body"] - get api_message_path(:id => msg.id), :headers => sender_auth + get api_message_path(msg), :headers => sender_auth assert_equal "application/xml", response.media_type assert_select "message", :count => 1 do assert_select "[id='#{msg.id}']" @@ -224,7 +228,7 @@ module Api end # verify json output - get api_message_path(:id => msg.id, :format => "json"), :headers => sender_auth + get api_message_path(msg, :format => "json"), :headers => sender_auth assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body) jsm = js["message"] @@ -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(msg), :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(msg), :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(msg), :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(msg), + :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(msg, :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(msg, :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) @@ -326,15 +330,15 @@ module Api msg = create(:message, :read, :sender => sender, :recipient => recipient) # attempt to delete message, not authenticated - delete api_message_path(:id => msg.id) + delete api_message_path(msg) assert_response :unauthorized # attempt to delete message, by user3 - delete api_message_path(:id => msg.id), :headers => user3_auth + delete api_message_path(msg), :headers => user3_auth assert_response :forbidden # delete message by recipient - delete api_message_path(:id => msg.id, :format => "json"), :headers => recipient_auth + delete api_message_path(msg, :format => "json"), :headers => recipient_auth assert_response :success assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body) @@ -353,7 +357,7 @@ module Api assert_equal msg.body, jsm["body"] # delete message by sender - delete api_message_path(:id => msg.id, :format => "json"), :headers => sender_auth + delete api_message_path(msg, :format => "json"), :headers => sender_auth assert_response :success assert_equal "application/json", response.media_type js = ActiveSupport::JSON.decode(@response.body)