File: candidate_presenter_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (56 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ml::CandidatePresenter, feature_category: :mlops do
  let_it_be(:project) { build_stubbed(:project) }
  let_it_be(:regular_candidate) { build_stubbed(:ml_candidates, :with_artifact, internal_id: 1, project: project) }
  let_it_be(:model_version) { build_stubbed(:ml_model_versions, :with_package, project: project) }
  let_it_be(:model_version_candidate) { model_version.candidate }
  let_it_be(:user) { project.owner }
  let_it_be(:pipeline) { build_stubbed(:ci_pipeline, project: project, user: user) }
  let_it_be(:build) { regular_candidate.ci_build = build_stubbed(:ci_build, pipeline: pipeline, user: user) }

  let(:candidate) { regular_candidate }

  subject(:presenter) { candidate.present(current_user: user) }

  describe '#path' do
    subject { presenter.path }

    it { is_expected.to eq("/#{project.full_path}/-/ml/candidates/#{candidate.iid}") }
  end

  describe '#artifact_show_path' do
    subject { presenter.artifact_show_path }

    context 'when candidate is not part of model a version' do
      it { is_expected.to eq("/#{project.full_path}/-/packages/#{candidate.package_id}") }
    end

    context 'when candidate is part of model version' do
      let(:candidate) { model_version_candidate }

      it { is_expected.to eq("/#{project.full_path}/-/packages/#{model_version.package_id}") }
    end
  end

  describe '#ci_build' do
    subject { presenter.ci_build }

    context 'when candidate is associated to job' do
      it { is_expected.to eq(build) }

      context 'when ci job is not to be added' do
        before do
          allow(Ability).to receive(:allowed?).and_call_original
          allow(Ability).to receive(:allowed?)
                              .with(user, :read_build, build)
                              .and_return(false)
        end

        it { is_expected.to be_nil }
      end
    end
  end
end