Skip to content
Snippets Groups Projects
Commit 2dd9b8a3 authored by Dongqing Hu's avatar Dongqing Hu Committed by Rémy Coutable
Browse files

Fix Project Wiki update

parent 915af2dc
No related branches found
No related tags found
No related merge requests found
Loading
@@ -45,8 +45,9 @@ class Projects::WikisController < Projects::ApplicationController
Loading
@@ -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.'
Loading
Loading
Loading
@@ -16,6 +16,7 @@ module NavHelper
Loading
@@ -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"
Loading
Loading
Loading
@@ -155,7 +155,7 @@ class WikiPage
Loading
@@ -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
Loading
@@ -226,6 +226,8 @@ class WikiPage
Loading
@@ -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)
   
Loading
@@ -243,10 +245,10 @@ class WikiPage
Loading
@@ -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
Loading
@@ -15,15 +15,30 @@ feature 'Projects > Wiki > User updates wiki page', feature: true do
Loading
@@ -15,15 +15,30 @@ 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
click_link 'Edit' 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' 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('Home')
expect(page).to have_content('My awesome wiki!') 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
end end
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment