diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 30c06b11d..27ee97472 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -12,15 +12,42 @@ describe Post do describe 'scopes' do describe '.for_a_stream' do - it 'returns the posts ordered and limited by unix time' - it 'includes everything in .includes_for_a_stream' - it 'is limited to 15 posts' + before do + time_interval = 1000 + time_past = 1000000 + @posts = (1..3).map do |n| + aspect_to_post = alice.aspects.where(:name => "generic").first + post = alice.post :status_message, :text => "#{alice.username} - #{n}", :to => aspect_to_post.id + post.created_at = (post.created_at-time_past) - time_interval + post.updated_at = (post.updated_at-time_past) + time_interval + post.save + time_interval += 1000 + post + end + end + + it 'returns the posts ordered and limited by unix time' do + Post.for_a_stream(Time.now + 1, "created_at").should == @posts + Post.for_a_stream(Time.now + 1, "updated_at").should == @posts.reverse + end + + it 'includes everything in .includes_for_a_stream' do + Post.should_receive(:includes_for_a_stream) + Post.for_a_stream(Time.now + 1, "created_at") + end + it 'is limited to 15 posts' do + Post.stub(:by_max_time).and_return(Post) + Post.stub(:includes_for_a_stream).and_return(Post) + Post.should_receive(:limit) + Post.for_a_stream(Time.now + 1, "created_at") + end end describe 'includes for a stream' do it 'inclues author profile and mentions' it 'should include photos and root of reshares(but does not)' end + end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 66e685b7f..b4d653488 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -19,11 +19,46 @@ describe StatusMessage do describe 'scopes' do describe '.where_person_is_mentioned' do - it 'returns status messages where the given person is mentioned' + it 'returns status messages where the given person is mentioned' do + @bo = bob.person + @test_string = "@{Daniel; #{@bo.diaspora_handle}} can mention people like Raph" + + Factory.create(:status_message, :text => @test_string ) + Factory.create(:status_message, :text => @test_string ) + Factory(:status_message) + + StatusMessage.where_person_is_mentioned(@bo).count.should == 2 + end end describe '.owned_or_visible_by_user' do - it 'scopes status_messages based on posts visisble via contacts or public' + before do + @you = bob + @public_post = Factory(:status_message, :public => true) + @your_post = Factory(:status_message, :author => @you.person) + @post_from_contact = eve.post(:status_message, :text => 'wooo', :to => eve.aspects.where(:name => 'generic').first) + @post_from_stranger = Factory(:status_message, :public => false) + end + + it 'returns post from your contacts' do + StatusMessage.owned_or_visible_by_user(@you).should include(@post_from_contact) + end + + it 'returns your posts' do + StatusMessage.owned_or_visible_by_user(@you).should include(@your_post) + end + + it 'returns public posts' do + StatusMessage.owned_or_visible_by_user(@you).should include(@public_post) + end + + it 'does not return non contacts, non-public post' do + StatusMessage.owned_or_visible_by_user(@you).should_not include(@post_from_stranger) + end + + it 'should return the three visible posts' do + StatusMessage.owned_or_visible_by_user(@you).count.should == 3 + end end end