Commit 9436579b authored by Jarka Kadlecová's avatar Jarka Kadlecová

Mark todos as done when epic was relabeled

parent 50b1b777
...@@ -9,6 +9,11 @@ module Epics ...@@ -9,6 +9,11 @@ module Epics
def handle_changes(epic, options) def handle_changes(epic, options)
old_associations = options.fetch(:old_associations, {}) old_associations = options.fetch(:old_associations, {})
old_mentioned_users = old_associations.fetch(:mentioned_users, []) old_mentioned_users = old_associations.fetch(:mentioned_users, [])
old_labels = old_associations.fetch(:labels, [])
if has_changes?(epic, old_labels: old_labels)
todo_service.mark_pending_todos_as_done(epic, current_user)
end
todo_service.update_epic(epic, current_user, old_mentioned_users) todo_service.update_epic(epic, current_user, old_mentioned_users)
end end
......
...@@ -61,18 +61,58 @@ describe Epics::UpdateService do ...@@ -61,18 +61,58 @@ describe Epics::UpdateService do
end end
context 'todos' do context 'todos' do
let(:mentioned1) { create(:user) }
let(:mentioned2) { create(:user) }
before do before do
group.update(visibility: Gitlab::VisibilityLevel::PUBLIC) group.update(visibility: Gitlab::VisibilityLevel::PUBLIC)
epic.update(description: "FYI: #{mentioned1.to_reference}")
end end
it 'creates todos for only newly mentioned users' do context 'creating todos' do
expect do let(:mentioned1) { create(:user) }
update_epic(description: "FYI: #{mentioned1.to_reference} #{mentioned2.to_reference}") let(:mentioned2) { create(:user) }
end.to change { Todo.count }.by(1)
before do
epic.update(description: "FYI: #{mentioned1.to_reference}")
end
it 'creates todos for only newly mentioned users' do
expect do
update_epic(description: "FYI: #{mentioned1.to_reference} #{mentioned2.to_reference}")
end.to change { Todo.count }.by(1)
end
end
context 'adding a label' do
let(:label) { create(:group_label, group: group) }
let(:user2) { create(:user) }
let!(:todo1) do
create(:todo, :mentioned, :pending,
target: epic,
group: group,
project: nil,
author: user,
user: user)
end
let!(:todo2) do
create(:todo, :mentioned, :pending,
target: epic,
group: group,
project: nil,
author: user2,
user: user2)
end
before do
group.add_developer(user)
update_epic(label_ids: [label.id])
end
it 'marks todo as done for a user who added a label' do
expect(todo1.reload.state).to eq('done')
end
it 'does not mark todos as done for other users' do
expect(todo2.reload.state).to eq('pending')
end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment