2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-20 08:31:21 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe WikiPages::UpdateService do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2016-12-20 08:31:21 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-06-01 15:27:52 -04:00
|
|
|
let(:page) { create(:wiki_page) }
|
|
|
|
|
2016-12-20 08:31:21 -05:00
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
content: 'New content for wiki page',
|
|
|
|
format: 'markdown',
|
2017-07-23 04:19:10 -04:00
|
|
|
message: 'New wiki message',
|
|
|
|
title: 'New Title'
|
2016-12-20 08:31:21 -05:00
|
|
|
}
|
|
|
|
end
|
2017-06-01 15:27:52 -04:00
|
|
|
|
2019-07-20 21:26:19 -04:00
|
|
|
let(:bad_opts) do
|
|
|
|
{ title: '' }
|
|
|
|
end
|
|
|
|
|
2017-06-01 15:27:52 -04:00
|
|
|
subject(:service) { described_class.new(project, user, opts) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
2016-12-20 08:31:21 -05:00
|
|
|
|
|
|
|
describe '#execute' do
|
2017-06-01 15:27:52 -04:00
|
|
|
it 'updates the wiki page' do
|
|
|
|
updated_page = service.execute(page)
|
|
|
|
|
|
|
|
expect(updated_page).to be_valid
|
|
|
|
expect(updated_page.message).to eq(opts[:message])
|
|
|
|
expect(updated_page.content).to eq(opts[:content])
|
|
|
|
expect(updated_page.format).to eq(opts[:format].to_sym)
|
2017-07-23 04:19:10 -04:00
|
|
|
expect(updated_page.title).to eq(opts[:title])
|
2017-06-01 15:27:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'executes webhooks' do
|
|
|
|
expect(service).to receive(:execute_hooks).once
|
|
|
|
.with(instance_of(WikiPage), 'update')
|
|
|
|
|
|
|
|
service.execute(page)
|
2016-12-20 08:31:21 -05:00
|
|
|
end
|
2019-07-20 21:26:19 -04:00
|
|
|
|
|
|
|
it 'counts edit events' do
|
|
|
|
counter = Gitlab::UsageDataCounters::WikiPageCounter
|
|
|
|
|
|
|
|
expect { service.execute page }.to change { counter.read(:update) }.by 1
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the options are bad' do
|
|
|
|
subject(:service) { described_class.new(project, user, bad_opts) }
|
|
|
|
|
|
|
|
it 'does not count an edit event' do
|
|
|
|
counter = Gitlab::UsageDataCounters::WikiPageCounter
|
|
|
|
|
|
|
|
expect { service.execute page }.not_to change { counter.read(:update) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reports the error' do
|
|
|
|
expect(service.execute page).to be_invalid
|
|
|
|
.and have_attributes(errors: be_present)
|
|
|
|
end
|
|
|
|
end
|
2016-12-20 08:31:21 -05:00
|
|
|
end
|
|
|
|
end
|