Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
ilya 2010-09-21 17:52:57 -07:00
commit 662071be08
2 changed files with 64 additions and 72 deletions

View file

@ -35,11 +35,6 @@ module Diaspora
aspects.detect{|x| x.id == id } aspects.detect{|x| x.id == id }
end end
def album_by_id( id )
id = id.to_id
albums.detect{|x| x.id == id }
end
def aspects_with_post( id ) def aspects_with_post( id )
self.aspects.find_all_by_post_ids( id.to_id ) self.aspects.find_all_by_post_ids( id.to_id )
end end

View file

@ -7,82 +7,79 @@
require File.dirname(__FILE__) + '/../../spec_helper' require File.dirname(__FILE__) + '/../../spec_helper'
describe User do describe User do
let(:user) { Factory(:user) }
let(:user2) { Factory(:user) }
let(:user3) { Factory(:user) }
let(:user4) { Factory(:user) }
let!(:aspect) { user.aspect(:name => 'heroes') }
let!(:aspect2) { user.aspect(:name => 'losers') }
let!(:user2_aspect) { user2.aspect(:name => 'dudes') }
let!(:user3_aspect) { user3.aspect(:name => 'dudes') }
let!(:user4_aspect) { user4.aspect(:name => 'dudes') }
let(:status_message1) { user2.post :status_message, :message => "hi", :to => user2_aspect.id }
let(:status_message2) { user3.post :status_message, :message => "heyyyy", :to => user3_aspect.id }
let(:status_message3) { user4.post :status_message, :message => "yooo", :to => user4_aspect.id }
before do before do
@user = Factory.create(:user) friend_users(user, aspect, user2, user2_aspect)
@aspect = @user.aspect(:name => 'heroes') friend_users(user, aspect2, user3, user3_aspect)
@aspect2 = @user.aspect(:name => 'losers') friend_users(user, aspect2, user4, user4_aspect)
@user2 = Factory.create :user
@user2_aspect = @user2.aspect(:name => 'dudes')
friend_users(@user, @aspect, @user2, @user2_aspect)
@user3 = Factory.create :user
@user3_aspect = @user3.aspect(:name => 'dudes')
friend_users(@user, @aspect2, @user3, @user3_aspect)
@user4 = Factory.create :user
@user4_aspect = @user4.aspect(:name => 'dudes')
friend_users(@user, @aspect2, @user4, @user4_aspect)
end end
it 'should generate a valid stream for a aspect of people' do it 'should generate a valid stream for a aspect of people' do
status_message1 = @user2.post :status_message, :message => "hi", :to => @user2_aspect.id (1..3).each{ |n|
status_message2 = @user3.post :status_message, :message => "heyyyy", :to => @user3_aspect.id eval("user.receive status_message#{n}.to_diaspora_xml")
status_message3 = @user4.post :status_message, :message => "yooo", :to => @user4_aspect.id }
@user.receive status_message1.to_diaspora_xml user.visible_posts(:by_members_of => aspect).should include status_message1
@user.receive status_message2.to_diaspora_xml user.visible_posts(:by_members_of => aspect).should_not include status_message2
@user.receive status_message3.to_diaspora_xml user.visible_posts(:by_members_of => aspect).should_not include status_message3
@user.reload
@user.visible_posts(:by_members_of => @aspect).include?(status_message1).should be true user.visible_posts(:by_members_of => aspect2).should_not include status_message1
@user.visible_posts(:by_members_of => @aspect).include?(status_message2).should be false user.visible_posts(:by_members_of => aspect2).should include status_message2
@user.visible_posts(:by_members_of => @aspect).include?(status_message3).should be false user.visible_posts(:by_members_of => aspect2).should include status_message3
@user.visible_posts(:by_members_of => @aspect2).include?(status_message1).should be false
@user.visible_posts(:by_members_of => @aspect2).include?(status_message2).should be true
@user.visible_posts(:by_members_of => @aspect2).include?(status_message3).should be true
end end
describe 'querying' do context 'querying' do
describe '#find_visible_post_by_id' do
it 'should find a visible post by id' do it 'should query' do
status_message1 = @user.post :status_message, :message => "hi", :to => @aspect.id user2.find_visible_post_by_id(status_message1.id).should == status_message1
status_message2 = @user2.post :status_message, :message => "heyyyy", :to => @user2_aspect.id user.find_visible_post_by_id(status_message1.id).should == nil
status_message3 = @user3.post :status_message, :message => "yooo", :to => @user3_aspect.id end
end
@user.find_visible_post_by_id(status_message1.id).should == status_message1
@user2.find_visible_post_by_id(status_message1.id).should == nil
end end
end context 'albums' do
describe 'albums' do
before do before do
@album = @user.post :album, :name => "Georges", :to => @aspect.id @album = user.post :album, :name => "Georges", :to => aspect.id
@aspect.reload aspect.reload
@aspect2.reload aspect2.reload
@user.reload user.reload
@album2 = @user.post :album, :name => "Borges", :to => @aspect.id @album2 = user.post :album, :name => "Borges", :to => aspect.id
@aspect.reload aspect.reload
@aspect2.reload aspect2.reload
@user.reload user.reload
@user.post :album, :name => "Luises", :to => @aspect2.id user.post :album, :name => "Luises", :to => aspect2.id
@aspect.reload aspect.reload
@aspect2.reload aspect2.reload
@user.reload user.reload
end end
it 'should find all albums if passed :all' do it 'should find all albums if passed :all' do
@user.albums_by_aspect(:all).size.should == 3 user.albums_by_aspect(:all).should have(3).albums
end end
it 'should return the right number of albums' do it 'should return the right number of albums' do
@user.albums_by_aspect(@aspect).size.should == 2 user.albums_by_aspect(aspect).should have(2).albums
@user.albums_by_aspect(@aspect2).size.should == 1 user.albums_by_aspect(aspect2).should have(1).album
end end
end end
end end