2016-04-05 19:21:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Notes::DestroyService do
|
2017-12-08 07:17:22 -05:00
|
|
|
set(:project) { create(:project, :public) }
|
|
|
|
set(:issue) { create(:issue, project: project) }
|
|
|
|
let(:user) { issue.author }
|
|
|
|
|
2016-04-05 19:21:02 -04:00
|
|
|
describe '#execute' do
|
|
|
|
it 'deletes a note' do
|
2016-04-12 09:43:29 -04:00
|
|
|
note = create(:note, project: project, noteable: issue)
|
|
|
|
|
2017-12-08 07:17:22 -05:00
|
|
|
described_class.new(project, user).execute(note)
|
2016-04-06 13:04:17 -04:00
|
|
|
|
|
|
|
expect(project.issues.find(issue.id).notes).not_to include(note)
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
2017-12-08 07:17:22 -05:00
|
|
|
|
|
|
|
it 'updates the todo counts for users with todos for the note' do
|
|
|
|
note = create(:note, project: project, noteable: issue)
|
|
|
|
create(:todo, note: note, target: issue, user: user, author: user, project: project)
|
|
|
|
|
|
|
|
expect { described_class.new(project, user).execute(note) }
|
|
|
|
.to change { user.todos_pending_count }.from(1).to(0)
|
|
|
|
end
|
2018-10-16 12:21:16 -04:00
|
|
|
|
|
|
|
context 'noteable highlight cache clearing' do
|
|
|
|
let(:repo_project) { create(:project, :repository) }
|
|
|
|
let(:merge_request) do
|
|
|
|
create(:merge_request, source_project: repo_project,
|
|
|
|
target_project: repo_project)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:note) do
|
|
|
|
create(:diff_note_on_merge_request, project: repo_project,
|
|
|
|
noteable: merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(note.position).to receive(:unfolded_diff?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'clears noteable diff cache when it was unfolded for the note position' do
|
|
|
|
expect(merge_request).to receive_message_chain(:diffs, :clear_cache)
|
|
|
|
|
|
|
|
described_class.new(repo_project, user).execute(note)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not clear cache when note is not the first of the discussion' do
|
|
|
|
reply_note = create(:diff_note_on_merge_request, in_reply_to: note,
|
|
|
|
project: repo_project,
|
|
|
|
noteable: merge_request)
|
|
|
|
|
|
|
|
expect(merge_request).not_to receive(:diffs)
|
|
|
|
|
|
|
|
described_class.new(repo_project, user).execute(reply_note)
|
|
|
|
end
|
|
|
|
end
|
2016-04-05 19:21:02 -04:00
|
|
|
end
|
|
|
|
end
|