Commit 2dd9b8a3 authored by Dongqing Hu's avatar Dongqing Hu Committed by Rémy Coutable

Fix Project Wiki update

parent 915af2dc
...@@ -45,8 +45,9 @@ class Projects::WikisController < Projects::ApplicationController ...@@ -45,8 +45,9 @@ class Projects::WikisController < Projects::ApplicationController
return render('empty') unless can?(current_user, :create_wiki, @project) return render('empty') unless can?(current_user, :create_wiki, @project)
@page = @project_wiki.find_page(params[:id]) @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( redirect_to(
namespace_project_wiki_path(@project.namespace, @project, @page), namespace_project_wiki_path(@project.namespace, @project, @page),
notice: 'Wiki was successfully updated.' notice: 'Wiki was successfully updated.'
......
...@@ -16,6 +16,7 @@ module NavHelper ...@@ -16,6 +16,7 @@ module NavHelper
"page-gutter build-sidebar right-sidebar-expanded" "page-gutter build-sidebar right-sidebar-expanded"
elsif current_path?('wikis#show') || elsif current_path?('wikis#show') ||
current_path?('wikis#edit') || current_path?('wikis#edit') ||
current_path?('wikis#update') ||
current_path?('wikis#history') || current_path?('wikis#history') ||
current_path?('wikis#git_access') current_path?('wikis#git_access')
"page-gutter wiki-sidebar right-sidebar-expanded" "page-gutter wiki-sidebar right-sidebar-expanded"
......
...@@ -155,7 +155,7 @@ class WikiPage ...@@ -155,7 +155,7 @@ class WikiPage
end end
# Returns boolean True or False if this instance # 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? def persisted?
@persisted == true @persisted == true
end end
...@@ -226,6 +226,8 @@ class WikiPage ...@@ -226,6 +226,8 @@ class WikiPage
end end
def save(method, *args) def save(method, *args)
saved = false
project_wiki = wiki project_wiki = wiki
if valid? && project_wiki.send(method, *args) if valid? && project_wiki.send(method, *args)
...@@ -243,10 +245,10 @@ class WikiPage ...@@ -243,10 +245,10 @@ class WikiPage
set_attributes set_attributes
@persisted = true @persisted = true
saved = true
else else
errors.add(:base, project_wiki.error_message) if project_wiki.error_message errors.add(:base, project_wiki.error_message) if project_wiki.error_message
@persisted = false
end end
@persisted saved
end end
end end
---
title: Fix Project Wiki update
merge_request: 9990
author: Dongqing Hu
...@@ -15,7 +15,8 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do ...@@ -15,7 +15,8 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
context 'in the user namespace' do context 'in the user namespace' do
let(:project) { create(:project, namespace: user.namespace) } 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' click_link 'Edit'
fill_in :wiki_content, with: 'My awesome wiki!' fill_in :wiki_content, with: 'My awesome wiki!'
...@@ -25,6 +26,20 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do ...@@ -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("Last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!') expect(page).to have_content('My awesome wiki!')
end 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 end
context 'in a group namespace' do context 'in a group namespace' do
......
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