Merge pull request #1002 from Retrospring/refactor/use-more-hooks
inbox: update inbox entries in controller
This commit is contained in:
commit
4e27af268b
|
@ -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
|
||||
|
|
|
@ -9,6 +9,5 @@
|
|||
= render 'shared/links'
|
||||
|
||||
:ruby
|
||||
@inbox.update_all(new: false)
|
||||
provide(:title, generate_title('Inbox'))
|
||||
parent_layout 'base'
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
Loading…
Reference in New Issue