summaryrefslogtreecommitdiff
path: root/spec/services/ci/image_for_build_service_spec.rb
blob: 0a50347a7c5077fe1e6d46a8059d9ad2b94652e6 (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
require 'spec_helper'

module Ci
  describe ImageForBuildService, services: true do
    let(:service) { ImageForBuildService.new }
    let(:project) { FactoryGirl.create(:empty_project) }
    let(:commit_sha) { '01234567890123456789' }
    let(:pipeline) { project.ensure_pipeline('master', commit_sha) }
    let(:build) { FactoryGirl.create(:ci_build, pipeline: pipeline) }

    before do
      stub_ci_pipeline_hooks
    end

    describe '#execute' do
      before { build }

      context 'branch name' do
        before { allow(project).to receive(:commit).and_return(OpenStruct.new(sha: commit_sha)) }
        before { build.run! }
        let(:image) { service.execute(project, ref: 'master') }

        it { expect(image).to be_kind_of(OpenStruct) }
        it { expect(image.path.to_s).to include('public/ci/build-running.svg') }
        it { expect(image.name).to eq('build-running.svg') }
      end

      context 'unknown branch name' do
        let(:image) { service.execute(project, ref: 'feature') }

        it { expect(image).to be_kind_of(OpenStruct) }
        it { expect(image.path.to_s).to include('public/ci/build-unknown.svg') }
        it { expect(image.name).to eq('build-unknown.svg') }
      end

      context 'commit sha' do
        before { build.run! }
        let(:image) { service.execute(project, sha: build.sha) }

        it { expect(image).to be_kind_of(OpenStruct) }
        it { expect(image.path.to_s).to include('public/ci/build-running.svg') }
        it { expect(image.name).to eq('build-running.svg') }
      end

      context 'unknown commit sha' do
        let(:image) { service.execute(project, sha: '0000000') }

        it { expect(image).to be_kind_of(OpenStruct) }
        it { expect(image.path.to_s).to include('public/ci/build-unknown.svg') }
        it { expect(image.name).to eq('build-unknown.svg') }
      end
    end
  end
end