debian-mirror-gitlab/spec/lib/gitlab/slash_commands/issue_new_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.3 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::SlashCommands::IssueNew do
2017-08-17 22:00:37 +05:30
describe '#execute' do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2018-03-27 19:54:05 +05:30
let(:chat_name) { double(:chat_name, user: user) }
2017-08-17 22:00:37 +05:30
let(:regex_match) { described_class.match("issue create bird is the word") }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-08-17 22:00:37 +05:30
end
subject do
2018-03-27 19:54:05 +05:30
described_class.new(project, chat_name).execute(regex_match)
2017-08-17 22:00:37 +05:30
end
context 'without description' do
it 'creates the issue' do
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}") }
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
2019-03-02 22:35:43 +05:30
let!(:issue) { create(:issue, project: project, title: 'bird is the word') }
2017-08-17 22:00:37 +05:30
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
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