diff options
author | Rémy Coutable <remy@rymai.me> | 2016-08-09 19:26:45 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-08-13 00:06:11 +0200 |
commit | 7cc4ab14b8a2f1d7d374a320b79374764527659f (patch) | |
tree | 6dfd4067d98db291f9b8f5db05909967e0c7cd27 /spec/services/notes | |
parent | a54fdc384fee9daeab1b9fb638dae5dce4e4be15 (diff) | |
download | gitlab-ce-7cc4ab14b8a2f1d7d374a320b79374764527659f.tar.gz |
New Notes::SlashCommandsService service
Check for update_issuable permission in Notes::SlashCommandsService
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/services/notes')
-rw-r--r-- | spec/services/notes/create_service_spec.rb | 23 | ||||
-rw-r--r-- | spec/services/notes/slash_commands_service_spec.rb | 129 |
2 files changed, 143 insertions, 9 deletions
diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 36ca7d2bce8..92dbccf0729 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -9,25 +9,30 @@ describe Notes::CreateService, services: true do end describe '#execute' do + before do + project.team << [user, :master] + end + context "valid params" do before do - project.team << [user, :master] @note = Notes::CreateService.new(project, user, opts).execute end it { expect(@note).to be_valid } it { expect(@note.note).to eq(opts[:note]) } + end - it_behaves_like 'note on noteable that supports slash commands' do - let(:noteable) { create(:issue, project: project) } - end + describe 'note with commands' do + describe '/close, /label, /assign & /milestone' do + let(:note_text) { %(HELLO\n/close\n/assign @#{user.username}\nWORLD) } - it_behaves_like 'note on noteable that supports slash commands' do - let(:noteable) { create(:merge_request, source_project: project) } - end + it 'saves the note and does not alter the note text' do + expect_any_instance_of(Issues::UpdateService).to receive(:execute).and_call_original + + note = described_class.new(project, user, opts.merge(note: note_text)).execute - it_behaves_like 'note on noteable that does not support slash commands' do - let(:noteable) { create(:commit, project: project) } + expect(note.note).to eq "HELLO\nWORLD" + end end end end diff --git a/spec/services/notes/slash_commands_service_spec.rb b/spec/services/notes/slash_commands_service_spec.rb new file mode 100644 index 00000000000..5632ec09834 --- /dev/null +++ b/spec/services/notes/slash_commands_service_spec.rb @@ -0,0 +1,129 @@ +require 'spec_helper' + +describe Notes::SlashCommandsService, services: true do + shared_context 'note on noteable' do + let(:project) { create(:empty_project) } + let(:master) { create(:user).tap { |u| project.team << [u, :master] } } + let(:assignee) { create(:user) } + end + + shared_examples 'note on noteable that does not support slash commands' do + include_context 'note on noteable' + + before do + note.note = note_text + described_class.new(project, master).execute(note) + 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 + expect(note.note).to eq note_text + 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 + expect(note.note).to eq note_text + end + end + end + end + + shared_examples 'note on noteable that supports slash commands' do + 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 + described_class.new(project, master).execute(note) + + expect(note.note).to eq '' + expect(note.noteable).to be_closed + expect(note.noteable.labels).to match_array(labels) + expect(note.noteable.assignee).to eq(assignee) + expect(note.noteable.milestone).to eq(milestone) + end + end + + describe '/open' do + before do + note.noteable.close! + expect(note.noteable).to be_closed + end + let(:note_text) { '/open' } + + it 'opens the noteable, and leave no note' do + described_class.new(project, master).execute(note) + + expect(note.note).to eq '' + expect(note.noteable).to be_open + end + end + 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 + described_class.new(project, master).execute(note) + + expect(note.note).to eq "HELLO\nWORLD" + expect(note.noteable).to be_closed + expect(note.noteable.labels).to match_array(labels) + expect(note.noteable.assignee).to eq(assignee) + expect(note.noteable.milestone).to eq(milestone) + end + end + + describe '/open' do + before do + note.noteable.close + expect(note.noteable).to be_closed + end + let(:note_text) { "HELLO\n/open\nWORLD" } + + it 'opens the noteable' do + described_class.new(project, master).execute(note) + + expect(note.note).to eq "HELLO\nWORLD" + expect(note.noteable).to be_open + end + end + end + end + + describe '#execute' do + it_behaves_like 'note on noteable that supports slash commands' do + let(:note) { build(:note_on_issue, project: project) } + end + + it_behaves_like 'note on noteable that supports slash commands' do + let(:note) { build(:note_on_merge_request, project: project) } + end + + it_behaves_like 'note on noteable that does not support slash commands' do + let(:note) { build(:note_on_commit, project: project) } + end + end +end |