Welcome to mirror list, hosted at ThFree Co, Russian Federation.

snippets_shared_examples.rb « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 51a4a8b1cd984601c336975a842687364f3b3181 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

RSpec.shared_examples 'snippets 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 allow_possible_spam 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