2016-02-16 17:21:24 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Notes::UpdateService do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-02-16 17:21:24 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
2017-03-28 02:25:43 -04:00
|
|
|
let(:user3) { create(:user) }
|
2016-02-16 17:21:24 -05:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
2017-03-28 02:25:43 -04:00
|
|
|
let(:note) { create(:note, project: project, noteable: issue, author: user, note: "Old note #{user2.to_reference}") }
|
2016-02-16 17:21:24 -05:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user2)
|
|
|
|
project.add_developer(user3)
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
def update_note(opts)
|
|
|
|
@note = Notes::UpdateService.new(project, user, opts).execute(note)
|
|
|
|
@note.reload
|
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
context 'todos' do
|
|
|
|
let!(:todo) { create(:todo, :assigned, user: user, project: project, target: issue, author: user2) }
|
2016-02-16 17:21:24 -05:00
|
|
|
|
|
|
|
context 'when the note change' do
|
|
|
|
before do
|
2017-03-28 02:25:43 -04:00
|
|
|
update_note({ note: "New note #{user2.to_reference} #{user3.to_reference}" })
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'marks todos as done' do
|
|
|
|
expect(todo.reload).to be_done
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
2017-03-28 02:25:43 -04:00
|
|
|
|
|
|
|
it 'creates only 1 new todo' do
|
|
|
|
expect(Todo.count).to eq(2)
|
|
|
|
end
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the note does not change' do
|
|
|
|
before do
|
2017-03-28 02:25:43 -04:00
|
|
|
update_note({ note: "Old note #{user2.to_reference}" })
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'keep todos' do
|
|
|
|
expect(todo.reload).to be_pending
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
2017-03-28 02:25:43 -04:00
|
|
|
|
|
|
|
it 'does not create any new todos' do
|
|
|
|
expect(Todo.count).to eq(1)
|
|
|
|
end
|
2016-02-16 17:21:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|