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 PostsController do
before do
Raphael Sofaer
a validé
sign_in alice
aspect = alice.aspects.first
@message = alice.build_post :status_message, :text => "ohai", :to => aspect.id
@message.save!
Raphael Sofaer
a validé
alice.add_to_streams(@message, [aspect])
alice.dispatch_post @message, :to => aspect.id
end
Raphael Sofaer
a validé
it 'succeeds' do
get :show, "id" => @message.id.to_s
response.should be_success
end
it 'succeeds on mobile' do
get :show, "id" => @message.id.to_s, :format => :mobile
response.should be_success
end
Raphael Sofaer
a validé
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
it 'marks a corresponding notification as read' do
alice.comment("comment after me", :post => @message)
bob.comment("here you go", :post => @message)
note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first
lambda{
get :show, :id => @message.id
note.reload
}.should change(note, :unread).from(true).to(false)
end
it 'redirects to back if there is no status message' do
get :show, :id => 2345
response.status.should == 302
end
it 'succeeds with a AS/photo' do
photo = Factory(:activity_streams_photo, :author => bob.person)
get :show, :id => photo.id
response.should be_success
end
end
describe '#destroy' do
it 'let a user delete his message' do
message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id)
delete :destroy, :format => :js, :id => message.id
response.should be_success
StatusMessage.find_by_id(message.id).should be_nil
end
it 'sends a retraction on delete' do
controller.stub!(:current_user).and_return alice
message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id)
alice.should_receive(:retract).with(message)
delete :destroy, :format => :js, :id => message.id
response.should be_success
Raphael Sofaer
a validé
it 'will not let you destroy posts visible to you' do
message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id)
delete :destroy, :format => :js, :id => message.id
response.should_not be_success
StatusMessage.exists?(message.id).should be_true
Maxwell Salzberg
a validé
Raphael Sofaer
a validé
it 'will not let you destory posts you do not own' do
message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id)
delete :destroy, :format => :js, :id => message.id
response.should_not be_success
StatusMessage.exists?(message.id).should be_true
Maxwell Salzberg
a validé
end