File: runner_namespace_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 (61 lines) | stat: -rw-r--r-- 2,010 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
57
58
59
60
61
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::RunnerNamespace, feature_category: :runner do
  it_behaves_like 'includes Limitable concern' do
    let_it_be(:group) { create(:group, :nested) }
    let_it_be(:another_group) { create(:group) }
    let_it_be(:runner) { create(:ci_runner, :group, groups: [another_group]) }

    subject { build(:ci_runner_namespace, namespace: group, runner: runner) }
  end

  it_behaves_like 'cleanup by a loose foreign key' do
    let!(:parent) { create(:group) }
    let!(:runner) { create(:ci_runner, :group, groups: [parent]) }
    let(:model) { runner.runner_namespaces.first }
  end

  describe 'validations' do
    let_it_be(:runner) { create(:ci_runner, :group, groups: [create(:group)]) }

    it { is_expected.to validate_presence_of(:namespace).on([:create, :update]) }
    it { is_expected.to validate_uniqueness_of(:runner_id).scoped_to(:namespace_id) }

    it 'validates that runner_id is valid' do
      runner_namespace = runner.runner_namespaces.first
      runner_namespace.runner_id = nil
      expect(runner_namespace).not_to be_valid
    end
  end

  describe 'associations' do
    it { is_expected.to belong_to(:runner) }
    it { is_expected.to belong_to(:namespace) }
    it { is_expected.to belong_to(:group).class_name('::Group').with_foreign_key(:namespace_id) }
  end

  describe '.for_runner' do
    subject(:for_runner) { described_class.for_runner(runner_ids) }

    let_it_be(:group) { create(:group) }
    let_it_be(:runners) { create_list(:ci_runner, 3, :group, groups: [group]) }

    context 'with runner ids' do
      let(:runner_ids) { runners[1..2].map(&:id) }

      it 'returns requested runner namespaces' do
        is_expected.to eq(runners[1..2].flat_map(&:runner_namespaces))
      end
    end

    context 'with runners' do
      let(:runner_ids) { runners.first }

      it 'returns requested runner namespaces' do
        is_expected.to eq(runners.first.runner_namespaces)
      end
    end
  end
end