inbox: update inbox entries in controller

This commit is contained in:
Georg Gadinger 2023-01-27 20:31:38 +01:00
parent 420627f3ad
commit 3e3501d201
3 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -9,6 +9,5 @@
= render 'shared/links'
:ruby
@inbox.update_all(new: false)
provide(:title, generate_title('Inbox'))
parent_layout 'base'

View File

@ -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 }