issuable_create_service_slash_commands_shared_examples.rb 2.13 KB
Newer Older
1
2
3
# Specifications for behavior common to all objects with executable attributes.
# It can take a `default_params`.

4
shared_examples 'new issuable record that supports quick actions' do
5
  let!(:project) { create(:project, :repository) }
6
  let(:user) { create(:user).tap { |u| project.add_maintainer(u) } }
7
8
9
  let(:assignee) { create(:user) }
  let!(:milestone) { create(:milestone, project: project) }
  let!(:labels) { create_list(:label, 3, project: project) }
10
  let(:base_params) { { title: 'My issuable title' } }
11
12
13
  let(:params) { base_params.merge(defined?(default_params) ? default_params : {}).merge(example_params) }
  let(:issuable) { described_class.new(project, user, params).execute }

14
  before do
15
    project.add_maintainer(assignee)
16
  end
17

18
19
20
  context 'with labels in command only' do
    let(:example_params) do
      {
Douwe Maan's avatar
Douwe Maan committed
21
        description: "/label ~#{labels.first.name} ~#{labels.second.name}\n/unlabel ~#{labels.third.name}"
22
23
24
25
26
27
28
29
30
31
32
33
34
      }
    end

    it 'attaches labels to issuable' do
      expect(issuable).to be_persisted
      expect(issuable.label_ids).to match_array([labels.first.id, labels.second.id])
    end
  end

  context 'with labels in params and command' do
    let(:example_params) do
      {
        label_ids: [labels.second.id],
Douwe Maan's avatar
Douwe Maan committed
35
        description: "/label ~#{labels.first.name}\n/unlabel ~#{labels.third.name}"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      }
    end

    it 'attaches all labels to issuable' do
      expect(issuable).to be_persisted
      expect(issuable.label_ids).to match_array([labels.first.id, labels.second.id])
    end
  end

  context 'with assignee and milestone in command only' do
    let(:example_params) do
      {
        description: %(/assign @#{assignee.username}\n/milestone %"#{milestone.name}")
      }
    end

    it 'assigns and sets milestone to issuable' do
      expect(issuable).to be_persisted
54
      expect(issuable.assignees).to eq([assignee])
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
      expect(issuable.milestone).to eq(milestone)
    end
  end

  describe '/close' do
    let(:example_params) do
      {
        description: '/close'
      }
    end

    it 'returns an open issue' do
      expect(issuable).to be_persisted
      expect(issuable).to be_open
    end
  end
end