]> source.dussan.org Git - redmine.git/commitdiff
Refactor: convert WikiController#destroy to use HTTP DELETE
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 26 Oct 2010 15:59:20 +0000 (15:59 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 26 Oct 2010 15:59:20 +0000 (15:59 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4295 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/wiki_controller.rb
app/views/wiki/destroy.rhtml
app/views/wiki/show.rhtml
config/routes.rb
test/functional/wiki_controller_test.rb
test/integration/routing_test.rb

index c7b866239ae82159bf994d6387a2b4649d2658ac..4f15d35a0adab3ea6f0d8ffa9533eb0081165ec8 100644 (file)
@@ -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   
@@ -172,7 +172,8 @@ class WikiController < ApplicationController
     @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
index 83c81fd5cda4c02d7c2bfa561e9f5edc90ce1d92..99f47032000471b7f116136389d9506c65b596cf 100644 (file)
@@ -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 />
index f8675608e41ad900ab81d99d5133a86825f98f94..d8bc8c55eea096cb37653a1c47758d56a54e4012 100644 (file)
@@ -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') %>
index 5ca9d86d1f56a7e63f3e7c958881c55f196be9d8..63c7dd76585bf2f1f1903acaceb848a1c974f013 100644 (file)
@@ -41,10 +41,12 @@ ActionController::Routing::Routes.draw do |map|
     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|
index fecde6159c980a167e8525474ecf1361bec2c978..9124dad3403823e1962ad26a6163c65e4220bdfd 100644 (file)
@@ -196,14 +196,14 @@ class WikiControllerTest < ActionController::TestCase
   
   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'
@@ -212,7 +212,7 @@ class WikiControllerTest < ActionController::TestCase
   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)
@@ -221,7 +221,7 @@ class WikiControllerTest < ActionController::TestCase
   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)
@@ -231,7 +231,7 @@ class WikiControllerTest < ActionController::TestCase
   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)
index c749f51e427928b20f6cb2ae25e8a886476d1c61..e41a04bd2cc4c30ded5a180869730f8dd3603f7f 100644 (file)
@@ -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