From cb9fb0ad94c9c931f8b50bfdc65d7a646933926d Mon Sep 17 00:00:00 2001 From: zhitomirskiyi <ilya@joindiaspora.com> Date: Mon, 8 Nov 2010 18:19:55 -0800 Subject: [PATCH] IZ local comment destroy --- app/controllers/comments_controller.rb | 10 +++++++++ app/views/comments/_comment.html.haml | 3 +++ spec/controllers/comments_controller_spec.rb | 23 ++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 808566d0cb..73e593f633 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -20,4 +20,14 @@ class CommentsController < ApplicationController end end + def destroy + target = Comment.where(:diaspora_handle => current_user.diaspora_handle, :id => params[:id]).first + + if target + target.destroy + end + + render :nothing => true + end + end diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index f84d4b6d57..662db19665 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -8,5 +8,8 @@ .from = link_to post.person.real_name, post.person = markdownify(post.text) + - if current_user.owns?(post) + .right + = link_to t('delete'), comment_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete" %div.time = "#{time_ago_in_words(post.updated_at)} #{t('ago')}" diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index a6d95a5364..b1d84cdd1f 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -57,4 +57,27 @@ describe CommentsController do end end end + + describe 'destroy' do + before do + friend_users(user, aspect, user2, aspect2) + @post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id + @comment1 = user.comment("yay", :on => @post) + @comment2 = user2.comment("gogogo", :on => @post) + end + + it 'deletes a comment made by that user' do + @post.reload.comments.count.should be 2 + delete :destroy, :id => @comment1.id + Comment.find_by_id(@comment1.id).should be nil + @post.reload.comments.count.should be 1 + end + + it 'does not delete a comment made by another user' do + @post.reload.comments.count.should be 2 + delete :destroy, :id => @comment2.id + Comment.find_by_id(@comment2.id).should_not be nil + @post.reload.comments.count.should be 2 + end + end end -- GitLab