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

This commit is contained in:
danielvincent 2010-10-20 18:15:19 -07:00
commit a1830b5d40
8 changed files with 232 additions and 314 deletions

View file

@ -37,5 +37,5 @@
= render type_partial(post), :post => post unless post.class == Album = render type_partial(post), :post => post unless post.class == Album
= will_paginate @posts = will_paginate @posts
- else - else
%h3=t('no posts to display!') %h3= t('.no_posts')

View file

@ -217,6 +217,7 @@ en:
save: "save" save: "save"
are_you_sure: "Are you sure?" are_you_sure: "Are you sure?"
remove_friend: "remove friend" remove_friend: "remove friend"
no_posts: "no posts to display!"
requests: requests:
new_request: new_request:
add_a_new_friend_to: "Add a new friend to" add_a_new_friend_to: "Add a new friend to"

View file

@ -5,149 +5,108 @@
require 'spec_helper' require 'spec_helper'
describe Diaspora::Parser do describe Diaspora::Parser do
before do let(:user) {Factory.create(:user)}
@user = Factory.create(:user) let(:aspect) {user.aspect(:name => 'spies')}
@aspect = @user.aspect(:name => 'spies') let(:user2) {Factory.create(:user)}
let(:aspect2){user2.aspect(:name => "pandas")}
@user3 = Factory.create :user let(:user3) {Factory.create :user}
@person = @user3.person let(:person) {user3.person}
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "pandas")
friend_users(@user, @aspect, @user2, @aspect2)
end
describe "parsing compliant XML object" do describe "parsing compliant XML object" do
before do
@xml = Factory.build(:status_message).to_diaspora_xml
end
it 'should be able to correctly handle comments with person in db' do it 'should be able to correctly handle comments with person in db' do
person = Factory.create(:person) post = user.post :status_message, :message => "hello", :to => aspect.id
post = Factory.create(:status_message, :person => @user.person) comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!")
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
xml = comment.to_diaspora_xml xml = comment.to_diaspora_xml
comment = Diaspora::Parser.from_xml(xml) comment = Diaspora::Parser.from_xml(xml)
comment.text.should == "Freedom!" comment.text.should == "Freedom!"
comment.person.should == person comment.person.should == @person
comment.post.should == post comment.post.should == post
end end
it 'should be able to correctly handle person on a comment with person not in db' do it 'should be able to correctly handle person on a comment with person not in db' do
commenter = Factory.create(:user) friend_users(user, aspect, user2, aspect2)
commenter_aspect = commenter.aspect :name => "bruisers" post = user.post :status_message, :message => "hello", :to => aspect.id
friend_users(@user, @aspect, commenter, commenter_aspect) comment = user2.comment "Fool!", :on => post
post = @user.post :status_message, :message => "hello", :to => @aspect.id
comment = commenter.comment "Fool!", :on => post
xml = comment.to_diaspora_xml xml = comment.to_diaspora_xml
commenter.delete user2.delete
commenter.person.delete user2.person.delete
parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml) parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml)
parsed_person.save.should be true parsed_person.save.should be true
parsed_person.diaspora_handle.should == commenter.person.diaspora_handle parsed_person.diaspora_handle.should == user2.person.diaspora_handle
parsed_person.profile.should_not be_nil parsed_person.profile.should_not be_nil
end end
it 'should marshal retractions' do it 'should accept retractions' do
person = @user2.person friend_users(user, aspect, user2, aspect2)
message = Factory.create(:status_message, :person => person) message = Factory.create(:status_message, :person => user2.person)
retraction = Retraction.for(message) retraction = Retraction.for(message)
xml = retraction.to_diaspora_xml xml = retraction.to_diaspora_xml
proc {@user.receive xml, person}.should change(StatusMessage, :count).by(-1) proc {user.receive xml, user2.person}.should change(StatusMessage, :count).by(-1)
end end
it "should create a new person upon getting a person request" do it "should create a new person upon getting a person request" do
person_count = Person.all.count request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
@user3.destroy user3.destroy
@person.destroy person.destroy
Person.all.count.should == person_count -1 user
@user.receive xml, @person lambda {user.receive xml, person}.should change(Person, :count).by(1)
Person.all.count.should == person_count
Person.first(:_id => original_person_id).serialized_public_key.include?("PUBLIC").should be true
url = "http://" + request.callback_url.split("/")[2] + "/"
Person.where(:url => url).first.id.should == original_person_id
end end
it "should not create a new person if the person is already here" do it "should not create a new person if the person is already here" do
person_count = Person.all.count request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person) original_person_id = user2.person.id
original_person_id = @user2.person.id
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
user
lambda {user.receive xml, user2.person}.should_not change(Person, :count)
Person.all.count.should be person_count user2.reload
@user.receive xml, @user2.person user2.person.reload
Person.all.count.should be person_count user2.serialized_private_key.include?("PRIVATE").should be true
@user2.reload
@user2.person.reload
@user2.serialized_private_key.include?("PRIVATE").should be true
url = "http://" + request.callback_url.split("/")[2] + "/" url = "http://" + request.callback_url.split("/")[2] + "/"
Person.where(:url => url).first.id.should == original_person_id Person.where(:url => url).first.id.should == original_person_id
end end
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
request = @user.send_friend_request_to( @user3.person, @aspect) request = user.send_friend_request_to( user3.person, aspect)
@user.reload user.reload
request.reverse_for @user3 request.reverse_for user3
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
@user3.person.destroy user3.person.destroy
@user3.destroy user3.destroy
@user.receive xml, @user3.person user.receive xml, user3.person
new_person = Person.first(:url => @user3.person.url) new_person = Person.first(:url => user3.person.url)
new_person.nil?.should be false new_person.nil?.should be false
@user.reload user.reload
@aspect.reload aspect.reload
@aspect.people.include?(new_person).should be true aspect.people.include?(new_person).should be true
@user.friends.include?(new_person).should be true user.friends.include?(new_person).should be true
end end
it 'should process retraction for a person' do it 'should process retraction for a person' do
user4 = Factory(:user) friend_users(user, aspect, user2, aspect2)
retraction = Retraction.for(user2)
person_count = Person.all.count
request = @user.send_friend_request_to( user4.person, @aspect)
@user.reload
request.reverse_for user4
xml = request.to_diaspora_xml
retraction = Retraction.for(user4)
retraction_xml = retraction.to_diaspora_xml retraction_xml = retraction.to_diaspora_xml
user4.person.destroy lambda {user.receive retraction_xml, user2.person}.should change{
user4.destroy aspect.reload.people.size}.by(-1)
@user.receive xml, user4.person
@aspect.reload
aspect_people_count = @aspect.people.size
#They are now friends
Person.count.should == person_count
@user.receive retraction_xml, user4.person
@aspect.reload
@aspect.people.size.should == aspect_people_count -1
end end
it 'should marshal a profile for a person' do it 'should marshal a profile for a person' do
friend_users(user, aspect, user2, aspect2)
#Create person #Create person
person = @user2.person person = user2.person
id = person.id id = person.id
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
person.save person.save
@ -167,7 +126,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob' old_profile.first_name.should == 'bob'
#Marshal profile #Marshal profile
@user.receive xml, person user.receive xml, person
#Check that marshaled profile is the same as old profile #Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id) person = Person.first(:id => person.id)

View file

@ -6,21 +6,11 @@ require 'spec_helper'
describe Diaspora::Webhooks do describe Diaspora::Webhooks do
before do before do
@user = Factory.create(:user) @user = Factory.build(:user)
@aspect = @user.aspect(:name => "losers")
@user2 = Factory.create(:user)
@aspect2 = @user2.aspect(:name => "losers")
friend_users(@user, @aspect, @user2, @aspect2)
end
describe "body" do
before do
@post = Factory.build(:status_message, :person => @user.person) @post = Factory.build(:status_message, :person => @user.person)
end end
it "should add the following methods to Post on inclusion" do it "should add the following methods to Post on inclusion" do
@post.respond_to?(:to_diaspora_xml).should be true @post.respond_to?(:to_diaspora_xml).should be true
end end
end
end end

View file

@ -63,10 +63,6 @@ describe Aspect do
before do before do
aspect aspect
user.activate_friend(friend, aspect) user.activate_friend(friend, aspect)
aspect2
friend_users(user, aspect, user2, aspect2)
aspect.reload
user.reload
end end
it 'belong to a user' do it 'belong to a user' do
@ -76,7 +72,7 @@ describe Aspect do
it 'should have people' do it 'should have people' do
aspect.people.all.include?(friend).should be true aspect.people.all.include?(friend).should be true
aspect.people.size.should == 2 aspect.people.size.should == 1
end end
describe '#aspects_with_person' do describe '#aspects_with_person' do
@ -85,10 +81,7 @@ describe Aspect do
user.reload user.reload
aspects = user.aspects_with_person(friend) aspects = user.aspects_with_person(friend)
aspects.size.should == 1 aspects.size.should == 1
aspects.first.id.should == aspect.id aspects.first.should == aspect
aspects.first.people.size.should == 2
aspects.first.people.include?(friend).should be true
aspects.first.people.include?(user2.person).should be true
end end
it 'returns multiple aspects if the person is there' do it 'returns multiple aspects if the person is there' do
@ -99,7 +92,6 @@ describe Aspect do
aspects.each{ |asp| asp.people.include?(friend) } aspects.each{ |asp| asp.people.include?(friend) }
aspects.should_not include aspect_without_friend aspects.should_not include aspect_without_friend
end end
end end
end end
@ -150,8 +142,6 @@ describe Aspect do
end end
context "aspect management" do context "aspect management" do
before do before do
friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user2, aspect2)
aspect.reload aspect.reload

View file

@ -5,140 +5,127 @@
require 'spec_helper' require 'spec_helper'
describe Comment do describe Comment do
describe "user" do let(:user) {Factory.create :user}
before do let(:aspect) {user.aspect(:name => "Doofuses")}
@user = Factory.create :user
@aspect = @user.aspect(:name => "Doofuses")
@user2 = Factory.create(:user) let(:user2) {Factory.create(:user)}
@aspect2 = @user2.aspect(:name => "Lame-faces") let(:aspect2) {user2.aspect(:name => "Lame-faces")}
end describe 'User#comment' do
let(:status) {user.post(:status_message, :message => "hello", :to => aspect)}
it "should be able to comment on his own status" do it "should be able to comment on his own status" do
status = Factory.create(:status_message, :person => @user.person)
status.comments.should == [] status.comments.should == []
@user.comment "Yeah, it was great", :on => status user.comment "Yeah, it was great", :on => status
status.reload.comments.first.text.should == "Yeah, it was great" status.reload.comments.first.text.should == "Yeah, it was great"
end end
it "should be able to comment on a person's status" do it "should be able to comment on a person's status" do
person= Factory.create :person user2.comment "sup dog", :on => status
status = Factory.create(:status_message, :person => person)
@user.comment "sup dog", :on => status
status.reload.comments.first.text.should == "sup dog" status.reload.comments.first.text.should == "sup dog"
status.reload.comments.first.person.should == @user.person end
end end
it 'should not send out comments when we have no people' do it 'should not send out comments when we have no people' do
status = Factory.create(:status_message, :person => @user.person) status = Factory.create(:status_message, :person => user.person)
User::QUEUE.should_not_receive(:add_post_request) User::QUEUE.should_not_receive(:add_post_request)
@user.comment "sup dog", :on => status user.comment "sup dog", :on => status
end end
describe 'comment propagation' do describe 'comment propagation' do
before do before do
friend_users(@user, Aspect.first(:id => @aspect.id), @user2, @aspect2) friend_users(user, aspect, user2, aspect2)
@person = Factory.create(:person) @person = Factory.create(:person)
@user.activate_friend(@person, Aspect.first(:id => @aspect.id)) user.activate_friend(@person, Aspect.first(:id => aspect.id))
@person2 = Factory.create(:person) @person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person) @person_status = Factory.build(:status_message, :person => @person)
@user.reload user.reload
@user_status = @user.post :status_message, :message => "hi", :to => @aspect.id user_status = user.post :status_message, :message => "hi", :to => aspect.id
@aspect.reload aspect.reload
@user.reload user.reload
end end
it 'should receive a comment from a person not on the pod' do it 'should receive a comment from a person not on the pod' do
user3 = Factory.create :user user3 = Factory.create :user
aspect3 = user3.aspect(:name => "blah") aspect3 = user3.aspect(:name => "blah")
friend_users(@user, @aspect, user3, aspect3) friend_users(user, aspect, user3, aspect3)
comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => @user_status) comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status)
comment.creator_signature = comment.sign_with_key(user3.encryption_key) comment.creator_signature = comment.sign_with_key(user3.encryption_key)
comment.post_creator_signature = comment.sign_with_key(@user.encryption_key) comment.post_creator_signature = comment.sign_with_key(user.encryption_key)
xml = @user.salmon(comment).xml_for(@user2) xml = user.salmon(comment).xml_for(user2)
user3.person.delete user3.person.delete
user3.delete user3.delete
@user_status.reload user_status.reload
@user_status.comments.should == [] user_status.comments.should == []
@user2.receive_salmon(xml) user.receive_salmon(xml)
@user_status.reload user_status.reload
@user_status.comments.include?(comment).should be true user_status.comments.include?(comment).should be true
end
it 'should have the post in the aspects post list' do
aspect = Aspect.first(:id => @aspect.id)
aspect.people.size.should == 2
aspect.post_ids.include?(@user_status.id).should be true
end end
it "should send a user's comment on a person's post to that person" do it "should send a user's comment on a person's post to that person" do
User::QUEUE.should_receive(:add_post_request) User::QUEUE.should_receive(:add_post_request)
@user.comment "yo", :on => @person_status user.comment "yo", :on => @person_status
end end
it 'should send a user comment on his own post to lots of people' do it 'should send a user comment on his own post to lots of people' do
User::QUEUE.should_receive(:add_post_request).twice User::QUEUE.should_receive(:add_post_request).twice
@user.comment "yo", :on => @user_status user.comment "yo", :on => user_status
end end
it 'should send a comment a person made on your post to all people' do it 'should send a comment a person made on your post to all people' do
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status) comment = Comment.new(:person_id => @person.id, :text => "balls", :post => user_status)
User::QUEUE.should_receive(:add_post_request).twice User::QUEUE.should_receive(:add_post_request).twice
@user.receive comment.to_diaspora_xml, @person user.receive comment.to_diaspora_xml, @person
end end
it 'should send a comment a user made on your post to all people' do it 'should send a comment a user made on your post to all people' do
comment = user2.comment( "balls", :on => user_status)
comment = @user2.comment( "balls", :on => @user_status)
User::QUEUE.should_receive(:add_post_request).twice User::QUEUE.should_receive(:add_post_request).twice
@user.receive comment.to_diaspora_xml, @user2.person user.receive comment.to_diaspora_xml, user2.person
end end
it 'should not send a comment a person made on his own post to anyone' do it 'should not send a comment a person made on his own post to anyone' do
User::QUEUE.should_not_receive(:add_post_request) User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status) comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
@user.receive comment.to_diaspora_xml, @person user.receive comment.to_diaspora_xml, @person
end end
it 'should not send a comment a person made on a person post to anyone' do it 'should not send a comment a person made on a person post to anyone' do
User::QUEUE.should_not_receive(:add_post_request) User::QUEUE.should_not_receive(:add_post_request)
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status) comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
@user.receive comment.to_diaspora_xml, @person user.receive comment.to_diaspora_xml, @person
end end
it 'should not clear the aspect post array on receiving a comment' do it 'should not clear the aspect post array on receiving a comment' do
@aspect.post_ids.include?(@user_status.id).should be true aspect.post_ids.include?(user_status.id).should be true
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status) comment = Comment.new(:person_id => @person.id, :text => "balls", :post => user_status)
@user.receive comment.to_diaspora_xml, @person user.receive comment.to_diaspora_xml, @person
@aspect.reload aspect.reload
@aspect.post_ids.include?(@user_status.id).should be true aspect.post_ids.include?(user_status.id).should be true
end end
end end
describe 'serialization' do describe 'serialization' do
it 'should serialize the commenter' do it 'should serialize the commenter' do
commenter = Factory.create(:user) commenter = Factory.create(:user)
commenter_aspect = commenter.aspect :name => "bruisers" commenter_aspect = commenter.aspect :name => "bruisers"
friend_users(@user, @aspect, commenter, commenter_aspect) friend_users(user, aspect, commenter, commenter_aspect)
post = @user.post :status_message, :message => "hello", :to => @aspect.id post = user.post :status_message, :message => "hello", :to => aspect.id
comment = commenter.comment "Fool!", :on => post comment = commenter.comment "Fool!", :on => post
comment.person.should_not == @user.person comment.person.should_not == user.person
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
end end
end end
end end
end

View file

@ -17,7 +17,6 @@ describe User do
before do before do
friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user2, aspect2)
friend_users(user, aspect, user3, aspect3)
end end
it 'should be able to parse and store a status message from xml' do it 'should be able to parse and store a status message from xml' do
@ -94,6 +93,10 @@ describe User do
end end
describe 'comments' do describe 'comments' do
before do
friend_users(user, aspect, user3, aspect3)
end
it 'should correctly marshal a stranger for the downstream user' do it 'should correctly marshal a stranger for the downstream user' do
post = user.post :status_message, :message => "hello", :to => aspect.id post = user.post :status_message, :message => "hello", :to => aspect.id

View file

@ -5,115 +5,103 @@
require 'spec_helper' require 'spec_helper'
describe User do describe User do
let!(:user) { Factory(:user_with_aspect) }
let!(:first_aspect) { user.aspects.first }
let!(:second_aspect) { user.aspect(:name => 'losers') }
let!(:user2) { Factory(:user_with_aspect) } let!(:user2) { Factory(:user_with_aspect) }
let!(:user3) { Factory(:user_with_aspect) }
let!(:user4) { Factory(:user_with_aspect) }
context 'with two posts' do
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id } let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id }
let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id } let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id }
let!(:status_message3) { user2.post :status_message, :message => "va", :to => user2.aspects.first.id }
let!(:status_message4) { user2.post :status_message, :message => "da", :public => true , :to => user2.aspects.first.id }
let!(:status_message5) { user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id}
let!(:status_message6) { user4.post :status_message, :message => "yooo", :to => user4.aspects.first.id}
before do
friend_users(user, first_aspect, user2, user2.aspects.first)
friend_users(user, second_aspect, user3, user3.aspects.first)
end
describe '#friends_not_in_aspect' do
it 'finds the people who are not in the given aspect' do
friend_users(user, first_aspect, user4, user4.aspects.first)
people = user.friends_not_in_aspect(first_aspect)
people.should == [user3.person]
people2 = user.friends_not_in_aspect(second_aspect)
people2.count.should == 2
people2.include?(user2.person).should be true
people2.include?(user4.person).should be true
end
end
describe "#visible_posts" do describe "#visible_posts" do
it "queries by person id" do it "queries by person id" do
user2.visible_posts(:person_id => user2.person.id).include?(status_message1).should == true query = user2.visible_posts(:person_id => user2.person.id)
user2.visible_posts(:person_id => user2.person.id).include?(status_message2).should == true query.include?(status_message1).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message3).should == true query.include?(status_message2).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message4).should == true
end end
it "selects public posts" do it "selects public posts" do
user2.visible_posts(:public => true).include?(status_message2).should == true query = user2.visible_posts(:public => true)
user2.visible_posts(:public => true).include?(status_message4).should == true query.include?(status_message2).should == true
query.include?(status_message1).should == false
end end
it "selects non public posts" do it "selects non public posts" do
user2.visible_posts(:public => false).include?(status_message1).should == true query = user2.visible_posts(:public => false)
user2.visible_posts(:public => false).include?(status_message3).should == true query.include?(status_message1).should == true
query.include?(status_message2).should == false
end end
it "selects by message contents" do it "selects by message contents" do
user2.visible_posts(:message => "hi").include?(status_message1).should == true user2.visible_posts(:message => "hi").include?(status_message1).should == true
end end
context 'with two users' do
let!(:user) {Factory :user}
let!(:first_aspect) {user.aspect(:name => 'bruisers')}
let!(:second_aspect) {user.aspect(:name => 'losers')}
it "queries by aspect" do it "queries by aspect" do
friend_users(user, second_aspect, user4, user4.aspects.first) friend_users(user, first_aspect, user2, user2.aspects.first)
user.receive status_message1.to_diaspora_xml, user2.person
user.receive status_message4.to_diaspora_xml, user2.person user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1]
user.receive status_message5.to_diaspora_xml, user3.person user.visible_posts(:by_members_of => second_aspect).should =~ []
user.receive status_message6.to_diaspora_xml, user4.person
user.visible_posts(:by_members_of => first_aspect).should =~ [status_message4]
user.visible_posts(:by_members_of => second_aspect).should =~ [status_message5, status_message6]
end end
end it '#find_visible_post_by_id' do
context 'querying' do
describe '#find_visible_post_by_id' do
it 'should query' do
user2.find_visible_post_by_id(status_message1.id).should == status_message1 user2.find_visible_post_by_id(status_message1.id).should == status_message1
user.find_visible_post_by_id(status_message1.id).should == nil user.find_visible_post_by_id(status_message1.id).should == nil
end end
end end
end
end
context 'with two users' do
let!(:user) {Factory :user}
let!(:first_aspect) {user.aspect(:name => 'bruisers')}
let!(:second_aspect) {user.aspect(:name => 'losers')}
describe '#friends_not_in_aspect' do
it 'finds the people who are not in the given aspect' do
user4 = Factory.create(:user_with_aspect)
friend_users(user, first_aspect, user4, user4.aspects.first)
friend_users(user, second_aspect, user2, user2.aspects.first)
people = user.friends_not_in_aspect(first_aspect)
people.should == [user2.person]
end
end
describe '#find_friend_by_id' do describe '#find_friend_by_id' do
it 'should find both friends' do it 'should find a friend' do
user.reload friend_users(user, first_aspect, user2, user2.aspects.first)
user.find_friend_by_id(user2.person.id).should == user2.person user.find_friend_by_id(user2.person.id).should == user2.person
user.find_friend_by_id(user3.person.id).should == user3.person
end end
it 'should not find a non-friend' do it 'should not find a non-friend' do
user3.find_friend_by_id(user4.person.id).should be nil user = Factory :user
end user.find_friend_by_id(user2.person.id).should be nil
end end
end end
end
context 'albums' do describe '#albums_by_aspect' do
let!(:first_aspect) {user2.aspect(:name => 'bruisers')}
let!(:second_aspect) {user2.aspect(:name => 'losers')}
before do before do
user.post :album, :name => "Georges", :to => first_aspect.id user2.post :album, :name => "Georges", :to => first_aspect.id
user.post :album, :name => "Borges", :to => first_aspect.id user2.post :album, :name => "Borges", :to => first_aspect.id
user.post :album, :name => "Luises", :to => second_aspect.id user2.post :album, :name => "Luises", :to => second_aspect.id
user.reload user2.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).should have(3).albums user2.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(first_aspect.reload).should have(2).albums user2.albums_by_aspect(first_aspect.reload).should have(2).albums
user.albums_by_aspect(second_aspect.reload).should have(1).album user2.albums_by_aspect(second_aspect.reload).should have(1).album
end end
end end
end end