diff options
Diffstat (limited to 'spec/services/snippets')
4 files changed, 26 insertions, 8 deletions
diff --git a/spec/services/snippets/bulk_destroy_service_spec.rb b/spec/services/snippets/bulk_destroy_service_spec.rb index 8a6250a8b45..2f399d10188 100644 --- a/spec/services/snippets/bulk_destroy_service_spec.rb +++ b/spec/services/snippets/bulk_destroy_service_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Snippets::BulkDestroyService do let_it_be(:project) { create(:project) } + let(:user) { create(:user) } let!(:personal_snippet) { create(:personal_snippet, :repository, author: user) } let!(:project_snippet) { create(:project_snippet, :repository, project: project, author: user) } diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb index eb6e85eb408..0eb73c8edd2 100644 --- a/spec/services/snippets/create_service_spec.rb +++ b/spec/services/snippets/create_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Snippets::CreateService do describe '#execute' do let_it_be(:user) { create(:user) } let_it_be(:admin) { create(:user, :admin) } + let(:action) { :create } let(:opts) { base_opts.merge(extra_opts) } let(:base_opts) do @@ -19,8 +20,9 @@ RSpec.describe Snippets::CreateService do let(:extra_opts) { {} } let(:creator) { admin } + let(:spam_params) { double } - subject { described_class.new(project: project, current_user: creator, params: opts).execute } + subject { described_class.new(project: project, current_user: creator, params: opts, spam_params: spam_params).execute } let(:snippet) { subject.payload[:snippet] } @@ -301,6 +303,10 @@ RSpec.describe Snippets::CreateService do end end + before do + stub_spam_services + end + context 'when ProjectSnippet' do let_it_be(:project) { create(:project) } diff --git a/spec/services/snippets/update_repository_storage_service_spec.rb b/spec/services/snippets/update_repository_storage_service_spec.rb index 50b28a5a125..fdea3615fb1 100644 --- a/spec/services/snippets/update_repository_storage_service_spec.rb +++ b/spec/services/snippets/update_repository_storage_service_spec.rb @@ -75,9 +75,10 @@ RSpec.describe Snippets::UpdateRepositoryStorageService do .with(snippet.repository.raw) .and_raise(Gitlab::Git::CommandError) - result = subject.execute + expect do + subject.execute + end.to raise_error(Gitlab::Git::CommandError) - expect(result).to be_error expect(snippet).not_to be_repository_read_only expect(snippet.repository_storage).to eq('default') expect(repository_storage_move).to be_failed @@ -93,9 +94,10 @@ RSpec.describe Snippets::UpdateRepositoryStorageService do expect(original_snippet_repository_double).to receive(:remove) .and_raise(Gitlab::Git::CommandError) - result = subject.execute + expect do + subject.execute + end.to raise_error(Gitlab::Git::CommandError) - expect(result).to be_error expect(repository_storage_move).to be_cleanup_failed end end @@ -107,9 +109,10 @@ RSpec.describe Snippets::UpdateRepositoryStorageService do expect(snippet_repository_double).to receive(:checksum) .and_return('not matching checksum') - result = subject.execute + expect do + subject.execute + end.to raise_error(UpdateRepositoryStorageMethods::Error, /Failed to verify snippet repository checksum from \w+ to not matching checksum/) - expect(result).to be_error expect(snippet).not_to be_repository_read_only expect(snippet.repository_storage).to eq('default') end diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb index 46bc62e11ef..f61d33e2436 100644 --- a/spec/services/snippets/update_service_spec.rb +++ b/spec/services/snippets/update_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Snippets::UpdateService do describe '#execute', :aggregate_failures do let_it_be(:user) { create(:user) } let_it_be(:admin) { create :user, admin: true } + let(:action) { :update } let(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } let(:base_opts) do @@ -20,7 +21,9 @@ RSpec.describe Snippets::UpdateService do let(:extra_opts) { {} } let(:options) { base_opts.merge(extra_opts) } let(:updater) { user } - let(:service) { Snippets::UpdateService.new(project: project, current_user: updater, params: options) } + let(:spam_params) { double } + + let(:service) { Snippets::UpdateService.new(project: project, current_user: updater, params: options, spam_params: spam_params) } subject { service.execute(snippet) } @@ -721,8 +724,13 @@ RSpec.describe Snippets::UpdateService do end end + before do + stub_spam_services + end + context 'when Project Snippet' do let_it_be(:project) { create(:project) } + let!(:snippet) { create(:project_snippet, :repository, author: user, project: project) } before do |