From: Anton Khorev Date: Wed, 20 Mar 2024 01:48:02 +0000 (+0300) Subject: Simplify link_to calls on message pages X-Git-Tag: live~777^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/332fad14bb66da4b858034e6c544b6f4361ffde5 Simplify link_to calls on message pages --- diff --git a/app/views/messages/_message_summary.html.erb b/app/views/messages/_message_summary.html.erb index 4a552e83e..8ac09251c 100644 --- a/app/views/messages/_message_summary.html.erb +++ b/app/views/messages/_message_summary.html.erb @@ -1,6 +1,6 @@ "> - <%= link_to message_summary.sender.display_name, user_path(message_summary.sender) %> - <%= link_to message_summary.title, message_path(message_summary) %> + <%= link_to message_summary.sender.display_name, message_summary.sender %> + <%= link_to message_summary.title, message_summary %> <%= l message_summary.sent_on, :format => :friendly %> <%= button_to t(".unread_button"), message_mark_path(message_summary, :mark => "unread"), :remote => true, :class => "btn btn-sm btn-primary", :form => { :class => "inbox-mark-unread", :hidden => !message_summary.message_read? } %> diff --git a/app/views/messages/_sent_message_summary.html.erb b/app/views/messages/_sent_message_summary.html.erb index 24caba5ab..d869fd3cb 100644 --- a/app/views/messages/_sent_message_summary.html.erb +++ b/app/views/messages/_sent_message_summary.html.erb @@ -1,6 +1,6 @@ - <%= link_to sent_message_summary.recipient.display_name, user_path(sent_message_summary.recipient) %> - <%= link_to sent_message_summary.title, message_path(sent_message_summary) %> + <%= link_to sent_message_summary.recipient.display_name, sent_message_summary.recipient %> + <%= link_to sent_message_summary.title, sent_message_summary %> <%= l sent_message_summary.sent_on, :format => :friendly %> <%= button_to t(".destroy_button"), message_path(sent_message_summary, :referer => request.fullpath), :method => :delete, :remote => true, :class => "btn btn-sm btn-danger", :form_class => "inbox-destroy" %> diff --git a/app/views/messages/new.html.erb b/app/views/messages/new.html.erb index 7c91722ff..2838a5dab 100644 --- a/app/views/messages/new.html.erb +++ b/app/views/messages/new.html.erb @@ -1,5 +1,5 @@ <% content_for :heading do %> -

<%= t(".send_message_to_html", :name => link_to(@message.recipient.display_name, user_path(@message.recipient))) %>

+

<%= t(".send_message_to_html", :name => link_to(@message.recipient.display_name, @message.recipient)) %>

<% end %> <%= bootstrap_form_for @message do |f| %> diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index f0742280f..29bf02cd8 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -5,10 +5,10 @@
<% if current_user == @message.recipient %> <%= user_thumbnail_tiny @message.sender %> - <%= link_to @message.sender.display_name, user_path(@message.sender) %> + <%= link_to @message.sender.display_name, @message.sender %> <% else %> <%= user_thumbnail_tiny @message.recipient %> - <%= link_to @message.recipient.display_name, user_path(@message.recipient) %> + <%= link_to @message.recipient.display_name, @message.recipient %> <% end %> <%= l @message.sent_on, :format => :friendly %> diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index c50eaf562..df7146ad6 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -64,6 +64,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template "new" assert_select "title", "Send message | OpenStreetMap" + assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name assert_select "form[action='/messages']", :count => 1 do assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']" assert_select "input#message_title", :count => 1 @@ -299,6 +300,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest get message_path(:id => unread_message) assert_response :success assert_template "show" + assert_select "a[href='#{user_path recipient_user}']", :text => recipient_user.display_name assert_not Message.find(unread_message.id).message_read # Login as the message recipient @@ -308,6 +310,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest get message_path(:id => unread_message) assert_response :success assert_template "show" + assert_select "a[href='#{user_path user}']", :text => user.display_name assert Message.find(unread_message.id).message_read # Asking to read a message with no ID should fail @@ -338,7 +341,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_template "inbox" assert_select ".content-inner > table", :count => 1 do assert_select "tr", :count => 2 - assert_select "tr#inbox-#{read_message.id}.inbox-row", :count => 1 + assert_select "tr#inbox-#{read_message.id}.inbox-row", :count => 1 do + assert_select "a[href='#{user_path read_message.sender}']", :text => read_message.sender.display_name + assert_select "a[href='#{message_path read_message}']", :text => read_message.title + end end end @@ -346,7 +352,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest # test the outbox action def test_outbox user = create(:user) - create(:message, :sender => user) + message = create(:message, :sender => user) # Check that the outbox page requires us to login get outbox_messages_path @@ -361,7 +367,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_template "outbox" assert_select ".content-inner > table", :count => 1 do assert_select "tr", :count => 2 - assert_select "tr.inbox-row", :count => 1 + assert_select "tr.inbox-row", :count => 1 do + assert_select "a[href='#{user_path message.recipient}']", :text => message.recipient.display_name + assert_select "a[href='#{message_path message}']", :text => message.title + end end end