diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 00:08:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 00:08:05 +0300 |
commit | 680d18802596089dc407b7011bcf682d24846aec (patch) | |
tree | 09e1beea15fe9ba9d1a757c31b7836e5f7e9fa89 /spec/services/snippets | |
parent | d84f18d66c1fc46f244b0f4dec8bf65b90d9882a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/snippets')
-rw-r--r-- | spec/services/snippets/create_service_spec.rb | 45 | ||||
-rw-r--r-- | spec/services/snippets/update_service_spec.rb | 20 |
2 files changed, 18 insertions, 47 deletions
diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb index c0a0a2f6ac2..786fc3ec8dd 100644 --- a/spec/services/snippets/create_service_spec.rb +++ b/spec/services/snippets/create_service_spec.rb @@ -74,47 +74,6 @@ describe Snippets::CreateService do end end - shared_examples 'spam check is performed' do - shared_examples 'marked as spam' do - it 'marks a snippet as spam' do - expect(snippet).to be_spam - end - - it 'invalidates the snippet' do - expect(snippet).to be_invalid - end - - it 'creates a new spam_log' do - expect { snippet } - .to have_spam_log(title: snippet.title, noteable_type: snippet.class.name) - end - - it 'assigns a spam_log to an issue' do - expect(snippet.spam_log).to eq(SpamLog.last) - end - end - - let(:extra_opts) do - { visibility_level: Gitlab::VisibilityLevel::PUBLIC, request: double(:request, env: {}) } - end - - before do - expect_next_instance_of(Spam::AkismetService) do |akismet_service| - expect(akismet_service).to receive_messages(spam?: true) - end - end - - [true, false, nil].each do |allow_possible_spam| - context "when recaptcha_disabled flag is #{allow_possible_spam.inspect}" do - before do - stub_feature_flags(allow_possible_spam: allow_possible_spam) unless allow_possible_spam.nil? - end - - it_behaves_like 'marked as spam' - end - end - end - shared_examples 'snippet create data is tracked' do let(:counter) { Gitlab::UsageDataCounters::SnippetCounter } @@ -280,7 +239,7 @@ describe Snippets::CreateService do it_behaves_like 'a service that creates a snippet' it_behaves_like 'public visibility level restrictions apply' - it_behaves_like 'spam check is performed' + it_behaves_like 'snippets spam check is performed' it_behaves_like 'snippet create data is tracked' it_behaves_like 'an error service response when save fails' it_behaves_like 'creates repository and files' @@ -306,7 +265,7 @@ describe Snippets::CreateService do it_behaves_like 'a service that creates a snippet' it_behaves_like 'public visibility level restrictions apply' - it_behaves_like 'spam check is performed' + it_behaves_like 'snippets spam check is performed' it_behaves_like 'snippet create data is tracked' it_behaves_like 'an error service response when save fails' it_behaves_like 'creates repository and files' diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb index 2d94cc87295..38747ae907f 100644 --- a/spec/services/snippets/update_service_spec.rb +++ b/spec/services/snippets/update_service_spec.rb @@ -7,7 +7,7 @@ describe Snippets::UpdateService do let_it_be(:user) { create(:user) } let_it_be(:admin) { create :user, admin: true } let(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } - let(:options) do + let(:base_opts) do { title: 'Test snippet', file_name: 'snippet.rb', @@ -15,6 +15,8 @@ describe Snippets::UpdateService do visibility_level: visibility_level } end + let(:extra_opts) { {} } + let(:options) { base_opts.merge(extra_opts) } let(:updater) { user } let(:service) { Snippets::UpdateService.new(project, updater, options) } @@ -85,7 +87,7 @@ describe Snippets::UpdateService do end context 'when update fails' do - let(:options) { { title: '' } } + let(:extra_opts) { { title: '' } } it 'does not increment count' do expect { subject }.not_to change { counter.read(:update) } @@ -273,7 +275,7 @@ describe Snippets::UpdateService do shared_examples 'committable attributes' do context 'when file_name is updated' do - let(:options) { { file_name: 'snippet.rb' } } + let(:extra_opts) { { file_name: 'snippet.rb' } } it 'commits to repository' do expect(service).to receive(:create_commit) @@ -282,7 +284,7 @@ describe Snippets::UpdateService do end context 'when content is updated' do - let(:options) { { content: 'puts "hello world"' } } + let(:extra_opts) { { content: 'puts "hello world"' } } it 'commits to repository' do expect(service).to receive(:create_commit) @@ -314,6 +316,11 @@ describe Snippets::UpdateService do it_behaves_like 'updates repository content' it_behaves_like 'commit operation fails' it_behaves_like 'committable attributes' + it_behaves_like 'snippets spam check is performed' do + before do + subject + end + end context 'when snippet does not have a repository' do let!(:snippet) { create(:project_snippet, author: user, project: project) } @@ -333,6 +340,11 @@ describe Snippets::UpdateService do it_behaves_like 'updates repository content' it_behaves_like 'commit operation fails' it_behaves_like 'committable attributes' + it_behaves_like 'snippets spam check is performed' do + before do + subject + end + end context 'when snippet does not have a repository' do let!(:snippet) { create(:personal_snippet, author: user, project: project) } |