summaryrefslogtreecommitdiff
path: root/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
blob: 9c187bead0a9e4be1d54745df95f6a69a3a81387 (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
70
71
72
73
require 'spec_helper'

describe Gitlab::GithubImport::ObjectImporter do
  let(:worker) do
    Class.new do
      def self.name
        'DummyWorker'
      end

      include(Gitlab::GithubImport::ObjectImporter)

      def counter_name
        :dummy_counter
      end

      def counter_description
        'This is a counter'
      end
    end.new
  end

  describe '#import' do
    it 'imports the object' do
      representation_class = double(:representation_class)
      importer_class = double(:importer_class)
      importer_instance = double(:importer_instance)
      representation = double(:representation)
      project = double(:project, full_path: 'foo/bar')
      client = double(:client)

      expect(worker)
        .to receive(:representation_class)
        .and_return(representation_class)

      expect(worker)
        .to receive(:importer_class)
        .and_return(importer_class)

      expect(representation_class)
        .to receive(:from_json_hash)
        .with(an_instance_of(Hash))
        .and_return(representation)

      expect(importer_class)
        .to receive(:new)
        .with(representation, project, client)
        .and_return(importer_instance)

      expect(importer_instance)
        .to receive(:execute)

      expect(worker.counter)
        .to receive(:increment)
        .and_call_original

      worker.import(project, client, { 'number' => 10 })
    end
  end

  describe '#counter' do
    it 'returns a Prometheus counter' do
      expect(worker)
        .to receive(:counter_name)
        .and_call_original

      expect(worker)
        .to receive(:counter_description)
        .and_call_original

      worker.counter
    end
  end
end