diff --git a/app/controllers/inbox_controller.rb b/app/controllers/inbox_controller.rb index 19c6a70d..48cc5675 100644 --- a/app/controllers/inbox_controller.rb +++ b/app/controllers/inbox_controller.rb @@ -3,6 +3,8 @@ class InboxController < ApplicationController before_action :authenticate_user! + after_action :mark_inbox_entries_as_read, only: %i[show] + def show find_author find_inbox_entries @@ -77,4 +79,9 @@ class InboxController < ApplicationController .joins(:question) .where(questions: { user: @author_user, author_is_anonymous: false }) end + + def mark_inbox_entries_as_read + # using .dup to not modify @inbox -- useful in tests + @inbox&.dup&.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations + end end diff --git a/app/views/layouts/inbox.html.haml b/app/views/layouts/inbox.html.haml index b54b82b5..cb931773 100644 --- a/app/views/layouts/inbox.html.haml +++ b/app/views/layouts/inbox.html.haml @@ -9,6 +9,5 @@ = render 'shared/links' :ruby - @inbox.update_all(new: false) provide(:title, generate_title('Inbox')) parent_layout 'base' diff --git a/spec/controllers/inbox_controller_spec.rb b/spec/controllers/inbox_controller_spec.rb index 6cb2e128..bc0ba2ad 100644 --- a/spec/controllers/inbox_controller_spec.rb +++ b/spec/controllers/inbox_controller_spec.rb @@ -58,6 +58,10 @@ describe InboxController, type: :controller do end end + it "updates the inbox entry status" do + expect { subject }.to change { inbox_entry.reload.new? }.from(true).to(false) + end + context "when requested the turbo stream format" do subject { get :show, format: :turbo_stream }