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

Fix Project Wiki update

Closes #29405

See merge request !9990
This commit is contained in:
Rémy Coutable 2017-03-20 13:53:24 +00:00
commit b075d38c9b
5 changed files with 34 additions and 11 deletions

View file

@ -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.'

View file

@ -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"

View file

@ -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

View file

@ -0,0 +1,4 @@
---
title: Fix Project Wiki update
merge_request: 9990
author: Dongqing Hu

View file

@ -15,7 +15,8 @@ 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
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!'
@ -25,6 +26,20 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
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
context 'in a group namespace' do