From b784c1eda463fe0f7b56f791be4681ebdc8ae9ac Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Mon, 22 Jan 2018 18:04:30 +0100 Subject: [PATCH] FIX: Remove all notifications of staged user during sign-up --- app/models/user.rb | 1 + spec/models/user_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index d17a1eb6ec5..1d4283659e6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -235,6 +235,7 @@ class User < ActiveRecord::Base user.staged = false user.active = false user.custom_fields[FROM_STAGED] = true + user.notifications.destroy_all DiscourseEvent.trigger(:user_unstaged, user) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index eb1fbd6fcf9..164d121848b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1600,6 +1600,16 @@ describe User do expect(User.unstage(email: 'no@account.com')).to be_nil end + it "removes all previous notifications during unstaging" do + Fabricate(:notification, user: user) + Fabricate(:private_message_notification, user: user) + user.reload + + expect(user.total_unread_notifications).to eq(2) + user = User.unstage(params) + expect(user.total_unread_notifications).to eq(0) + end + it "triggers an event" do unstaged_user = nil event = DiscourseEvent.track_events { unstaged_user = User.unstage(params) }.first