debian-mirror-gitlab/spec/services/wiki_pages/destroy_service_spec.rb

55 lines
1.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe WikiPages::DestroyService do
let(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
2017-09-10 17:25:29 +05:30
let(:page) { create(:wiki_page) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
subject(:service) { described_class.new(project, user) }
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
before do
project.add_developer(user)
end
describe '#execute' do
2017-08-17 22:00:37 +05:30
it 'executes webhooks' do
2020-04-22 19:07:51 +05:30
expect(service).to receive(:execute_hooks).once.with(page)
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
service.execute(page)
2017-08-17 22:00:37 +05:30
end
2019-10-12 21:52:04 +05:30
it 'increments the delete count' do
counter = Gitlab::UsageDataCounters::WikiPageCounter
expect { service.execute(page) }.to change { counter.read(:delete) }.by 1
end
2020-04-22 19:07:51 +05:30
it 'creates a new wiki page deletion event' do
expect { service.execute(page) }.to change { Event.count }.by 1
expect(Event.recent.first).to have_attributes(
action: Event::DESTROYED,
target: have_attributes(canonical_slug: page.slug)
)
end
2019-10-12 21:52:04 +05:30
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
2017-08-17 22:00:37 +05:30
end
2020-04-22 19:07:51 +05:30
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
2017-08-17 22:00:37 +05:30
end