Commit 60cdd2bc authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for container repository factory method

parent a7466af3
...@@ -58,7 +58,7 @@ class ContainerRepository < ActiveRecord::Base ...@@ -58,7 +58,7 @@ class ContainerRepository < ActiveRecord::Base
end end
end end
def self.create_from_path(path) def self.create_from_path!(path)
self.create(project: path.repository_project, self.create(project: path.repository_project,
name: path.repository_name) name: path.repository_name)
end end
......
...@@ -94,7 +94,7 @@ module Auth ...@@ -94,7 +94,7 @@ module Auth
return if path.has_repository? return if path.has_repository?
return unless actions.include?('push') return unless actions.include?('push')
ContainerRepository.create_from_path(path) ContainerRepository.create_from_path!(path)
end end
def can_access?(requested_project, requested_action) def can_access?(requested_project, requested_action)
......
...@@ -85,28 +85,63 @@ describe ContainerRepository do ...@@ -85,28 +85,63 @@ describe ContainerRepository do
end end
end end
describe '#from_repository_path' do describe '.create_from_path!' do
let(:repository) do
described_class.create_from_path!(ContainerRegistry::Path.new(path))
end
let(:repository_path) { ContainerRegistry::Path.new(path) }
context 'when received multi-level repository path' do context 'when received multi-level repository path' do
let(:repository) do let(:path) { project.full_path + '/some/image' }
described_class.from_repository_path('group/test/some/image/name')
end
pending 'fabricates object within a correct project' do it 'fabricates repository assigned to a correct project' do
expect(repository.project).to eq project expect(repository.project).to eq project
end end
pending 'it fabricates project with a correct name' do it 'fabricates repository with a correct name' do
expect(repository.name).to eq 'some/image/name' expect(repository.name).to eq 'some/image'
end end
end end
context 'when path contains too many nodes' do context 'when path is too long' do
let(:path) do
project.full_path + '/a/b/c/d/e/f/g/h/i/j/k/l/n/o/p/s/t/u/x/y/z'
end
it 'does not create repository and raises error' do
expect { repository }.to raise_error(
ContainerRegistry::Path::InvalidRegistryPathError)
end
end end
context 'when received multi-level repository with nested groups' do context 'when received multi-level repository with nested groups' do
let(:group) { create(:group, :nested, name: 'nested') }
let(:path) { project.full_path + '/some/image' }
it 'fabricates repository assigned to a correct project' do
expect(repository.project).to eq project
end
it 'fabricates repository with a correct name' do
expect(repository.name).to eq 'some/image'
end
it 'has path including a nested group' do
expect(repository.path).to include 'nested/test/some/image'
end
end end
context 'when received root repository path' do context 'when received root repository path' do
let(:path) { project.full_path }
it 'fabricates repository assigned to a correct project' do
expect(repository.project).to eq project
end
it 'fabricates repository with an empty name' do
expect(repository.name).to be_empty
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment