Newer
Older
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
require 'aspect_stream'
describe AspectStream do
describe '#aspects' do
it 'queries the user given initialized aspect ids' do
alice = stub.as_null_object
stream = AspectStream.new(alice, [1,2,3])
alice.aspects.should_receive(:where)
stream.aspects
end
it "returns all the user's aspects if no aspect ids are specified" do
alice = stub.as_null_object
stream = AspectStream.new(alice, [])
alice.aspects.should_not_receive(:where)
stream.aspects
end
it 'filters aspects given a user' do
alice = stub(:aspects => [stub(:id => 1)])
alice.aspects.stub(:where).and_return(alice.aspects)
stream = AspectStream.new(alice, [1,2,3])
stream.aspects.should == alice.aspects
end
end
describe '#aspect_ids' do
it 'maps ids from aspects' do
alice = stub.as_null_object
aspects = stub.as_null_object
stream = AspectStream.new(alice, [1,2])
stream.should_receive(:aspects).and_return(aspects)
aspects.should_receive(:map)
stream.aspect_ids
end
end
describe '#posts' do
before do
@alice = stub.as_null_object
end
it 'calls visible posts for the given user' do
stream = AspectStream.new(@alice, [1,2])
@alice.should_receive(:visible_posts).and_return(stub.as_null_object)
stream.posts
end
danielgrippi
a validé
it 'is called with 3 types' do
stream = AspectStream.new(@alice, [1,2], :order => 'created_at')
@alice.should_receive(:visible_posts).with(hash_including(:type=> ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'])).and_return(stub.as_null_object)
stream.posts
end
it 'respects ordering' do
stream = AspectStream.new(@alice, [1,2], :order => 'created_at')
@alice.should_receive(:visible_posts).with(hash_including(:order => 'created_at DESC')).and_return(stub.as_null_object)
stream.posts
end
it 'respects max_time' do
stream = AspectStream.new(@alice, [1,2], :max_time => 123)
@alice.should_receive(:visible_posts).with(hash_including(:max_time => 123)).and_return(stub.as_null_object)
stream.posts
end
end
describe '#people' do
danielgrippi
a validé
it 'should call Person.all_from_aspects' do
class Person ; end
alice = stub.as_null_object
aspect_ids = [1,2,3]
stream = AspectStream.new(alice, [])
stream.stub(:aspect_ids).and_return(aspect_ids)
Person.should_receive(:all_from_aspects).with(stream.aspect_ids, alice)
stream.people
end
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
111
112
113
114
115
116
117
118
119
120
121
122
end
describe '#aspect' do
before do
alice = stub.as_null_object
@stream = AspectStream.new(alice, [1,2])
end
it "returns an aspect if the stream is not for all the user's aspects" do
@stream.stub(:for_all_aspects?).and_return(false)
@stream.aspect.should_not be_nil
end
it "returns nothing if the stream is not for all the user's aspects" do
@stream.stub(:for_all_aspects?).and_return(true)
@stream.aspect.should be_nil
end
end
describe 'for_all_aspects?' do
before do
alice = stub.as_null_object
alice.aspects.stub(:size).and_return(2)
@stream = AspectStream.new(alice, [1,2])
end
it "is true if the count of aspect_ids is equal to the size of the user's aspect count" do
@stream.aspect_ids.stub(:length).and_return(2)
@stream.should be_for_all_aspects
end
it "is false if the count of aspect_ids is not equal to the size of the user's aspect count" do
@stream.aspect_ids.stub(:length).and_return(1)
@stream.should_not be_for_all_aspects
end
end
end