Merge pull request #4594 from AntonKhorev/simplify-link_to-on-message-pages

Simplify link_to calls on message pages
This commit is contained in:
Andy Allan 2024-03-20 14:30:06 +00:00 committed by GitHub
commit f0e76d90ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 10 deletions

View file

@ -1,6 +1,6 @@
<tr id="inbox-<%= message_summary.id %>" class="inbox-row<%= "-unread" unless message_summary.message_read? %>"> <tr id="inbox-<%= message_summary.id %>" class="inbox-row<%= "-unread" unless message_summary.message_read? %>">
<td><%= link_to message_summary.sender.display_name, user_path(message_summary.sender) %></td> <td><%= link_to message_summary.sender.display_name, message_summary.sender %></td>
<td><%= link_to message_summary.title, message_path(message_summary) %></td> <td><%= link_to message_summary.title, message_summary %></td>
<td class="text-nowrap"><%= l message_summary.sent_on, :format => :friendly %></td> <td class="text-nowrap"><%= l message_summary.sent_on, :format => :friendly %></td>
<td class="text-nowrap d-flex justify-content-end gap-1"> <td class="text-nowrap d-flex justify-content-end gap-1">
<%= 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? } %> <%= 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? } %>

View file

@ -1,6 +1,6 @@
<tr class="inbox-row"> <tr class="inbox-row">
<td><%= link_to sent_message_summary.recipient.display_name, user_path(sent_message_summary.recipient) %></td> <td><%= link_to sent_message_summary.recipient.display_name, sent_message_summary.recipient %></td>
<td><%= link_to sent_message_summary.title, message_path(sent_message_summary) %></td> <td><%= link_to sent_message_summary.title, sent_message_summary %></td>
<td class="text-nowrap"><%= l sent_message_summary.sent_on, :format => :friendly %></td> <td class="text-nowrap"><%= l sent_message_summary.sent_on, :format => :friendly %></td>
<td class="text-nowrap d-flex justify-content-end gap-1"> <td class="text-nowrap d-flex justify-content-end gap-1">
<%= 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" %> <%= 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" %>

View file

@ -1,5 +1,5 @@
<% content_for :heading do %> <% content_for :heading do %>
<h1><%= t(".send_message_to_html", :name => link_to(@message.recipient.display_name, user_path(@message.recipient))) %></h1> <h1><%= t(".send_message_to_html", :name => link_to(@message.recipient.display_name, @message.recipient)) %></h1>
<% end %> <% end %>
<%= bootstrap_form_for @message do |f| %> <%= bootstrap_form_for @message do |f| %>

View file

@ -5,10 +5,10 @@
<div class='mb-3 border-bottom border-grey py-1 d-flex gap-1 flex-wrap'> <div class='mb-3 border-bottom border-grey py-1 d-flex gap-1 flex-wrap'>
<% if current_user == @message.recipient %> <% if current_user == @message.recipient %>
<%= user_thumbnail_tiny @message.sender %> <%= user_thumbnail_tiny @message.sender %>
<%= link_to @message.sender.display_name, user_path(@message.sender) %> <%= link_to @message.sender.display_name, @message.sender %>
<% else %> <% else %>
<%= user_thumbnail_tiny @message.recipient %> <%= user_thumbnail_tiny @message.recipient %>
<%= link_to @message.recipient.display_name, user_path(@message.recipient) %> <%= link_to @message.recipient.display_name, @message.recipient %>
<% end %> <% end %>
<span class="ms-auto"> <span class="ms-auto">
<%= l @message.sent_on, :format => :friendly %> <%= l @message.sent_on, :format => :friendly %>

View file

@ -64,6 +64,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_template "new" assert_template "new"
assert_select "title", "Send message | OpenStreetMap" 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 "form[action='/messages']", :count => 1 do
assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']" assert_select "input[type='hidden'][name='display_name'][value='#{recipient_user.display_name}']"
assert_select "input#message_title", :count => 1 assert_select "input#message_title", :count => 1
@ -299,6 +300,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
get message_path(:id => unread_message) get message_path(:id => unread_message)
assert_response :success assert_response :success
assert_template "show" 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 assert_not Message.find(unread_message.id).message_read
# Login as the message recipient # Login as the message recipient
@ -308,6 +310,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
get message_path(:id => unread_message) get message_path(:id => unread_message)
assert_response :success assert_response :success
assert_template "show" assert_template "show"
assert_select "a[href='#{user_path user}']", :text => user.display_name
assert Message.find(unread_message.id).message_read assert Message.find(unread_message.id).message_read
# Asking to read a message with no ID should fail # Asking to read a message with no ID should fail
@ -338,7 +341,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
assert_template "inbox" assert_template "inbox"
assert_select ".content-inner > table", :count => 1 do assert_select ".content-inner > table", :count => 1 do
assert_select "tr", :count => 2 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
end end
@ -346,7 +352,7 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
# test the outbox action # test the outbox action
def test_outbox def test_outbox
user = create(:user) user = create(:user)
create(:message, :sender => user) message = create(:message, :sender => user)
# Check that the outbox page requires us to login # Check that the outbox page requires us to login
get outbox_messages_path get outbox_messages_path
@ -361,7 +367,10 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest
assert_template "outbox" assert_template "outbox"
assert_select ".content-inner > table", :count => 1 do assert_select ".content-inner > table", :count => 1 do
assert_select "tr", :count => 2 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
end end