From dfe21fec82a03d5313d1c78c5f0e2390f0aef287 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 5 Sep 2018 11:25:44 +0800 Subject: [PATCH] Use resourceful routing for message replies --- app/models/notifier.rb | 2 +- app/views/messages/show.html.erb | 2 +- config/routes.rb | 3 ++- test/controllers/messages_controller_test.rb | 8 ++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/notifier.rb b/app/models/notifier.rb index d08bedd8c..11658cfd9 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -70,7 +70,7 @@ class Notifier < ActionMailer::Base @text = message.body @title = message.title @readurl = message_url(message) - @replyurl = reply_message_url(message) + @replyurl = message_reply_url(message) @author = @from_user attach_user_avatar(message.sender) diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 6ea46fcc6..e3634e232 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -14,7 +14,7 @@
<%= @message.body.to_html %>
- <%= button_to t('.reply_button'), reply_message_path(@message), :class => 'reply-button' %> + <%= button_to t('.reply_button'), message_reply_path(@message), :class => 'reply-button' %> <%= button_to t('.unread_button'), message_mark_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %> <%= button_to t('.destroy_button'), message_path(@message), :method => 'delete', :class => 'destroy-button' %> diff --git a/config/routes.rb b/config/routes.rb index f3b7fefe4..1a5fb8272 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -266,6 +266,7 @@ OpenStreetMap::Application.routes.draw do # messages resources :messages, :only => [:create, :show, :destroy] do post :mark + match :reply, :via => [:get, :post] collection do get :inbox get :outbox @@ -276,7 +277,7 @@ OpenStreetMap::Application.routes.draw do get "/message/new/:display_name" => "messages#new", :as => "new_message" get "/message/read/:message_id", :to => redirect(:path => "/messages/%{message_id}") post "/message/mark/:message_id" => "messages#mark" # remove after deployment - match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post], :as => "reply_message" + match "/message/reply/:message_id" => "messages#reply", :via => [:get, :post] # remove after deployment # oauth admin pages (i.e: for setting up new clients, etc...) scope "/user/:display_name" do diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index e3756f042..6d4e808f6 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -29,11 +29,11 @@ class MessagesControllerTest < ActionController::TestCase { :controller => "messages", :action => "mark", :message_id => "1" } ) assert_routing( - { :path => "/message/reply/1", :method => :get }, + { :path => "/messages/1/reply", :method => :get }, { :controller => "messages", :action => "reply", :message_id => "1" } ) assert_routing( - { :path => "/message/reply/1", :method => :post }, + { :path => "/messages/1/reply", :method => :post }, { :controller => "messages", :action => "reply", :message_id => "1" } ) assert_routing( @@ -232,14 +232,14 @@ class MessagesControllerTest < ActionController::TestCase # Check that the message reply page requires us to login get :reply, :params => { :message_id => unread_message.id } - assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) + assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id)) # Login as the wrong user session[:user] = other_user.id # Check that we can't reply to somebody else's message get :reply, :params => { :message_id => unread_message.id } - assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id)) + assert_redirected_to login_path(:referer => message_reply_path(:message_id => unread_message.id)) assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to reply to was not sent to that user. Please login as the correct user in order to reply.", flash[:notice] # Login as the right user -- 2.39.5