Commit 87f82f6e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '19302-wiki-page-delete-does-not-trigger-the-webhook' into 'master'

Resolve "Wiki page delete does not trigger the webhook"

Closes #19302

See merge request !8198
parents 77760455 1fc6f6cc
......@@ -84,7 +84,7 @@ class Projects::WikisController < Projects::ApplicationController
def destroy
@page = @project_wiki.find_page(params[:id])
@page&.delete
WikiPages::DestroyService.new(@project, current_user).execute(@page)
redirect_to(
namespace_project_wiki_path(@project.namespace, @project, :home),
......
......@@ -207,6 +207,10 @@ class WikiPage
'projects/wikis/wiki_page'
end
def id
page.version.to_s
end
private
def set_attributes
......
module WikiPages
class DestroyService < WikiPages::BaseService
def execute(page)
if page&.delete
execute_hooks(page, 'delete')
end
page
end
end
end
---
title: Execute web hooks for WikiPage delete operation
merge_request: 8198
author:
......@@ -714,7 +714,7 @@ X-Gitlab-Event: Merge Request Hook
### Wiki Page events
Triggered when a wiki page is created or edited.
Triggered when a wiki page is created, edited or deleted.
**Request Header**:
......
......@@ -2,8 +2,26 @@ require 'ostruct'
FactoryGirl.define do
factory :wiki_page do
transient do
attrs do
{
title: 'Title',
content: 'Content for wiki page',
format: 'markdown'
}
end
end
page { OpenStruct.new(url_path: 'some-name') }
association :wiki, factory: :project_wiki, strategy: :build
initialize_with { new(wiki, page, true) }
before(:create) do |page, evaluator|
page.attributes = evaluator.attrs
end
to_create do |page|
page.create
end
end
end
......@@ -318,6 +318,19 @@ describe WikiPage, models: true do
end
end
describe '#==' do
let(:original_wiki_page) { create(:wiki_page) }
it 'returns true for identical wiki page' do
expect(original_wiki_page).to eq(original_wiki_page)
end
it 'returns false for updated wiki page' do
updated_wiki_page = original_wiki_page.update("Updated content")
expect(original_wiki_page).not_to eq(updated_wiki_page)
end
end
private
def remove_temp_repo(path)
......
require 'spec_helper'
describe WikiPages::CreateService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:opts) do
{
title: 'Title',
content: 'Content for wiki page',
format: 'markdown'
}
end
let(:service) { described_class.new(project, user, opts) }
describe '#execute' do
context "valid params" do
before do
allow(service).to receive(:execute_hooks)
project.add_master(user)
end
subject { service.execute }
it 'creates a valid wiki page' do
is_expected.to be_valid
expect(subject.title).to eq(opts[:title])
expect(subject.content).to eq(opts[:content])
expect(subject.format).to eq(opts[:format].to_sym)
end
it 'executes webhooks' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'create')
end
end
end
end
require 'spec_helper'
describe WikiPages::DestroyService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) }
let(:service) { described_class.new(project, user) }
describe '#execute' do
before do
allow(service).to receive(:execute_hooks)
project.add_master(user)
end
it 'executes webhooks' do
service.execute(wiki_page)
expect(service).to have_received(:execute_hooks).once.with(wiki_page, 'delete')
end
end
end
require 'spec_helper'
describe WikiPages::UpdateService, services: true do
let(:project) { create(:empty_project) }
let(:user) { create(:user) }
let(:wiki_page) { create(:wiki_page) }
let(:opts) do
{
content: 'New content for wiki page',
format: 'markdown',
message: 'New wiki message'
}
end
let(:service) { described_class.new(project, user, opts) }
describe '#execute' do
context "valid params" do
before do
allow(service).to receive(:execute_hooks)
project.add_master(user)
end
subject { service.execute(wiki_page) }
it 'updates the wiki page' do
is_expected.to be_valid
expect(subject.content).to eq(opts[:content])
expect(subject.format).to eq(opts[:format].to_sym)
expect(subject.message).to eq(opts[:message])
end
it 'executes webhooks' do
expect(service).to have_received(:execute_hooks).once.with(subject, 'update')
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment