container_tag_entity_spec.rb 1.14 KB
Newer Older
Kamil Trzcinski's avatar
Kamil Trzcinski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'spec_helper'

describe ContainerTagEntity do
  let(:entity) do
    described_class.new(tag, request: request)
  end

  set(:project) { create(:project) }
  set(:user) { create(:user) }
  set(:repository) { create(:container_repository, name: 'image', project: project) }

  let(:request) { double('request') }
  let(:tag) { repository.tag('test') }

  subject { entity.as_json }

  before do
    stub_container_registry_config(enabled: true)
    stub_container_registry_tags(repository: /image/, tags: %w[test])
    allow(request).to receive(:project).and_return(project)
    allow(request).to receive(:current_user).and_return(user)
  end

  it 'exposes required informations'  do
25
    expect(subject).to include(:name, :location, :revision, :short_revision, :total_size, :created_at)
Kamil Trzcinski's avatar
Kamil Trzcinski committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  end

  context 'when user can manage repositories' do
    before do
      project.add_developer(user)
    end

    it 'exposes destroy_path' do
      expect(subject).to include(:destroy_path)
    end
  end

  context 'when user cannot manage repositories' do
    it 'does not expose destroy_path' do
      expect(subject).not_to include(:destroy_path)
    end
  end
end