Commit 70bf0706 authored by Eric Davis's avatar Eric Davis

Refactor: convert WikiController#destroy to use HTTP DELETE

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4295 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 17eab0f5
...@@ -36,7 +36,7 @@ class WikiController < ApplicationController ...@@ -36,7 +36,7 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize before_filter :find_wiki, :authorize
before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :show } verify :method => :post, :only => [:protect], :redirect_to => { :action => :show }
helper :attachments helper :attachments
include AttachmentsHelper include AttachmentsHelper
...@@ -172,7 +172,8 @@ class WikiController < ApplicationController ...@@ -172,7 +172,8 @@ class WikiController < ApplicationController
@annotate = @page.annotate(params[:version]) @annotate = @page.annotate(params[:version])
render_404 unless @annotate render_404 unless @annotate
end end
verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
# Removes a wiki page and its history # Removes a wiki page and its history
# Children can be either set as root pages, removed or reassigned to another parent page # Children can be either set as root pages, removed or reassigned to another parent page
def destroy def destroy
......
<h2><%=h @page.pretty_title %></h2> <h2><%=h @page.pretty_title %></h2>
<% form_tag({}) do %> <% form_tag({}, :method => :delete) do %>
<div class="box"> <div class="box">
<p><strong><%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %></strong></p> <p><strong><%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %></strong></p>
<p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_wiki_page_nullify_children) %></label><br /> <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_wiki_page_nullify_children) %></label><br />
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :page => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %> <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :page => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %>
<%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :page => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :page => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %>
<%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %>
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
<%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %>
<% end %> <% end %>
<%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> <%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %>
......
...@@ -41,10 +41,12 @@ ActionController::Routing::Routes.draw do |map| ...@@ -41,10 +41,12 @@ ActionController::Routing::Routes.draw do |map|
end end
wiki_routes.connect 'projects/:project_id/wiki/:page/:action', wiki_routes.connect 'projects/:project_id/wiki/:page/:action',
:action => /rename|destroy|preview|protect|add_attachment/, :action => /rename|preview|protect|add_attachment/,
:conditions => {:method => :post} :conditions => {:method => :post}
wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post} wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post}
wiki_routes.connect 'projects/:project_id/wiki/:page', :action => 'destroy', :conditions => {:method => :delete}
end end
map.with_options :controller => 'messages' do |messages_routes| map.with_options :controller => 'messages' do |messages_routes|
......
...@@ -196,14 +196,14 @@ class WikiControllerTest < ActionController::TestCase ...@@ -196,14 +196,14 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_child def test_destroy_child
@request.session[:user_id] = 2 @request.session[:user_id] = 2
post :destroy, :project_id => 1, :page => 'Child_1' delete :destroy, :project_id => 1, :page => 'Child_1'
assert_redirected_to :action => 'index', :project_id => 'ecookbook' assert_redirected_to :action => 'index', :project_id => 'ecookbook'
end end
def test_destroy_parent def test_destroy_parent
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_no_difference('WikiPage.count') do assert_no_difference('WikiPage.count') do
post :destroy, :project_id => 1, :page => 'Another_page' delete :destroy, :project_id => 1, :page => 'Another_page'
end end
assert_response :success assert_response :success
assert_template 'destroy' assert_template 'destroy'
...@@ -212,7 +212,7 @@ class WikiControllerTest < ActionController::TestCase ...@@ -212,7 +212,7 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_parent_with_nullify def test_destroy_parent_with_nullify
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do assert_difference('WikiPage.count', -1) do
post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify' delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify'
end end
assert_redirected_to :action => 'index', :project_id => 'ecookbook' assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
...@@ -221,7 +221,7 @@ class WikiControllerTest < ActionController::TestCase ...@@ -221,7 +221,7 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_parent_with_cascade def test_destroy_parent_with_cascade
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -3) do assert_difference('WikiPage.count', -3) do
post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy' delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy'
end end
assert_redirected_to :action => 'index', :project_id => 'ecookbook' assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
...@@ -231,7 +231,7 @@ class WikiControllerTest < ActionController::TestCase ...@@ -231,7 +231,7 @@ class WikiControllerTest < ActionController::TestCase
def test_destroy_parent_with_reassign def test_destroy_parent_with_reassign
@request.session[:user_id] = 2 @request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do assert_difference('WikiPage.count', -1) do
post :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
end end
assert_redirected_to :action => 'index', :project_id => 'ecookbook' assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2) assert_nil WikiPage.find_by_id(2)
......
...@@ -325,9 +325,10 @@ class RoutingTest < ActionController::IntegrationTest ...@@ -325,9 +325,10 @@ class RoutingTest < ActionController::IntegrationTest
should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page' should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page'
should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation' should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation'
should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida'
should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida'
should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida'
should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :page => 'ladida' should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :page => 'ladida'
should_route :delete, "/projects/22/wiki/ladida", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida'
end end
context "wikis (plural, admin setup)" do context "wikis (plural, admin setup)" 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