Commit a2f63f4e authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'wiki-edit-invalid-page' into 'master'

Redirect wiki edit actions for missing pages

See merge request gitlab-org/gitlab!35350
parents 37b31db8 1111e98e
......@@ -19,7 +19,11 @@ module WikiActions
end
before_action only: [:edit, :update], unless: :valid_encoding? do
redirect_to wiki_page_path(wiki, page)
if params[:id].present?
redirect_to wiki_page_path(wiki, page || params[:id])
else
redirect_to wiki_path(wiki)
end
end
end
......
---
title: Redirect wiki edit actions for missing pages
merge_request: 35350
author:
type: fixed
......@@ -211,8 +211,26 @@ RSpec.shared_examples 'wiki controller actions' do
end
end
describe 'GET #edit' do
subject { get(:edit, params: routing_params.merge(id: wiki_title)) }
shared_examples 'edit action' do
context 'when the page does not exist' do
let(:id_param) { 'invalid' }
it 'redirects to show' do
subject
expect(response).to redirect_to_wiki(wiki, 'invalid')
end
end
context 'when id param is blank' do
let(:id_param) { ' ' }
it 'redirects to the home page' do
subject
expect(response).to redirect_to_wiki(wiki, 'home')
end
end
context 'when page content encoding is invalid' do
it 'redirects to show' do
......@@ -236,6 +254,14 @@ RSpec.shared_examples 'wiki controller actions' do
expect(response).to redirect_to_wiki(wiki, page)
end
end
end
describe 'GET #edit' do
let(:id_param) { wiki_title }
subject { get(:edit, params: routing_params.merge(id: id_param)) }
it_behaves_like 'edit action'
context 'when page content encoding is valid' do
render_views
......@@ -252,23 +278,17 @@ RSpec.shared_examples 'wiki controller actions' do
describe 'PATCH #update' do
let(:new_title) { 'New title' }
let(:new_content) { 'New content' }
let(:id_param) { wiki_title }
subject do
patch(:update,
params: routing_params.merge(
id: wiki_title,
id: id_param,
wiki: { title: new_title, content: new_content }
))
end
context 'when page content encoding is invalid' do
it 'redirects to show' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to_wiki(wiki, wiki.list_pages.first)
end
end
it_behaves_like 'edit action'
context 'when page content encoding is valid' do
render_views
......
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