Merge pull request #1002 from Retrospring/refactor/use-more-hooks

inbox: update inbox entries in controller
This commit is contained in:
Karina Kwiatek 2023-01-27 23:22:58 +01:00 committed by GitHub
commit 4e27af268b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 }