From 8aead312002f6b68f63cfc1627f7eba226f71462 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 4 Nov 2025 06:12:30 +0100 Subject: [PATCH] Fix: mark all as read wasn't refreshing in the notifications screen --- .../notifications/bulk_readings_controller.rb | 11 +++++++++++ app/views/notifications/_tray.html.erb | 2 +- .../notifications/bulk_readings_controller_test.rb | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/controllers/notifications/bulk_readings_controller.rb b/app/controllers/notifications/bulk_readings_controller.rb index 71b387101..5f80938fe 100644 --- a/app/controllers/notifications/bulk_readings_controller.rb +++ b/app/controllers/notifications/bulk_readings_controller.rb @@ -1,5 +1,16 @@ class Notifications::BulkReadingsController < ApplicationController def create Current.user.notifications.unread.read_all + + if from_tray? + head :ok + else + redirect_to notifications_path + end end + + private + def from_tray? + params[:from_tray] + end end diff --git a/app/views/notifications/_tray.html.erb b/app/views/notifications/_tray.html.erb index a009835a4..b81e72b44 100644 --- a/app/views/notifications/_tray.html.erb +++ b/app/views/notifications/_tray.html.erb @@ -28,7 +28,7 @@ <% end %> - <%= button_to bulk_reading_path, + <%= button_to bulk_reading_path(from_tray: true), class: "btn borderless tray__clear-notifications", title: "Mark all notifications as read", data: { action: "dialog#close badge#clear", turbo_frame: "notifications" }, diff --git a/test/controllers/notifications/bulk_readings_controller_test.rb b/test/controllers/notifications/bulk_readings_controller_test.rb index 405d1f4a0..124490f53 100644 --- a/test/controllers/notifications/bulk_readings_controller_test.rb +++ b/test/controllers/notifications/bulk_readings_controller_test.rb @@ -5,11 +5,21 @@ class Notifications::BulkReadingsControllerTest < ActionDispatch::IntegrationTes sign_in_as :kevin end - test "create" do + test "create marks all notifications as read" do assert_changes -> { notifications(:logo_published_kevin).reload.read? }, from: false, to: true do assert_changes -> { notifications(:layout_commented_kevin).reload.read? }, from: false, to: true do post bulk_reading_path end end end + + test "create redirects to notifications path when not from tray" do + post bulk_reading_path + assert_redirected_to notifications_path + end + + test "create returns ok when from tray" do + post bulk_reading_path, params: { from_tray: true } + assert_response :ok + end end