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

82 lines
2.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
2015-12-23 02:04:40 +05:30
describe Notes::CreateService, services: true do
2014-09-02 18:07:02 +05:30
let(:project) { create(:empty_project) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
2016-09-13 17:45:13 +05:30
let(:opts) do
{ note: 'Awesome comment', noteable_type: 'Issue', noteable_id: issue.id }
end
2014-09-02 18:07:02 +05:30
2016-08-24 12:49:21 +05:30
describe '#execute' do
2016-09-13 17:45:13 +05:30
before do
project.team << [user, :master]
end
2014-09-02 18:07:02 +05:30
context "valid params" do
before do
@note = Notes::CreateService.new(project, user, opts).execute
end
2015-04-26 12:48:37 +05:30
it { expect(@note).to be_valid }
2016-09-13 17:45:13 +05:30
it { expect(@note.note).to eq(opts[:note]) }
end
describe 'note with commands' do
describe '/close, /label, /assign & /milestone' do
let(:note_text) { %(HELLO\n/close\n/assign @#{user.username}\nWORLD) }
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
expect(note.note).to eq "HELLO\nWORLD"
end
end
2014-09-02 18:07:02 +05:30
end
end
2015-11-26 14:37:03 +05:30
describe "award emoji" do
before do
project.team << [user, :master]
end
it "creates an award emoji" do
2015-11-26 14:37:03 +05:30
opts = {
note: ':smile: ',
noteable_type: 'Issue',
noteable_id: issue.id
}
note = Notes::CreateService.new(project, user, opts).execute
2015-11-26 14:37:03 +05:30
expect(note).to be_valid
expect(note.name).to eq('smile')
2015-11-26 14:37:03 +05:30
end
it "creates regular note if emoji name is invalid" do
opts = {
2016-09-13 17:45:13 +05:30
note: ':smile: moretext:',
2015-11-26 14:37:03 +05:30
noteable_type: 'Issue',
noteable_id: issue.id
}
note = Notes::CreateService.new(project, user, opts).execute
expect(note).to be_valid
expect(note.note).to eq(opts[:note])
end
it "normalizes the emoji name" do
opts = {
note: ':+1:',
noteable_type: 'Issue',
noteable_id: issue.id
}
2015-11-26 14:37:03 +05:30
expect_any_instance_of(TodoService).to receive(:new_award_emoji).with(issue, user)
2015-11-26 14:37:03 +05:30
Notes::CreateService.new(project, user, opts).execute
2015-11-26 14:37:03 +05:30
end
end
2014-09-02 18:07:02 +05:30
end