summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/services/notes/update_service.rb4
-rw-r--r--app/services/task_service.rb11
-rw-r--r--spec/services/notes/update_service_spec.rb45
3 files changed, 60 insertions, 0 deletions
diff --git a/app/services/notes/update_service.rb b/app/services/notes/update_service.rb
index 72e2f78008d..6c2d36546e1 100644
--- a/app/services/notes/update_service.rb
+++ b/app/services/notes/update_service.rb
@@ -7,6 +7,10 @@ module Notes
note.create_new_cross_references!(current_user)
note.reset_events_cache
+ if note.previous_changes.include?('note')
+ TaskService.new.update_note(note, current_user)
+ end
+
note
end
end
diff --git a/app/services/task_service.rb b/app/services/task_service.rb
index e58974a9b38..57f68c61d00 100644
--- a/app/services/task_service.rb
+++ b/app/services/task_service.rb
@@ -54,6 +54,17 @@ class TaskService
end
end
+ # When update a note we should:
+ #
+ # * mark all pending tasks related to the noteable for the current user as done
+ #
+ def update_note(note, current_user)
+ # Skip system notes, like status changes and cross-references
+ unless note.system
+ mark_as_done(note.noteable, current_user)
+ end
+ end
+
private
def create_task(project, target, author, user, action)
diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb
new file mode 100644
index 00000000000..e6670143951
--- /dev/null
+++ b/spec/services/notes/update_service_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe Notes::UpdateService, services: true do
+ let(:project) { create(:empty_project) }
+ let(:user) { create(:user) }
+ let(:user2) { create(:user) }
+ let(:issue) { create(:issue, project: project) }
+ let(:note) { create(:note, project: project, noteable: issue, author: user, note: 'Old note') }
+
+ before do
+ project.team << [user, :master]
+ project.team << [user2, :developer]
+ end
+
+ describe '#execute' do
+ def update_note(opts)
+ @note = Notes::UpdateService.new(project, user, opts).execute(note)
+ @note.reload
+ end
+
+ context 'task queue' do
+ let!(:task) { create(:pending_assigned_task, user: user, project: project, target: issue, author: user2) }
+
+ context 'when the note change' do
+ before do
+ update_note({ note: 'New note' })
+ end
+
+ it 'marks pending tasks as done' do
+ expect(task.reload).to be_done
+ end
+ end
+
+ context 'when the note does not change' do
+ before do
+ update_note({ note: 'Old note' })
+ end
+
+ it 'keep pending tasks' do
+ expect(task.reload).to be_pending
+ end
+ end
+ end
+ end
+end