From f1437b7ec59ba9126d93b239d29c85820e7154e4 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Mon, 23 Oct 2023 17:33:40 +0000 Subject: [PATCH] Reinitialize an empty Wiki page after after project wiki is deleted (#34634). git-svn-id: https://svn.redmine.org/redmine/trunk@22370 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/wikis_controller.rb | 4 +++- app/models/enabled_module.rb | 2 +- app/models/wiki.rb | 4 ++++ test/functional/wikis_controller_test.rb | 8 ++++++-- test/unit/wiki_test.rb | 6 ++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/wikis_controller.rb b/app/controllers/wikis_controller.rb index 4469e3627..5b753b13b 100644 --- a/app/controllers/wikis_controller.rb +++ b/app/controllers/wikis_controller.rb @@ -24,7 +24,9 @@ class WikisController < ApplicationController # Delete a project's wiki def destroy if request.post? && params[:confirm] && @project.wiki - @project.wiki.destroy + if @project.wiki.destroy + Wiki.create_default(@project) unless @wiki + end redirect_to project_path(@project) end end diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb index 237563228..1b97903fb 100644 --- a/app/models/enabled_module.rb +++ b/app/models/enabled_module.rb @@ -34,7 +34,7 @@ class EnabledModule < ActiveRecord::Base when 'wiki' # Create a wiki with a default start page if project && project.wiki.nil? - Wiki.create(:project => project, :start_page => 'Wiki') + Wiki.create_default(project) end end end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 726dcea7e..0fddeb3a9 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -97,6 +97,10 @@ class Wiki < ActiveRecord::Base end end + def self.create_default(project) + create(:project => project, :start_page => 'Wiki') + end + # turn a string into a valid page title def self.titleize(title) # replace spaces with _ and remove unwanted caracters diff --git a/test/functional/wikis_controller_test.rb b/test/functional/wikis_controller_test.rb index 9f3f9bffb..ecad3a4a4 100644 --- a/test/functional/wikis_controller_test.rb +++ b/test/functional/wikis_controller_test.rb @@ -35,13 +35,17 @@ class WikisControllerTest < Redmine::ControllerTest end end - def test_post_destroy_should_delete_wiki + def test_post_destroy_should_reinitialize_empty_wiki set_tmp_attachments_directory @request.session[:user_id] = 1 + wiki = Project.find(1).wiki post :destroy, :params => {:id => 1, :confirm => 1} assert_redirected_to :controller => 'projects', :action => 'show', :id => 'ecookbook' - assert_nil Project.find(1).wiki + + new_wiki = Project.find(1).wiki + assert_not_equal wiki, new_wiki + assert_equal "Wiki", new_wiki.start_page end def test_not_found diff --git a/test/unit/wiki_test.rb b/test/unit/wiki_test.rb index da791dff4..eeb6aa2bb 100644 --- a/test/unit/wiki_test.rb +++ b/test/unit/wiki_test.rb @@ -35,6 +35,12 @@ class WikiTest < ActiveSupport::TestCase assert wiki.save end + def test_create_default + wiki = Wiki.create_default(Project.find(1)) + assert wiki.save + assert_equal "Wiki", wiki.start_page + end + def test_update @wiki = Wiki.find(1) @wiki.start_page = "Another start page" -- 2.39.5