find_or_create_service_spec.rb 1.37 KB
Newer Older
1
2
require 'spec_helper'

3
describe Labels::FindOrCreateService, services: true do
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  describe '#execute' do
    let(:user)    { create(:user) }
    let(:group)   { create(:group) }
    let(:project) { create(:project, namespace: group) }

    let(:params) do
      {
        title: 'Security',
        description: 'Security related stuff.',
        color: '#FF0000'
      }
    end

    subject(:service) { described_class.new(user, project, params) }

    before do
      project.team << [user, :developer]
    end

    context 'when label does not exist at group level' do
      it 'creates a new label at project level' do
        expect { service.execute }.to change(project.labels, :count).by(1)
      end
    end

    context 'when label exists at group level' do
      it 'returns the group label' do
        group_label = create(:group_label, group: group, title: 'Security')

        expect(service.execute).to eq group_label
      end
    end

    context 'when label does not exist at group level' do
      it 'creates a new label at project leve' do
        expect { service.execute }.to change(project.labels, :count).by(1)
      end
    end

    context 'when label exists at project level' do
      it 'returns the project label' do
        project_label = create(:label, project: project, title: 'Security')

        expect(service.execute).to eq project_label
      end
    end
  end
end