2016-11-15 15:50:27 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-16 12:28:38 -05:00
|
|
|
describe Gitlab::ChatCommands::IssueCreate, service: true do
|
2016-11-15 15:50:27 -05:00
|
|
|
describe '#execute' do
|
2016-11-17 09:30:04 -05:00
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:user) { create(:user) }
|
2016-11-16 12:28:38 -05:00
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
subject do
|
|
|
|
described_class.new(project, user).execute(regex_match)
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
|
|
|
|
context 'without description' do
|
|
|
|
it 'creates the issue' do
|
2016-11-17 09:30:04 -05:00
|
|
|
expect { subject }.to change { project.issues.count }.by(1)
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 09:30:04 -05:00
|
|
|
expect(subject.title).to eq('bird is the word')
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with description' do
|
|
|
|
let(:description) { "Surfin bird" }
|
2016-11-16 12:28:38 -05:00
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") }
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 09:30:04 -05:00
|
|
|
it 'creates the issue with description' do
|
2016-11-17 06:06:45 -05:00
|
|
|
subject
|
2016-11-15 15:50:27 -05:00
|
|
|
|
2016-11-17 06:06:45 -05:00
|
|
|
expect(Issue.last.description).to eq(description)
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 14:48:18 -05:00
|
|
|
|
|
|
|
context "with more newlines between the title and the description" do
|
|
|
|
let(:description) { "Surfin bird" }
|
|
|
|
let(:regex_match) { described_class.match("issue create bird is the word\n\n#{description}\n") }
|
|
|
|
|
|
|
|
it 'creates the issue' do
|
|
|
|
expect { subject }.to change { project.issues.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|
2016-11-17 06:06:45 -05:00
|
|
|
|
2016-11-18 05:38:54 -05:00
|
|
|
describe '.match' do
|
2016-11-17 06:06:45 -05:00
|
|
|
it 'matches the title without description' do
|
|
|
|
match = described_class.match("issue create my title")
|
|
|
|
|
|
|
|
expect(match[:title]).to eq('my title')
|
|
|
|
expect(match[:description]).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'matches the title with description' do
|
|
|
|
match = described_class.match("issue create my title\n\ndescription")
|
|
|
|
|
|
|
|
expect(match[:title]).to eq('my title')
|
|
|
|
expect(match[:description]).to eq('description')
|
|
|
|
end
|
|
|
|
end
|
2016-11-15 15:50:27 -05:00
|
|
|
end
|