Refactor: move #destroy_comment method to CommentsController#destroy
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4172 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
4948121af0
commit
401197a895
|
@ -16,6 +16,12 @@ class CommentsController < ApplicationController
|
||||||
redirect_to :controller => 'news', :action => 'show', :id => @news
|
redirect_to :controller => 'news', :action => 'show', :id => @news
|
||||||
end
|
end
|
||||||
|
|
||||||
|
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
||||||
|
def destroy
|
||||||
|
@news.comments.find(params[:comment_id]).destroy
|
||||||
|
redirect_to :controller => 'news', :action => 'show', :id => @news
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# ApplicationController's find_model_object sets it based on the controller
|
# ApplicationController's find_model_object sets it based on the controller
|
||||||
|
|
|
@ -73,11 +73,6 @@ class NewsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_comment
|
|
||||||
@news.comments.find(params[:comment_id]).destroy
|
|
||||||
redirect_to :action => 'show', :id => @news
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@news.destroy
|
@news.destroy
|
||||||
redirect_to :action => 'index', :project_id => @project
|
redirect_to :action => 'index', :project_id => @project
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
<% @comments.each do |comment| %>
|
<% @comments.each do |comment| %>
|
||||||
<% next if comment.new_record? %>
|
<% next if comment.new_record? %>
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to_if_authorized image_tag('delete.png'), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment},
|
<%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
|
||||||
:confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_delete) %>
|
:confirm => l(:text_are_you_sure), :method => :delete, :title => l(:button_delete) %>
|
||||||
</div>
|
</div>
|
||||||
<h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4>
|
<h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4>
|
||||||
<%= textilizable(comment.comments) %>
|
<%= textilizable(comment.comments) %>
|
||||||
|
|
|
@ -154,6 +154,7 @@ ActionController::Routing::Routes.draw do |map|
|
||||||
news_routes.connect 'news/:id/edit', :action => 'update', :conditions => {:method => :put}
|
news_routes.connect 'news/:id/edit', :action => 'update', :conditions => {:method => :put}
|
||||||
|
|
||||||
news_routes.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
|
news_routes.connect 'news/:id/comments', :controller => 'comments', :action => 'create', :conditions => {:method => :post}
|
||||||
|
news_routes.connect 'news/:id/comments/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
|
||||||
end
|
end
|
||||||
|
|
||||||
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
|
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
|
||||||
|
|
|
@ -91,7 +91,7 @@ Redmine::AccessControl.map do |map|
|
||||||
end
|
end
|
||||||
|
|
||||||
map.project_module :news do |map|
|
map.project_module :news do |map|
|
||||||
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy, :destroy_comment]}, :require => :member
|
map.permission :manage_news, {:news => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
|
||||||
map.permission :view_news, {:news => [:index, :show]}, :public => true
|
map.permission :view_news, {:news => [:index, :show]}, :public => true
|
||||||
map.permission :comment_news, {:comments => :create}
|
map.permission :comment_news, {:comments => :create}
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,4 +43,15 @@ class CommentsControllerTest < ActionController::TestCase
|
||||||
assert_redirected_to 'news/1'
|
assert_redirected_to 'news/1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_destroy_comment
|
||||||
|
comments_count = News.find(1).comments.size
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
delete :destroy, :id => 1, :comment_id => 2
|
||||||
|
assert_redirected_to 'news/1'
|
||||||
|
assert_nil Comment.find_by_id(2)
|
||||||
|
assert_equal comments_count - 1, News.find(1).comments.size
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -111,15 +111,6 @@ class NewsControllerTest < ActionController::TestCase
|
||||||
:content => /1 error/
|
:content => /1 error/
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy_comment
|
|
||||||
comments_count = News.find(1).comments.size
|
|
||||||
@request.session[:user_id] = 2
|
|
||||||
post :destroy_comment, :id => 1, :comment_id => 2
|
|
||||||
assert_redirected_to 'news/1'
|
|
||||||
assert_nil Comment.find_by_id(2)
|
|
||||||
assert_equal comments_count - 1, News.find(1).comments.size
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
post :destroy, :id => 1
|
post :destroy, :id => 1
|
||||||
|
|
|
@ -163,6 +163,8 @@ class RoutingTest < ActionController::IntegrationTest
|
||||||
should_route :post, "/news/567/comments", :controller => 'comments', :action => 'create', :id => '567'
|
should_route :post, "/news/567/comments", :controller => 'comments', :action => 'create', :id => '567'
|
||||||
|
|
||||||
should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :id => '567'
|
should_route :put, "/news/567/edit", :controller => 'news', :action => 'update', :id => '567'
|
||||||
|
|
||||||
|
should_route :delete, "/news/567/comments/15", :controller => 'comments', :action => 'destroy', :id => '567', :comment_id => '15'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "projects" do
|
context "projects" do
|
||||||
|
|
Loading…
Reference in New Issue