IZ local comment destroy

This commit is contained in:
zhitomirskiyi 2010-11-08 18:19:55 -08:00
parent 4164ceaf90
commit cb9fb0ad94
3 changed files with 36 additions and 0 deletions

View file

@ -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

View file

@ -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')}"

View file

@ -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