Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edavis10 committed Sep 23, 2010
1 parent 4948121 commit 401197a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions app/controllers/comments_controller.rb
Expand Up @@ -16,6 +16,12 @@ def create
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
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/news_controller.rb
Expand Up @@ -73,11 +73,6 @@ def update
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
Expand Down
4 changes: 2 additions & 2 deletions app/views/news/show.rhtml
Expand Up @@ -39,8 +39,8 @@
<% @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) %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -154,6 +154,7 @@
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'
Expand Down
2 changes: 1 addition & 1 deletion lib/redmine.rb
Expand Up @@ -91,7 +91,7 @@
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
Expand Down
11 changes: 11 additions & 0 deletions test/functional/comments_controller_test.rb
Expand Up @@ -43,4 +43,15 @@ def test_empty_comment_should_not_be_added
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
9 changes: 0 additions & 9 deletions test/functional/news_controller_test.rb
Expand Up @@ -111,15 +111,6 @@ def test_post_create_with_validation_failure
: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
Expand Down
2 changes: 2 additions & 0 deletions test/integration/routing_test.rb
Expand Up @@ -163,6 +163,8 @@ class RoutingTest < ActionController::IntegrationTest
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
Expand Down

0 comments on commit 401197a

Please sign in to comment.