Welcome to mirror list, hosted at ThFree Co, Russian Federation.

label_links_importer_spec.rb « importer « github_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e005d8eda844b293612b8cd8656b174d010a1285 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GithubImport::Importer::LabelLinksImporter do
  let(:project) { create(:project) }
  let(:client) { double(:client) }
  let(:issue) do
    double(
      :issue,
      iid: 4,
      label_names: %w[bug],
      issuable_type: Issue,
      pull_request?: false
    )
  end

  let(:importer) { described_class.new(issue, project, client) }

  describe '#execute' do
    it 'creates the label links' do
      importer = described_class.new(issue, project, client)

      expect(importer).to receive(:create_labels)

      importer.execute
    end
  end

  describe '#create_labels' do
    it 'inserts the label links in bulk' do
      expect(importer.label_finder)
        .to receive(:id_for)
        .with('bug')
        .and_return(2)

      expect(importer)
        .to receive(:find_target_id)
        .and_return(4)

      expect(LabelLink).to receive(:bulk_insert!)

      importer.create_labels
    end

    it 'does not insert label links for non-existing labels' do
      expect(importer.label_finder)
        .to receive(:id_for)
        .with('bug')
        .and_return(nil)

      expect(LabelLink)
        .to receive(:bulk_insert!)
        .with([])

      importer.create_labels
    end
  end

  describe '#find_target_id' do
    it 'returns the ID of the issuable to create the label link for' do
      expect_next_instance_of(Gitlab::GithubImport::IssuableFinder) do |instance|
        expect(instance).to receive(:database_id).and_return(10)
      end

      expect(importer.find_target_id).to eq(10)
    end
  end
end