debian-mirror-gitlab/spec/services/notes/update_service_spec.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

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