From 3aabed3456506d1a917e6daba29cd46ce6a25dab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rub=C3=A9n=20D=C3=A1vila?= <ruben@gitlab.com>
Date: Fri, 20 Nov 2015 13:58:45 -0500
Subject: [PATCH] Fix bug that happened when replacing the Task list. #2296

REF: https://gitlab.com/gitlab-org/gitlab-ce/issues/2296#note_2724697
---
 app/models/concerns/taskable.rb             |  2 +-
 spec/services/issues/update_service_spec.rb | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb
index de7588fea8..df2a9e3e84 100644
--- a/app/models/concerns/taskable.rb
+++ b/app/models/concerns/taskable.rb
@@ -31,7 +31,7 @@ module Taskable
       old_task = old_tasks[i]
       next unless old_task
 
-      new_task.source == new_task.source && new_task.complete? != old_task.complete?
+      new_task.source == old_task.source && new_task.complete? != old_task.complete?
     end
   end
 
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index adb3aa143a..bc6a26416a 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -121,6 +121,25 @@ describe Issues::UpdateService do
           expect(note).to be_nil
         end
       end
+
+      context 'when a Task list with a completed item is totally replaced' do
+        before do
+          update_issue({ description: "- [ ] Task 1\n- [X] Task 2" })
+          update_issue({ description: "- [ ] One\n- [ ] Two\n- [ ] Three" })
+        end
+
+        it 'does not create a system note referencing the position the old item' do
+          note = find_note('Marked the task **Two** as incomplete')
+
+          expect(note).to be_nil
+        end
+
+        it 'should not generate a new note at all' do
+          expect {
+            update_issue({ description: "- [ ] One\n- [ ] Two\n- [ ] Three" })
+          }.not_to change { Note.count }
+        end
+      end
     end
 
   end
-- 
2.30.9