Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/5410'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Dec 18, 2024
2 parents 7e7ede8 + e89a78f commit 7d4cc85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
9 changes: 4 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,17 @@
put "" => "user_preferences#update_all", :as => ""
end
end
end

resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :destroy], :controller => "messages", :as => :api_messages do
namespace :api, :path => "api/0.6" do
resources :messages, :path => "user/messages", :constraints => { :id => /\d+/ }, :only => [:create, :show, :update, :destroy] do
collection do
get "inbox"
get "outbox"
end
end
post "/user/messages/:id" => "messages#update"

post "/user/messages/:id" => "messages#update", :as => :api_message_update
end

namespace :api, :path => "api/0.6" do
resources :traces, :path => "gpx", :only => [:create, :show, :update, :destroy], :id => /\d+/ do
scope :module => :traces do
resource :data, :only => :show
Expand Down
30 changes: 17 additions & 13 deletions test/controllers/api/messages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ def test_routes
{ :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" }
Expand Down Expand Up @@ -253,27 +257,27 @@ def test_update_status
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)
Expand All @@ -292,9 +296,9 @@ def test_update_status
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)
Expand Down

0 comments on commit 7d4cc85

Please sign in to comment.