File: base_container_service_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 (51 lines) | stat: -rw-r--r-- 1,417 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BaseContainerService, feature_category: :container_registry do
  let_it_be(:group) { build_stubbed(:group) }
  let_it_be(:subgroup) { build_stubbed(:group, parent: group) }
  let_it_be(:project) { build_stubbed(:project, group: group) }
  let_it_be(:user) { User.new }

  let(:container) { project }

  subject(:instance) { described_class.new(container: container, current_user: user) }

  describe '#initialize' do
    it 'accepts container and current_user' do
      expect(instance.container).to eq(project)
      expect(instance.current_user).to eq(user)
    end

    it 'treats current_user as optional' do
      instance = described_class.new(container: project)

      expect(instance.current_user).to be_nil
    end
  end

  describe '.root_ancestor' do
    context 'when container is a group' do
      let(:container) { subgroup }

      it 'returns the top level group' do
        expect(instance.root_ancestor).to eq(group)
      end
    end

    context 'when container is a project' do
      it 'returns the project top level group' do
        expect(instance.root_ancestor).to eq(group)
      end

      context 'when the project does not belong to a group' do
        let(:container) { build_stubbed(:project) }

        it 'returns nil' do
          expect(instance.root_ancestor).to be_nil
        end
      end
    end
  end
end