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

destroy_service_shared_examples.rb « wiki_pages « services « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1231c012c31eb673b84d87219fad3119f57be1b9 (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
43
44
45
46
47
48
49
50
# frozen_string_literal: true

RSpec.shared_examples 'WikiPages::DestroyService#execute' do |container_type|
  let(:container) { create(container_type) }

  let(:user) { create(:user) }
  let(:page) { create(:wiki_page) }

  subject(:service) { described_class.new(container: container, current_user: user) }

  it 'executes webhooks' do
    expect(service).to receive(:execute_hooks).once.with(page)

    service.execute(page)
  end

  it 'increments the delete count' do
    counter = Gitlab::UsageDataCounters::WikiPageCounter

    expect { service.execute(page) }.to change { counter.read(:delete) }.by 1
  end

  it 'creates a new wiki page deletion event' do
    # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/216904
    pending('group wiki support') if container_type == :group

    expect { service.execute(page) }.to change { Event.count }.by 1

    expect(Event.recent.first).to have_attributes(
      action: 'destroyed',
      target: have_attributes(canonical_slug: page.slug)
    )
  end

  it 'does not increment the delete count if the deletion failed' do
    counter = Gitlab::UsageDataCounters::WikiPageCounter

    expect { service.execute(nil) }.not_to change { counter.read(:delete) }
  end

  context 'the feature is disabled' do
    before do
      stub_feature_flags(wiki_events: false)
    end

    it 'does not record the activity' do
      expect { service.execute(page) }.not_to change(Event, :count)
    end
  end
end