redirect_to :controller => 'news', :action => 'show', :id => @news
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
# ApplicationController's find_model_object sets it based on the controller
end
end
- def destroy_comment
- @news.comments.find(params[:comment_id]).destroy
- redirect_to :action => 'show', :id => @news
- end
-
def destroy
@news.destroy
redirect_to :action => 'index', :project_id => @project
<% @comments.each do |comment| %>
<% next if comment.new_record? %>
<div class="contextual">
- <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'news', :action => 'destroy_comment', :id => @news, :comment_id => comment},
- :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_delete) %>
+ <%= link_to_if_authorized image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment},
+ :confirm => l(:text_are_you_sure), :method => :delete, :title => l(:button_delete) %>
</div>
<h4><%= avatar(comment.author, :size => "24") %><%= authoring comment.created_on, comment.author %></h4>
<%= textilizable(comment.comments) %>
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/:comment_id', :controller => 'comments', :action => 'destroy', :conditions => {:method => :delete}
end
map.connect 'projects/:id/members/new', :controller => 'members', :action => 'new'
end
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 :comment_news, {:comments => :create}
end
assert_redirected_to 'news/1'
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
:content => /1 error/
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
@request.session[:user_id] = 2
post :destroy, :id => 1
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 :delete, "/news/567/comments/15", :controller => 'comments', :action => 'destroy', :id => '567', :comment_id => '15'
end
context "projects" do