gitlab-org--gitlab-foss/spec/lib/gitlab/slash_commands/issue_new_spec.rb

79 lines
2.3 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe Gitlab::SlashCommands::IssueNew do
describe '#execute' do
let(:project) { create(:project) }
2016-11-17 09:30:04 -05:00
let(:user) { create(:user) }
let(:regex_match) { described_class.match("issue create bird is the word") }
before do
project.team << [user, :master]
end
subject do
described_class.new(project, user).execute(regex_match)
end
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)
expect(subject[:response_type]).to be(:in_channel)
end
end
context 'with description' do
let(:description) { "Surfin bird" }
let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") }
2016-11-17 09:30:04 -05:00
it 'creates the issue with description' do
subject
expect(Issue.last.description).to eq(description)
end
end
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
context 'issue cannot be created' do
let!(:issue) { create(:issue, project: project, title: 'bird is the word') }
let(:regex_match) { described_class.match("issue create #{'a' * 512}}") }
it 'displays the errors' do
expect(subject[:response_type]).to be(:ephemeral)
expect(subject[:text]).to match("- Title is too long")
end
end
end
2016-11-18 05:38:54 -05:00
describe '.match' do
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
it 'matches the alias new' do
match = described_class.match("issue new my title")
expect(match).not_to be_nil
expect(match[:title]).to eq('my title')
end
end
end