summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import/label_formatter_spec.rb
blob: 565435824fd14d77bb02f1aa89756bb3c288a869 (plain)
1
2
3
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
require 'spec_helper'

describe Gitlab::GithubImport::LabelFormatter, lib: true do
  let(:project) { create(:empty_project) }
  let(:raw) { double(name: 'improvements', color: 'e6e6e6') }

  subject { described_class.new(project, raw) }

  describe '#attributes' do
    it 'returns formatted attributes' do
      expect(subject.attributes).to eq({
        project: project,
        title: 'improvements',
        color: '#e6e6e6'
      })
    end
  end

  describe '#create!' do
    context 'when label does not exist' do
      it 'creates a new label' do
        expect { subject.create! }.to change(Label, :count).by(1)
      end
    end

    context 'when label exists' do
      it 'does not create a new label' do
        Labels::CreateService.new(name: raw.name).execute(project: project)

        expect { subject.create! }.not_to change(Label, :count)
      end
    end
  end
end