2016-08-09 17:26:45 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Notes::QuickActionsService do
|
2016-08-09 17:26:45 +00:00
|
|
|
shared_context 'note on noteable' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2018-07-11 14:36:08 +00:00
|
|
|
let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
|
2016-08-09 17:26:45 +00:00
|
|
|
let(:assignee) { create(:user) }
|
2016-12-14 21:39:53 +00:00
|
|
|
|
2017-06-14 18:18:56 +00:00
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(assignee)
|
2017-06-14 18:18:56 +00:00
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
|
2017-05-31 05:50:53 +00:00
|
|
|
shared_examples 'note on noteable that does not support quick actions' do
|
2016-08-09 17:26:45 +00:00
|
|
|
include_context 'note on noteable'
|
|
|
|
|
|
|
|
before do
|
|
|
|
note.note = note_text
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'note with only command' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) { %(/close\n/assign @#{assignee.username}") }
|
|
|
|
|
|
|
|
it 'saves the note and does not alter the note text' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
|
|
|
|
expect(content).to eq note_text
|
|
|
|
expect(command_params).to be_empty
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'note with command & text' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) { %(HELLO\n/close\n/assign @#{assignee.username}\nWORLD) }
|
|
|
|
|
|
|
|
it 'saves the note and does not alter the note text' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
|
|
|
|
expect(content).to eq note_text
|
|
|
|
expect(command_params).to be_empty
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-31 05:50:53 +00:00
|
|
|
shared_examples 'note on noteable that supports quick actions' do
|
2016-08-09 17:26:45 +00:00
|
|
|
include_context 'note on noteable'
|
|
|
|
|
|
|
|
before do
|
|
|
|
note.note = note_text
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:milestone) { create(:milestone, project: project) }
|
|
|
|
let!(:labels) { create_pair(:label, project: project) }
|
|
|
|
|
|
|
|
describe 'note with only command' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) do
|
|
|
|
%(/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\n/milestone %"#{milestone.name}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'closes noteable, sets labels, assigns, and sets milestone to noteable, and leave no note' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
service.execute(command_params, note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 16:58:51 +00:00
|
|
|
expect(content).to eq ''
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable).to be_closed
|
|
|
|
expect(note.noteable.labels).to match_array(labels)
|
2017-05-04 12:11:15 +00:00
|
|
|
expect(note.noteable.assignees).to eq([assignee])
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable.milestone).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-17 23:58:52 +00:00
|
|
|
describe '/reopen' do
|
2016-08-09 17:26:45 +00:00
|
|
|
before do
|
|
|
|
note.noteable.close!
|
|
|
|
expect(note.noteable).to be_closed
|
|
|
|
end
|
2016-08-17 23:58:52 +00:00
|
|
|
let(:note_text) { '/reopen' }
|
2016-08-09 17:26:45 +00:00
|
|
|
|
|
|
|
it 'opens the noteable, and leave no note' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
service.execute(command_params, note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 16:58:51 +00:00
|
|
|
expect(content).to eq ''
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable).to be_open
|
|
|
|
end
|
|
|
|
end
|
2016-12-23 05:44:02 +00:00
|
|
|
|
|
|
|
describe '/spend' do
|
|
|
|
let(:note_text) { '/spend 1h' }
|
|
|
|
|
|
|
|
it 'updates the spent time on the noteable' do
|
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
service.execute(command_params, note)
|
|
|
|
|
|
|
|
expect(content).to eq ''
|
|
|
|
expect(note.noteable.time_spent).to eq(3600)
|
|
|
|
end
|
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'note with command & text' do
|
|
|
|
describe '/close, /label, /assign & /milestone' do
|
|
|
|
let(:note_text) do
|
|
|
|
%(HELLO\n/close\n/label ~#{labels.first.name} ~#{labels.last.name}\n/assign @#{assignee.username}\n/milestone %"#{milestone.name}"\nWORLD)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'closes noteable, sets labels, assigns, and sets milestone to noteable' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
service.execute(command_params, note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 16:58:51 +00:00
|
|
|
expect(content).to eq "HELLO\nWORLD"
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable).to be_closed
|
|
|
|
expect(note.noteable.labels).to match_array(labels)
|
2017-05-04 12:11:15 +00:00
|
|
|
expect(note.noteable.assignees).to eq([assignee])
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable.milestone).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-17 23:58:52 +00:00
|
|
|
describe '/reopen' do
|
2016-08-09 17:26:45 +00:00
|
|
|
before do
|
|
|
|
note.noteable.close
|
|
|
|
expect(note.noteable).to be_closed
|
|
|
|
end
|
2016-08-17 23:58:52 +00:00
|
|
|
let(:note_text) { "HELLO\n/reopen\nWORLD" }
|
2016-08-09 17:26:45 +00:00
|
|
|
|
|
|
|
it 'opens the noteable' do
|
2016-08-13 16:58:51 +00:00
|
|
|
content, command_params = service.extract_commands(note)
|
|
|
|
service.execute(command_params, note)
|
2016-08-09 17:26:45 +00:00
|
|
|
|
2016-08-13 16:58:51 +00:00
|
|
|
expect(content).to eq "HELLO\nWORLD"
|
2016-08-09 17:26:45 +00:00
|
|
|
expect(note.noteable).to be_open
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-20 08:23:13 +00:00
|
|
|
describe '.noteable_update_service' do
|
|
|
|
include_context 'note on noteable'
|
|
|
|
|
|
|
|
it 'returns Issues::UpdateService for a note on an issue' do
|
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
|
|
|
expect(described_class.noteable_update_service(note)).to eq(Issues::UpdateService)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns Issues::UpdateService for a note on a merge request' do
|
|
|
|
note = create(:note_on_merge_request, project: project)
|
|
|
|
|
|
|
|
expect(described_class.noteable_update_service(note)).to eq(MergeRequests::UpdateService)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for a note on a commit' do
|
|
|
|
note = create(:note_on_commit, project: project)
|
|
|
|
|
|
|
|
expect(described_class.noteable_update_service(note)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.supported?' do
|
|
|
|
include_context 'note on noteable'
|
|
|
|
|
|
|
|
let(:note) { create(:note_on_issue, project: project) }
|
|
|
|
|
2018-03-02 12:03:03 +00:00
|
|
|
context 'with a note on an issue' do
|
2016-09-20 08:23:13 +00:00
|
|
|
it 'returns true' do
|
2018-03-02 12:03:03 +00:00
|
|
|
expect(described_class.supported?(note)).to be_truthy
|
2016-09-20 08:23:13 +00:00
|
|
|
end
|
2018-03-02 12:03:03 +00:00
|
|
|
end
|
2016-09-20 08:23:13 +00:00
|
|
|
|
2018-03-02 12:03:03 +00:00
|
|
|
context 'with a note on a commit' do
|
|
|
|
let(:note) { create(:note_on_commit, project: project) }
|
2016-09-20 08:23:13 +00:00
|
|
|
|
2018-03-02 12:03:03 +00:00
|
|
|
it 'returns false' do
|
|
|
|
expect(described_class.supported?(note)).to be_falsy
|
2016-09-20 08:23:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#supported?' do
|
|
|
|
include_context 'note on noteable'
|
|
|
|
|
|
|
|
it 'delegates to the class method' do
|
2018-07-11 14:36:08 +00:00
|
|
|
service = described_class.new(project, maintainer)
|
2016-09-20 08:23:13 +00:00
|
|
|
note = create(:note_on_issue, project: project)
|
|
|
|
|
2018-03-02 12:03:03 +00:00
|
|
|
expect(described_class).to receive(:supported?).with(note)
|
2016-09-20 08:23:13 +00:00
|
|
|
|
|
|
|
service.supported?(note)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-09 17:26:45 +00:00
|
|
|
describe '#execute' do
|
2018-07-11 14:36:08 +00:00
|
|
|
let(:service) { described_class.new(project, maintainer) }
|
2016-08-13 16:58:51 +00:00
|
|
|
|
2017-05-31 05:50:53 +00:00
|
|
|
it_behaves_like 'note on noteable that supports quick actions' do
|
2016-08-09 17:26:45 +00:00
|
|
|
let(:note) { build(:note_on_issue, project: project) }
|
|
|
|
end
|
|
|
|
|
2017-05-31 05:50:53 +00:00
|
|
|
it_behaves_like 'note on noteable that supports quick actions' do
|
2016-08-09 17:26:45 +00:00
|
|
|
let(:note) { build(:note_on_merge_request, project: project) }
|
|
|
|
end
|
|
|
|
|
2017-05-31 05:50:53 +00:00
|
|
|
it_behaves_like 'note on noteable that does not support quick actions' do
|
2016-08-09 17:26:45 +00:00
|
|
|
let(:note) { build(:note_on_commit, project: project) }
|
|
|
|
end
|
|
|
|
end
|
2017-05-05 15:55:16 +00:00
|
|
|
|
|
|
|
context 'CE restriction for issue assignees' do
|
|
|
|
describe '/assign' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2018-07-11 14:36:08 +00:00
|
|
|
let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
|
2017-05-05 15:55:16 +00:00
|
|
|
let(:assignee) { create(:user) }
|
2018-07-11 14:36:08 +00:00
|
|
|
let(:maintainer) { create(:user) }
|
|
|
|
let(:service) { described_class.new(project, maintainer) }
|
2017-05-05 15:55:16 +00:00
|
|
|
let(:note) { create(:note_on_issue, note: note_text, project: project) }
|
|
|
|
|
|
|
|
let(:note_text) do
|
2018-07-11 14:36:08 +00:00
|
|
|
%(/assign @#{assignee.username} @#{maintainer.username}\n")
|
2017-05-05 15:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
project.add_maintainer(assignee)
|
2017-05-05 15:55:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds only one assignee from the list' do
|
2017-05-05 17:44:19 +00:00
|
|
|
_, command_params = service.extract_commands(note)
|
2017-05-05 15:55:16 +00:00
|
|
|
service.execute(command_params, note)
|
|
|
|
|
|
|
|
expect(note.noteable.assignees.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-09 17:26:45 +00:00
|
|
|
end
|