Skip to content

Commit

Permalink
Refactor: convert WikiController#destroy to use HTTP DELETE
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4295 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
edavis10 committed Oct 26, 2010
1 parent 17eab0f commit 70bf070
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class WikiController < ApplicationController
before_filter :find_wiki, :authorize
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
include AttachmentsHelper
Expand Down Expand Up @@ -172,7 +172,8 @@ def annotate
@annotate = @page.annotate(params[:version])
render_404 unless @annotate
end


verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show }
# Removes a wiki page and its history
# Children can be either set as root pages, removed or reassigned to another parent page
def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/views/wiki/destroy.rhtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2><%=h @page.pretty_title %></h2>

<% form_tag({}) do %>
<% form_tag({}, :method => :delete) do %>
<div class="box">
<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 />
Expand Down
2 changes: 1 addition & 1 deletion app/views/wiki/show.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_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 %>
<% end %>
<%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
end

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}

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

map.with_options :controller => 'messages' do |messages_routes|
Expand Down
10 changes: 5 additions & 5 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ def test_rename_without_redirect

def test_destroy_child
@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'
end

def test_destroy_parent
@request.session[:user_id] = 2
assert_no_difference('WikiPage.count') do
post :destroy, :project_id => 1, :page => 'Another_page'
delete :destroy, :project_id => 1, :page => 'Another_page'
end
assert_response :success
assert_template 'destroy'
Expand All @@ -212,7 +212,7 @@ def test_destroy_parent
def test_destroy_parent_with_nullify
@request.session[:user_id] = 2
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
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2)
Expand All @@ -221,7 +221,7 @@ def test_destroy_parent_with_nullify
def test_destroy_parent_with_cascade
@request.session[:user_id] = 2
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
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2)
Expand All @@ -231,7 +231,7 @@ def test_destroy_parent_with_cascade
def test_destroy_parent_with_reassign
@request.session[:user_id] = 2
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
assert_redirected_to :action => 'index', :project_id => 'ecookbook'
assert_nil WikiPage.find_by_id(2)
Expand Down
3 changes: 2 additions & 1 deletion test/integration/routing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/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/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/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

context "wikis (plural, admin setup)" do
Expand Down

0 comments on commit 70bf070

Please sign in to comment.