FIX: Only active assigns should be included in reminders (#281)

FIX: Only active assigns should be included in reminders (#281)

  • FIX: Only active assigns should be included in reminders

  • Update lib/pending_assigns_reminder.rb

Co-authored-by: Robin Ward robin.ward@gmail.com

diff --git a/lib/pending_assigns_reminder.rb b/lib/pending_assigns_reminder.rb
index a9a8578..741f822 100644
--- a/lib/pending_assigns_reminder.rb
+++ b/lib/pending_assigns_reminder.rb
@@ -54,7 +54,7 @@ class PendingAssignsReminder
   end
 
   def assigned_count_for(user)
-    Assignment.joins_with_topics.where(assigned_to_id: user.id, assigned_to_type: 'User').count
+    Assignment.joins_with_topics.where(assigned_to_id: user.id, assigned_to_type: 'User', active: true).count
   end
 
   def assigned_topics(user, order:)
@@ -63,7 +63,7 @@ class PendingAssignsReminder
     Topic
       .joins(:assignment)
       .select(:slug, :id, :title, :fancy_title, 'assignments.created_at AS assigned_at')
-      .where("assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User'", user.id)
+      .where("assignments.assigned_to_id = ? AND assignments.assigned_to_type = 'User' AND assignments.active", user.id)
       .merge(secure)
       .order("assignments.created_at #{order}")
       .limit(3)
diff --git a/spec/lib/pending_assigns_reminder_spec.rb b/spec/lib/pending_assigns_reminder_spec.rb
index 0e4cad2..01056cc 100644
--- a/spec/lib/pending_assigns_reminder_spec.rb
+++ b/spec/lib/pending_assigns_reminder_spec.rb
@@ -112,5 +112,36 @@ RSpec.describe PendingAssignsReminder do
 
       expect(reminders_count).to eq(2)
     end
+
+    it "closed topics aren't included as active assigns" do
+      SiteSetting.unassign_on_close = true
+
+      @post5 = Fabricate(:post)
+      Assigner.new(@post5.topic, user).assign(user)
+
+      subject.remind(user)
+
+      post = Post.last
+      topic = post.topic
+
+      expect(topic.title).to eq(I18n.t(
+        'pending_assigns_reminder.title',
+        pending_assignments: 4
+      ))
+
+      @post5.topic.update_status("closed", true, Discourse.system_user)
+      expect(@post5.topic.closed).to eq(true)
+
+      subject.remind(user)
+
+      post = Post.last
+      topic = post.topic
+
+      expect(topic.title).to eq(I18n.t(
+        'pending_assigns_reminder.title',
+        pending_assignments: 3
+      ))
+    end
+
   end
 end

GitHub sha: 7a04569c0acfa15ee9bf67ef1138055a9957b668

This commit appears in #281 which was approved by eviltrout. It was merged by jbrw.