diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-24 14:41:42 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-03-24 14:41:42 +0300 |
commit | 7db1f22673f1b6890b6ce4b9db9b367eae3988f0 (patch) | |
tree | 31ebf5e0a4a841082c0e600261d04d00ce9fb701 /spec | |
parent | af42dd29a0e81d524731f4ce3ced2ed17bac9903 (diff) |
Fix specs for services related to container registry
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/container_images/destroy_service_spec.rb | 66 | ||||
-rw-r--r-- | spec/services/projects/destroy_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/projects/transfer_service_spec.rb | 2 |
3 files changed, 39 insertions, 31 deletions
diff --git a/spec/services/container_images/destroy_service_spec.rb b/spec/services/container_images/destroy_service_spec.rb index ebc15598cce..ab5ebe5eac8 100644 --- a/spec/services/container_images/destroy_service_spec.rb +++ b/spec/services/container_images/destroy_service_spec.rb @@ -1,34 +1,42 @@ require 'spec_helper' -describe ContainerImages::DestroyService, services: true do - describe '#execute' do - let(:user) { create(:user) } - let(:container_repository) { create(:container_repository, name: '') } - let(:project) { create(:project, path: 'test', namespace: user.namespace, container_repositorys: [container_repository]) } - let(:example_host) { 'example.com' } - let(:registry_url) { 'http://' + example_host } - - it { expect(container_repository).to be_valid } - it { expect(project.container_repositorys).not_to be_empty } - - context 'when container image has tags' do - before do - project.team << [user, :master] - end - - it 'removes all tags before destroy' do - service = described_class.new(project, user) - - expect(container_repository).to receive(:delete_tags).and_return(true) - expect { service.execute(container_repository) }.to change(project.container_repositorys, :count).by(-1) - end - - it 'fails when tags are not removed' do - service = described_class.new(project, user) - - expect(container_repository).to receive(:delete_tags).and_return(false) - expect { service.execute(container_repository) }.to raise_error(ActiveRecord::RecordNotDestroyed) - end +describe ContainerImages::DestroyService, '#execute', :services do + let(:user) { create(:user) } + + let(:container_repository) do + create(:container_repository, name: 'myimage', tags: %w[latest]) + end + + let(:project) do + create(:project, path: 'test', + namespace: user.namespace, + container_repositories: [container_repository]) + end + + it { expect(container_repository).to be_valid } + it { expect(project.container_repositories).not_to be_empty } + + context 'when container image has tags' do + before do + project.add_master(user) + end + + it 'removes all tags before destroy' do + service = described_class.new(project, user) + + expect(container_repository) + .to receive(:delete_tags).and_return(true) + expect { service.execute(container_repository) } + .to change(project.container_repositories, :count).by(-1) + end + + it 'fails when tags are not removed' do + service = described_class.new(project, user) + + expect(container_repository) + .to receive(:delete_tags).and_return(false) + expect { service.execute(container_repository) } + .to raise_error(ActiveRecord::RecordNotDestroyed) end end end diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index daad65d478a..44e0286350b 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -95,7 +95,7 @@ describe Projects::DestroyService, services: true do before do stub_container_registry_config(enabled: true) stub_container_registry_tags('tag') - project.container_repositorys << container_repository + project.container_repositories << container_repository end context 'images deletion succeeds' do diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb index adf8ede5086..a3babaf1e0b 100644 --- a/spec/services/projects/transfer_service_spec.rb +++ b/spec/services/projects/transfer_service_spec.rb @@ -34,7 +34,7 @@ describe Projects::TransferService, services: true do before do stub_container_registry_config(enabled: true) stub_container_registry_tags('tag') - project.container_repositorys << container_repository + project.container_repositories << container_repository end subject { transfer_project(project, user, group) } |