Newer
Older
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe CommentsController do
@aspect1 = alice.aspects.first
@aspect2 = bob.aspects.first
@controller.stub(:current_user).and_return(alice)
sign_in :user, alice
end
describe '#create' do
let(:comment_hash) {
@post = alice.post :status_message, :text => 'GIANTS', :to => @aspect1.id
it 'responds to format js' do
post :create, comment_hash.merge(:format => 'js')
response.code.should == '201'
context "on a post from a contact" do
@post = bob.post :status_message, :text => 'GIANTS', :to => @aspect2.id
it 'comments' do
post :create, comment_hash
response.code.should == '201'
end
it "doesn't overwrite author_id" do
new_user = Factory.create(:user)
comment_hash[:author_id] = new_user.person.id.to_s
Comment.find_by_text(comment_hash[:text]).author_id.should == alice.person.id
old_comment = alice.comment("hello", :on => @post)
post :create, comment_hash
old_comment.reload.text.should == 'hello'
end
end
context 'on a post from a stranger' do
before do
@post = eve.post :status_message, :text => 'GIANTS', :to => eve.aspects.first.id
alice.should_not_receive(:comment)
MrZYX
a validé
response.code.should == '422'
describe '#destroy' do
context 'your post' do
before do
@message = alice.post(:status_message, :text => "hey", :to => @aspect1.id)
@comment = alice.comment("hey", :on => @message)
@comment2 = bob.comment("hey", :on => @message)
@comment3 = eve.comment("hey", :on => @message)
end
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
it 'lets the user delete his comment' do
alice.should_receive(:retract).with(@comment)
delete :destroy, :format => "js", :id => @comment.id
response.status.should == 204
end
it "lets the user destroy other people's comments" do
alice.should_receive(:retract).with(@comment2)
delete :destroy, :format => "js", :id => @comment2.id
response.status.should == 204
end
end
context "another user's post" do
before do
@message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id)
@comment = alice.comment("hey", :on => @message)
@comment2 = bob.comment("hey", :on => @message)
@comment3 = eve.comment("hey", :on => @message)
end
it 'let the user delete his comment' do
alice.should_receive(:retract).with(@comment)
delete :destroy, :format => "js", :id => @comment.id
response.status.should == 204
end
it 'does not let the user destroy comments he does not own' do
alice.should_not_receive(:retract).with(@comment2)
delete :destroy, :format => "js", :id => @comment3.id