From: Anton Khorev Date: Sun, 5 May 2024 12:32:47 +0000 (+0300) Subject: Redirect to inbox after marking a message as read/unread disregarding referer X-Git-Tag: live~561^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5da2957591e88bb23ca2e3670edece200e15b027?ds=inline Redirect to inbox after marking a message as read/unread disregarding referer Avoids staying on the message page after the "Mark as unread" button is clicked and immediately reading the message again. --- diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index d231fddde..111a31f96 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -127,7 +127,7 @@ class MessagesController < ApplicationController @message.message_read = message_read if @message.save flash[:notice] = notice - redirect_back_or_to inbox_messages_path, :status => :see_other + redirect_to inbox_messages_path, :status => :see_other end rescue ActiveRecord::RecordNotFound @title = t "messages.no_such_message.title" diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb index 8fc7d35d2..4a48ebbbe 100644 --- a/test/controllers/messages_controller_test.rb +++ b/test/controllers/messages_controller_test.rb @@ -407,14 +407,14 @@ class MessagesControllerTest < ActionDispatch::IntegrationTest assert_redirected_to inbox_messages_path assert_not Message.find(message.id).message_read - # Check that the marking a message read via XHR works - post message_mark_path(:message_id => message, :mark => "read") - assert_response :see_other + # Check that the marking a message read works and redirects to inbox from the message page + post message_mark_path(:message_id => message, :mark => "read"), :headers => { :referer => message_path(message) } + assert_redirected_to inbox_messages_path assert Message.find(message.id).message_read - # Check that the marking a message unread via XHR works - post message_mark_path(:message_id => message, :mark => "unread") - assert_response :see_other + # Check that the marking a message unread works and redirects to inbox from the message page + post message_mark_path(:message_id => message, :mark => "unread"), :headers => { :referer => message_path(message) } + assert_redirected_to inbox_messages_path assert_not Message.find(message.id).message_read # Asking to mark a message with no ID should fail