summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-30 13:31:33 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-30 13:31:33 +0200
commit031122eb54390b4ed792289237ecfb156ec69002 (patch)
treeee16229945c93ff3178e22b8239b8fffd2846e06 /spec/services
parent4407d3cf19bc815142ea3a7908003e85efde76ed (diff)
downloadgitlab-ce-031122eb54390b4ed792289237ecfb156ec69002.tar.gz
Add container repository create service with specs
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/container_registry/create_repository_service_spec.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/services/container_registry/create_repository_service_spec.rb b/spec/services/container_registry/create_repository_service_spec.rb
new file mode 100644
index 00000000000..dfd07c8cc02
--- /dev/null
+++ b/spec/services/container_registry/create_repository_service_spec.rb
@@ -0,0 +1,74 @@
+require 'spec_helper'
+
+describe ContainerRegistry::CreateRepositoryService, '#execute' do
+ let(:project) { create(:empty_project) }
+ let(:user) { create(:user) }
+
+ let(:path) do
+ ContainerRegistry::Path.new("#{project.full_path}/my/image")
+ end
+
+ let(:service) { described_class.new(project, user) }
+
+ before do
+ stub_container_registry_config(enabled: true)
+ end
+
+ context 'when container repository already exists' do
+ before do
+ create(:container_repository, project: project, name: 'my/image')
+ end
+
+ it 'does not create container repository again' do
+ expect { service.execute(path) }
+ .to raise_error(Gitlab::Access::AccessDeniedError)
+ .and change { ContainerRepository.count }.by(0)
+ end
+ end
+
+ context 'when repository is created by an user' do
+ context 'when user has no ability to create a repository' do
+ it 'does not create a new container repository' do
+ expect { service.execute(path) }
+ .to raise_error(Gitlab::Access::AccessDeniedError)
+ .and change { ContainerRepository.count }.by(0)
+ end
+ end
+
+ context 'when user has ability do create a repository' do
+ before do
+ project.add_developer(user)
+ end
+
+ it 'creates a new container repository' do
+ expect { service.execute(path) }
+ .to change { project.container_repositories.count }.by(1)
+ end
+ end
+ end
+
+ context 'when repository is created by a legacy pipeline trigger' do
+ let(:user) { nil }
+
+ context 'when repository path matches authenticated project' do
+ it 'creates a new container repository' do
+ expect { service.execute(path) }
+ .to change { project.container_repositories.count }.by(1)
+ end
+ end
+
+ context 'when repository path does not match authenticated project' do
+ let(:private_project) { create(:empty_project, :private) }
+
+ let(:path) do
+ ContainerRegistry::Path.new("#{private_project.full_path}/my/image")
+ end
+
+ it 'does not create a new container repository' do
+ expect { service.execute(path) }
+ .to raise_error(Gitlab::Access::AccessDeniedError)
+ .and change { ContainerRepository.count }.by(0)
+ end
+ end
+ end
+end