forked from diaspora/diaspora
/
base_spec.rb
80 lines (67 loc) · 2.34 KB
/
base_spec.rb
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
78
79
80
require 'spec_helper'
require Rails.root.join('spec', 'shared_behaviors', 'stream')
describe Stream::Base do
before do
@stream = Stream::Base.new(alice)
end
describe '#contacts_link' do
it 'should default to your contacts page' do
@stream.contacts_link.should =~ /contacts/
end
end
describe '#stream_posts' do
it "should returns the posts.for_a_stream" do
posts = mock
@stream.stub(:posts).and_return(posts)
@stream.stub(:like_posts_for_stream!)
posts.should_receive(:for_a_stream).with(anything, anything, alice).and_return(posts)
@stream.stream_posts
end
context "when alice has liked some posts" do
before do
bob.post(:status_message, :text => "sup", :to => bob.aspects.first.id)
@liked_status = bob.posts.last
@like = Factory(:like, :target => @liked_status, :author => alice.person)
end
it "marks the posts as liked" do
@stream.stream_posts.first.user_like.id.should == @like.id
end
end
end
describe '.can_comment?' do
before do
@person = Factory(:person)
@stream.stub(:people).and_return([bob.person, eve.person, @person])
end
it 'allows me to comment on my local contacts post' do
post = Factory(:status_message, :author => bob.person)
@stream.can_comment?(post).should be_true
end
it 'allows me to comment on my own post' do
post = Factory(:status_message, :author => alice.person)
@stream.can_comment?(post).should be_true
end
it 'allows me to comment on any local public post' do
post = Factory(:status_message, :author => eve.person)
@stream.can_comment?(post).should be_true
end
it 'allows me to comment on a remote contacts post' do
Contact.create!(:user => @stream.user, :person => @person)
post = Factory(:status_message, :author => @person)
@stream.can_comment?(post).should be_true
end
it 'returns false if person is remote and not a contact' do
post = Factory(:status_message, :author => @person)
@stream.can_comment?(post).should be_false
end
end
describe '#people' do
it 'excludes blocked people' do
@stream.should_receive(:stream_posts).and_return(stub.as_null_object)
@stream.people
end
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
end
end