1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# 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
sign_in alice
aspect = alice.aspects.first
@message = alice.build_post :status_message, :text => "ohai", :to => aspect.id
@message.save!
alice.add_to_streams(@message, [aspect])
alice.dispatch_post @message, :to => aspect.id
end
describe '#show' do
it 'succeeds' do
get :show, "id" => @message.id.to_s
response.should be_success
end
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
end
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
end
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
end
end
end
|