From 11050e5d10e68a9c09e1cb9029cb9a2a0e483e95 Mon Sep 17 00:00:00 2001 From: scossar Date: Wed, 13 Dec 2017 18:48:46 -0800 Subject: [PATCH] Don't override count value that has been set by query.count --- app/jobs/scheduled/pending_users_reminder.rb | 4 ++-- spec/jobs/pending_users_reminder_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/jobs/scheduled/pending_users_reminder.rb b/app/jobs/scheduled/pending_users_reminder.rb index af0a1b17ca1..88c2fa4db33 100644 --- a/app/jobs/scheduled/pending_users_reminder.rb +++ b/app/jobs/scheduled/pending_users_reminder.rb @@ -22,13 +22,13 @@ module Jobs target_usernames = Group[:moderators].users.map do |user| next if user.id < 0 - count = user.notifications.joins(:topic) + unseen_count = user.notifications.joins(:topic) .where("notifications.id > ?", user.seen_notification_id) .where("notifications.read = false") .where("topics.subtype = ?", TopicSubtype.pending_users_reminder) .count - count == 0 ? user.username : nil + unseen_count == 0 ? user.username : nil end.compact unless target_usernames.empty? diff --git a/spec/jobs/pending_users_reminder_spec.rb b/spec/jobs/pending_users_reminder_spec.rb index 2d13df00d5f..ce118df93cb 100644 --- a/spec/jobs/pending_users_reminder_spec.rb +++ b/spec/jobs/pending_users_reminder_spec.rb @@ -38,6 +38,13 @@ describe Jobs::PendingUsersReminder do PostCreator.expects(:create).never Jobs::PendingUsersReminder.new.execute({}) end + + it "sets the correct pending user count in the notification" do + SiteSetting.pending_users_reminder_delay = 8 + Fabricate(:user, created_at: 9.hours.ago) + PostCreator.expects(:create).with(Discourse.system_user, has_entries(title: '1 user waiting for approval')) + Jobs::PendingUsersReminder.new.execute({}) + end end end