From 5da2957591e88bb23ca2e3670edece200e15b027 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 5 May 2024 15:32:47 +0300 Subject: [PATCH] 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. --- app/controllers/messages_controller.rb | 2 +- test/controllers/messages_controller_test.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) 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 -- 2.45.1