issue_new_spec.rb 2.26 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::SlashCommands::IssueNew do
4
  describe '#execute' do
5
    let(:project) { create(:project) }
6
    let(:user) { create(:user) }
7
    let(:regex_match) { described_class.match("issue create bird is the word") }
8

9 10 11
    before do
      project.team << [user, :master]
    end
12

13 14 15
    subject do
      described_class.new(project, user).execute(regex_match)
    end
16 17 18

    context 'without description' do
      it 'creates the issue' do
19
        expect { subject }.to change { project.issues.count }.by(1)
20

21
        expect(subject[:response_type]).to be(:in_channel)
22 23 24 25 26
      end
    end

    context 'with description' do
      let(:description) { "Surfin bird" }
27
      let(:regex_match) { described_class.match("issue create bird is the word\n#{description}") }
28

29
      it 'creates the issue with description' do
30
        subject
31

32
        expect(Issue.last.description).to eq(description)
33 34
      end
    end
35 36 37 38 39 40 41 42 43

    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
44 45 46 47 48 49 50 51 52 53

    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
54
  end
55

56
  describe '.match' do
57 58 59 60 61 62 63 64 65 66 67 68 69
    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
70 71 72 73 74 75 76

    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
77
  end
78
end