mark dataexported notifications as read when visiting export page

This commit is contained in:
Georg Gadinger 2022-12-10 15:56:07 +01:00
parent 3e143954e3
commit d52529c840
2 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,7 @@
class Settings::ExportController < ApplicationController
before_action :authenticate_user!
before_action :mark_notifications_as_read, only: %i[index]
def index
flash[:info] = t(".info") if current_user.export_processing
@ -17,4 +18,12 @@ class Settings::ExportController < ApplicationController
redirect_to settings_export_path
end
private
def mark_notifications_as_read
Notification::DataExported
.where(recipient: current_user, new: true)
.update_all(new: false) # rubocop:disable Rails/SkipsModelValidations
end
end

View File

@ -15,6 +15,21 @@ describe Settings::ExportController, type: :controller do
subject
expect(response).to render_template(:index)
end
context "when user has a new DataExported notification" do
let(:notification) do
Notification::DataExported.create(
target_id: user.id,
target_type: "User::DataExport",
recipient: user,
new: true
)
end
it "marks the notification as read" do
expect { subject }.to change { notification.reload.new }.from(true).to(false)
end
end
end
end