From 4ca291875251213a05a0c6ce5defd509ed931561 Mon Sep 17 00:00:00 2001 From: Christian Ratz Date: Mon, 29 Apr 2013 09:56:46 +0200 Subject: [PATCH] [OPF #478] fixes wiki page renaming - changed wiki#rename routes to rails default 'put' - adapted tests --- app/controllers/wiki_controller.rb | 2 +- config/routes.rb | 2 +- test/functional/wiki_controller_test.rb | 24 ++++++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 9c33cfabf3..3110ed612b 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -198,7 +198,7 @@ class WikiController < ApplicationController @page.redirect_existing_links = true # used to display the *original* title if some AR validation errors occur @original_title = @page.pretty_title - if request.post? && @page.update_attributes(params[:wiki_page]) + if request.put? && @page.update_attributes(params[:wiki_page]) flash[:notice] = l(:notice_successful_update) redirect_to :action => 'show', :project_id => @project, :id => @page.title end diff --git a/config/routes.rb b/config/routes.rb index 9dacbe25b9..27e28b404f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -123,7 +123,7 @@ OpenProject::Application.routes.draw do get '/diff/:version/vs/:version_from' => 'wiki#diff', :as => 'wiki_diff' get '/diff(/:version)' => 'wiki#diff', :as => 'wiki_diff' get '/annotate/:version' => 'wiki#annotate', :as => 'wiki_annotate' - match :rename, :via => [:get, :post] + match :rename, :via => [:get, :put] get :history post :preview post :protect diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 6802b872f4..69a1d40379 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -283,9 +283,9 @@ class WikiControllerTest < ActionController::TestCase def test_rename_with_redirect @request.session[:user_id] = 2 - post :rename, :project_id => 1, :id => 'Another_page', - :wiki_page => { :title => 'Another renamed page', - :redirect_existing_links => 1 } + put :rename, :project_id => 1, :id => 'Another_page', + :wiki_page => { :title => 'Another renamed page', + :redirect_existing_links => 1 } assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' wiki = Project.find(1).wiki # Check redirects @@ -295,9 +295,9 @@ class WikiControllerTest < ActionController::TestCase def test_rename_without_redirect @request.session[:user_id] = 2 - post :rename, :project_id => 1, :id => 'Another_page', - :wiki_page => { :title => 'Another renamed page', - :redirect_existing_links => "0" } + put :rename, :project_id => 1, :id => 'Another_page', + :wiki_page => { :title => 'Another renamed page', + :redirect_existing_links => "0" } assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_renamed_page' wiki = Project.find(1).wiki # Check that there's no redirects @@ -306,16 +306,20 @@ class WikiControllerTest < ActionController::TestCase def test_rename_with_parent_assignment @request.session[:user_id] = 2 - post :rename, :project_id => 1, :id => 'Another_page', - :wiki_page => { :title => 'Another page', :redirect_existing_links => "0", :parent_id => '4' } + put :rename, :project_id => 1, :id => 'Another_page', + :wiki_page => { :title => 'Another page', + :redirect_existing_links => "0", + :parent_id => '4' } assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Another_page' assert_equal WikiPage.find(4), WikiPage.find_by_title('Another_page').parent end def test_rename_with_parent_unassignment @request.session[:user_id] = 2 - post :rename, :project_id => 1, :id => 'Child_1', - :wiki_page => { :title => 'Child 1', :redirect_existing_links => "0", :parent_id => '' } + put :rename, :project_id => 1, :id => 'Child_1', + :wiki_page => { :title => 'Child 1', + :redirect_existing_links => "0", + :parent_id => '' } assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'Child_1' assert_nil WikiPage.find_by_title('Child_1').parent end