summaryrefslogtreecommitdiff
path: root/spec/presenters/ci/stage_presenter_spec.rb
blob: 368f03b01505f751c7892b347de88cd364815876 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::StagePresenter do
  let(:stage) { create(:ci_stage) }
  let(:presenter) { described_class.new(stage) }

  let!(:build) { create(:ci_build, :tags, :artifacts, pipeline: stage.pipeline, stage: stage.name) }
  let!(:retried_build) { create(:ci_build, :tags, :artifacts, :retried, pipeline: stage.pipeline, stage: stage.name) }

  before do
    create(:generic_commit_status, pipeline: stage.pipeline, stage: stage.name)
  end

  shared_examples 'preloaded associations for CI status' do
    it 'preloads project' do
      expect(presented_stage.association(:project)).to be_loaded
    end

    it 'preloads build pipeline' do
      expect(presented_stage.association(:pipeline)).to be_loaded
    end

    it 'preloads build tags' do
      expect(presented_stage.association(:tags)).to be_loaded
    end

    it 'preloads build artifacts archive' do
      expect(presented_stage.association(:job_artifacts_archive)).to be_loaded
    end

    it 'preloads build artifacts metadata' do
      expect(presented_stage.association(:metadata)).to be_loaded
    end
  end

  describe '#latest_ordered_statuses' do
    subject(:presented_stage) { presenter.latest_ordered_statuses.second }

    it_behaves_like 'preloaded associations for CI status'
  end

  describe '#retried_ordered_statuses' do
    subject(:presented_stage) { presenter.retried_ordered_statuses.first }

    it_behaves_like 'preloaded associations for CI status'
  end
end