Don't override count value that has been set by query.count

This commit is contained in:
scossar 2017-12-13 18:48:46 -08:00
parent 5db3d39b05
commit 11050e5d10
2 changed files with 9 additions and 2 deletions

View File

@ -22,13 +22,13 @@ module Jobs
target_usernames = Group[:moderators].users.map do |user| target_usernames = Group[:moderators].users.map do |user|
next if user.id < 0 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.id > ?", user.seen_notification_id)
.where("notifications.read = false") .where("notifications.read = false")
.where("topics.subtype = ?", TopicSubtype.pending_users_reminder) .where("topics.subtype = ?", TopicSubtype.pending_users_reminder)
.count .count
count == 0 ? user.username : nil unseen_count == 0 ? user.username : nil
end.compact end.compact
unless target_usernames.empty? unless target_usernames.empty?

View File

@ -38,6 +38,13 @@ describe Jobs::PendingUsersReminder do
PostCreator.expects(:create).never PostCreator.expects(:create).never
Jobs::PendingUsersReminder.new.execute({}) Jobs::PendingUsersReminder.new.execute({})
end 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
end end