From b5a72be2882542b0933382ec0ba003d17fec9d40 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Fri, 10 Mar 2023 21:36:43 +0100 Subject: [PATCH] Add test for marking all notifications as read --- .../notifications_controller_spec.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 97ac8a8e..448c2997 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -40,4 +40,25 @@ describe NotificationsController do end end end + + describe "#read" do + subject { post :read, format: :turbo_stream } + + let(:recipient) { FactoryBot.create(:user) } + let(:notification_count) { rand(8..20) } + + context "user has some unread notifications" do + before do + notification_count.times do + FactoryBot.create(:user).follow(recipient) + end + + sign_in(recipient) + end + + it "marks all notifications as read" do + expect { subject }.to change { Notification.where(recipient:, new: true).count }.from(notification_count).to(0) + end + end + end end