Commit b075d38c authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '29405-fix-project-wiki-update' into 'master'

Fix Project Wiki update

Closes #29405

See merge request !9990
parents 915af2dc 2dd9b8a3
......@@ -45,8 +45,9 @@ class Projects::WikisController < Projects::ApplicationController
return render('empty') unless can?(current_user, :create_wiki, @project)
@page = @project_wiki.find_page(params[:id])
@page = WikiPages::UpdateService.new(@project, current_user, wiki_params).execute(@page)
if @page = WikiPages::UpdateService.new(@project, current_user, wiki_params).execute(@page)
if @page.valid?
redirect_to(
namespace_project_wiki_path(@project.namespace, @project, @page),
notice: 'Wiki was successfully updated.'
......
......@@ -16,6 +16,7 @@ module NavHelper
"page-gutter build-sidebar right-sidebar-expanded"
elsif current_path?('wikis#show') ||
current_path?('wikis#edit') ||
current_path?('wikis#update') ||
current_path?('wikis#history') ||
current_path?('wikis#git_access')
"page-gutter wiki-sidebar right-sidebar-expanded"
......
......@@ -155,7 +155,7 @@ class WikiPage
end
# Returns boolean True or False if this instance
# has been fully saved to disk or not.
# has been fully created on disk or not.
def persisted?
@persisted == true
end
......@@ -226,6 +226,8 @@ class WikiPage
end
def save(method, *args)
saved = false
project_wiki = wiki
if valid? && project_wiki.send(method, *args)
......@@ -243,10 +245,10 @@ class WikiPage
set_attributes
@persisted = true
saved = true
else
errors.add(:base, project_wiki.error_message) if project_wiki.error_message
@persisted = false
end
@persisted
saved
end
end
---
title: Fix Project Wiki update
merge_request: 9990
author: Dongqing Hu
......@@ -15,15 +15,30 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
context 'in the user namespace' do
let(:project) { create(:project, namespace: user.namespace) }
scenario 'the home page' do
click_link 'Edit'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Save changes'
expect(page).to have_content('Home')
expect(page).to have_content("Last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
context 'the home page' do
scenario 'success when the wiki content is not empty' do
click_link 'Edit'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Save changes'
expect(page).to have_content('Home')
expect(page).to have_content("Last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
end
scenario 'failure when the wiki content is empty' do
click_link 'Edit'
fill_in :wiki_content, with: ''
click_button 'Save changes'
expect(page).to have_selector('.wiki-form')
expect(page).to have_content('Edit Page')
expect(page).to have_content('The form contains the following error:')
expect(page).to have_content('Content can\'t be blank')
expect(find('textarea#wiki_content').value).to eq ''
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