2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe WikiPages::EventCreateService do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { described_class.new(user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let_it_be(:page) { create(:wiki_page, project: project) }
|
|
|
|
let(:slug) { generate(:sluggified_title) }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:action) { :created }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:response) { subject.execute(slug, page, action) }
|
|
|
|
|
|
|
|
context 'feature flag is not enabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(wiki_events: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not error' do
|
|
|
|
expect(response).to be_success
|
|
|
|
.and have_attributes(message: /No event created/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create an event' do
|
|
|
|
expect { response }.not_to change(Event, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the user is nil' do
|
|
|
|
subject { described_class.new(nil) }
|
|
|
|
|
|
|
|
it 'raises an error on construction' do
|
|
|
|
expect { subject }.to raise_error ArgumentError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the action is illegal' do
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:action) { :illegal_action }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
it 'returns an error' do
|
|
|
|
expect(response).to be_error
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create an event' do
|
|
|
|
expect { response }.not_to change(Event, :count)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a metadata record' do
|
|
|
|
expect { response }.not_to change(WikiPage::Meta, :count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a successful response' do
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the action is a deletion' do
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:action) { :destroyed }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
it 'does not synchronize the wiki metadata timestamps with the git commit' do
|
|
|
|
expect_next_instance_of(WikiPage::Meta) do |instance|
|
|
|
|
expect(instance).not_to receive(:synch_times_with_page)
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a wiki page event' do
|
|
|
|
expect { response }.to change(Event, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an event in the payload' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(response.payload).to include(event: have_attributes(author: user, wiki_page?: true, action: 'created'))
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'records the slug for the page' do
|
|
|
|
response
|
|
|
|
meta = WikiPage::Meta.find_or_create(page.slug, page)
|
|
|
|
|
|
|
|
expect(meta.slugs.pluck(:slug)).to include(slug)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|