From: Andy Allan Date: Tue, 15 May 2018 10:03:15 +0000 (+0800) Subject: Rename messages#delete to destroy X-Git-Tag: live~3621^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/73df8447e3918f08156dd69ddf631652d048f191 Rename messages#delete to destroy This is a better fit for rails controller method conventions, paving the way to resourceful routing. Keep user-facing strings as 'delete' since that's more commonly used. --- diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 11a71c3ee..e1b6d0051 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -115,13 +115,13 @@ class MessagesController < ApplicationController render :action => "no_such_message", :status => :not_found end - # Delete the message. - def delete + # Destroy the message. + def destroy @message = Message.where("to_user_id = ? OR from_user_id = ?", current_user.id, current_user.id).find(params[:message_id]) @message.from_user_visible = false if @message.sender == current_user @message.to_user_visible = false if @message.recipient == current_user if @message.save && !request.xhr? - flash[:notice] = t ".deleted" + flash[:notice] = t ".destroyed" if params[:referer] redirect_to params[:referer] diff --git a/app/views/messages/_message_summary.html.erb b/app/views/messages/_message_summary.html.erb index e9d8311fc..2132f0d08 100644 --- a/app/views/messages/_message_summary.html.erb +++ b/app/views/messages/_message_summary.html.erb @@ -4,5 +4,5 @@ <%= l message_summary.sent_on, :format => :friendly %> <%= button_to t('.unread_button'), mark_message_path(message_summary, :mark => 'unread'), { :remote => true } %> <%= button_to t('.read_button'), mark_message_path(message_summary, :mark => 'read'), { :remote => true } %> - <%= button_to t('.delete_button'), delete_message_path(message_summary, :referer => request.fullpath), { :remote => true } %> + <%= button_to t('.destroy_button'), destroy_message_path(message_summary, :referer => request.fullpath), { :remote => true } %> diff --git a/app/views/messages/_sent_message_summary.html.erb b/app/views/messages/_sent_message_summary.html.erb index 44eaa0bce..cd2839b01 100644 --- a/app/views/messages/_sent_message_summary.html.erb +++ b/app/views/messages/_sent_message_summary.html.erb @@ -2,5 +2,5 @@ <%= link_to h(sent_message_summary.recipient.display_name), user_path(sent_message_summary.recipient) %> <%= link_to h(sent_message_summary.title), read_message_path(sent_message_summary) %> <%= l sent_message_summary.sent_on, :format => :friendly %> - <%= button_to t('.delete_button'), delete_message_path(sent_message_summary, :referer => request.fullpath) %> + <%= button_to t('.destroy_button'), destroy_message_path(sent_message_summary, :referer => request.fullpath) %> diff --git a/app/views/messages/delete.js.erb b/app/views/messages/destroy.js.erb similarity index 100% rename from app/views/messages/delete.js.erb rename to app/views/messages/destroy.js.erb diff --git a/app/views/messages/read.html.erb b/app/views/messages/read.html.erb index c18b586a4..4d2f6f6ce 100644 --- a/app/views/messages/read.html.erb +++ b/app/views/messages/read.html.erb @@ -16,7 +16,7 @@
<%= button_to t('.reply_button'), reply_message_path(@message), :class => 'reply-button' %> <%= button_to t('.unread_button'), mark_message_path(@message, :mark => 'unread'), :class => 'mark-unread-button' %> - <%= button_to t('.delete_button'), delete_message_path(@message), :class => 'delete-button' %> + <%= button_to t('.destroy_button'), destroy_message_path(@message), :class => 'destroy-button' %> <% else %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 51f8dbecd..908d3755d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1078,7 +1078,7 @@ en: unread_button: "Mark as unread" read_button: "Mark as read" reply_button: "Reply" - delete_button: "Delete" + destroy_button: "Delete" new: title: "Send message" send_message_to: "Send a new message to %{name}" @@ -1114,17 +1114,17 @@ en: date: "Date" reply_button: "Reply" unread_button: "Mark as unread" - delete_button: "Delete" + destroy_button: "Delete" back: "Back" to: "To" wrong_user: "You are logged in as `%{user}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it." sent_message_summary: - delete_button: "Delete" + destroy_button: "Delete" mark: as_read: "Message marked as read" as_unread: "Message marked as unread" - delete: - deleted: "Message deleted" + destroy: + destroyed: "Message deleted" site: about: next: Next diff --git a/config/routes.rb b/config/routes.rb index 44996fd8f..171eb8ed5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -267,7 +267,7 @@ OpenStreetMap::Application.routes.draw do get "/message/read/:message_id" => "messages#read", :as => "read_message" post "/message/mark/:message_id" => "messages#mark", :as => "mark_message" get "/message/reply/:message_id" => "messages#reply", :as => "reply_message" - post "/message/delete/:message_id" => "messages#delete", :as => "delete_message" + post "/message/delete/:message_id" => "messages#destroy", :as => "destroy_message" # 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 d9a1d9b0c..a4f504ebc 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -34,7 +34,7 @@ class MessagesControllerTest < ActionController::TestCase ) assert_routing( { :path => "/message/delete/1", :method => :post }, - { :controller => "messages", :action => "delete", :message_id => "1" } + { :controller => "messages", :action => "destroy", :message_id => "1" } ) end @@ -421,52 +421,52 @@ class MessagesControllerTest < ActionController::TestCase end ## - # test the delete action - def test_delete + # test the destroy action + def test_destroy user = create(:user) second_user = create(:user) other_user = create(:user) read_message = create(:message, :read, :recipient => user, :sender => second_user) sent_message = create(:message, :unread, :recipient => second_user, :sender => user) - # Check that the deleting a message requires us to login - post :delete, :params => { :message_id => read_message.id } + # Check that destroying a message requires us to login + post :destroy, :params => { :message_id => read_message.id } assert_response :forbidden # Login as a user with no messages session[:user] = other_user.id - # Check that deleting a message we didn't send or receive fails - post :delete, :params => { :message_id => read_message.id } + # Check that destroying a message we didn't send or receive fails + post :destroy, :params => { :message_id => read_message.id } assert_response :not_found assert_template "no_such_message" # Login as the message recipient_user session[:user] = user.id - # Check that the deleting a received message works - post :delete, :params => { :message_id => read_message.id } + # Check that the destroy a received message works + post :destroy, :params => { :message_id => read_message.id } assert_redirected_to inbox_path(:display_name => user.display_name) assert_equal "Message deleted", flash[:notice] m = Message.find(read_message.id) assert_equal true, m.from_user_visible assert_equal false, m.to_user_visible - # Check that the deleting a sent message works - post :delete, :params => { :message_id => sent_message.id, :referer => outbox_path(:display_name => user.display_name) } + # Check that the destroying a sent message works + post :destroy, :params => { :message_id => sent_message.id, :referer => outbox_path(:display_name => user.display_name) } assert_redirected_to outbox_path(:display_name => user.display_name) assert_equal "Message deleted", flash[:notice] m = Message.find(sent_message.id) assert_equal false, m.from_user_visible assert_equal true, m.to_user_visible - # Asking to delete a message with no ID should fail + # Asking to destroy a message with no ID should fail assert_raise ActionController::UrlGenerationError do - post :delete + post :destroy end - # Asking to delete a message with a bogus ID should fail - post :delete, :params => { :message_id => 99999 } + # Asking to destroy a message with a bogus ID should fail + post :destroy, :params => { :message_id => 99999 } assert_response :not_found assert_template "no_such_message" end