Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
a1830b5d40
8 changed files with 232 additions and 314 deletions
|
|
@ -37,5 +37,5 @@
|
|||
= render type_partial(post), :post => post unless post.class == Album
|
||||
= will_paginate @posts
|
||||
- else
|
||||
%h3=t('no posts to display!')
|
||||
%h3= t('.no_posts')
|
||||
|
||||
|
|
|
|||
|
|
@ -217,6 +217,7 @@ en:
|
|||
save: "save"
|
||||
are_you_sure: "Are you sure?"
|
||||
remove_friend: "remove friend"
|
||||
no_posts: "no posts to display!"
|
||||
requests:
|
||||
new_request:
|
||||
add_a_new_friend_to: "Add a new friend to"
|
||||
|
|
|
|||
|
|
@ -5,149 +5,108 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Diaspora::Parser do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspect(:name => 'spies')
|
||||
|
||||
@user3 = Factory.create :user
|
||||
@person = @user3.person
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspect(:name => "pandas")
|
||||
friend_users(@user, @aspect, @user2, @aspect2)
|
||||
end
|
||||
let(:user) {Factory.create(:user)}
|
||||
let(:aspect) {user.aspect(:name => 'spies')}
|
||||
let(:user2) {Factory.create(:user)}
|
||||
let(:aspect2){user2.aspect(:name => "pandas")}
|
||||
let(:user3) {Factory.create :user}
|
||||
let(:person) {user3.person}
|
||||
|
||||
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
|
||||
person = Factory.create(:person)
|
||||
post = Factory.create(:status_message, :person => @user.person)
|
||||
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
|
||||
post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||
comment = Factory.build(:comment, :post => post, :person => @person, :text => "Freedom!")
|
||||
xml = comment.to_diaspora_xml
|
||||
|
||||
comment = Diaspora::Parser.from_xml(xml)
|
||||
comment.text.should == "Freedom!"
|
||||
comment.person.should == person
|
||||
comment.person.should == @person
|
||||
comment.post.should == post
|
||||
end
|
||||
|
||||
it 'should be able to correctly handle person on a comment with person not in db' do
|
||||
commenter = Factory.create(:user)
|
||||
commenter_aspect = commenter.aspect :name => "bruisers"
|
||||
friend_users(@user, @aspect, commenter, commenter_aspect)
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
comment = commenter.comment "Fool!", :on => post
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||
comment = user2.comment "Fool!", :on => post
|
||||
|
||||
xml = comment.to_diaspora_xml
|
||||
commenter.delete
|
||||
commenter.person.delete
|
||||
user2.delete
|
||||
user2.person.delete
|
||||
|
||||
parsed_person = Diaspora::Parser::parse_or_find_person_from_xml(xml)
|
||||
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
|
||||
end
|
||||
|
||||
it 'should marshal retractions' do
|
||||
person = @user2.person
|
||||
message = Factory.create(:status_message, :person => person)
|
||||
it 'should accept retractions' do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
message = Factory.create(:status_message, :person => user2.person)
|
||||
retraction = Retraction.for(message)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
@user3.destroy
|
||||
@person.destroy
|
||||
Person.all.count.should == person_count -1
|
||||
@user.receive xml, @person
|
||||
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
|
||||
user3.destroy
|
||||
person.destroy
|
||||
user
|
||||
lambda {user.receive xml, person}.should change(Person, :count).by(1)
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
original_person_id = @user2.person.id
|
||||
request = Request.instantiate(:to =>"http://www.google.com/", :from => user2.person)
|
||||
original_person_id = user2.person.id
|
||||
xml = request.to_diaspora_xml
|
||||
user
|
||||
lambda {user.receive xml, user2.person}.should_not change(Person, :count)
|
||||
|
||||
Person.all.count.should be person_count
|
||||
@user.receive xml, @user2.person
|
||||
Person.all.count.should be person_count
|
||||
|
||||
@user2.reload
|
||||
@user2.person.reload
|
||||
@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] + "/"
|
||||
Person.where(:url => url).first.id.should == original_person_id
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
request = @user.send_friend_request_to( @user3.person, @aspect)
|
||||
@user.reload
|
||||
request.reverse_for @user3
|
||||
request = user.send_friend_request_to( user3.person, aspect)
|
||||
user.reload
|
||||
request.reverse_for user3
|
||||
|
||||
xml = request.to_diaspora_xml
|
||||
|
||||
@user3.person.destroy
|
||||
@user3.destroy
|
||||
user3.person.destroy
|
||||
user3.destroy
|
||||
|
||||
@user.receive xml, @user3.person
|
||||
new_person = Person.first(:url => @user3.person.url)
|
||||
user.receive xml, user3.person
|
||||
new_person = Person.first(:url => user3.person.url)
|
||||
new_person.nil?.should be false
|
||||
|
||||
@user.reload
|
||||
@aspect.reload
|
||||
@aspect.people.include?(new_person).should be true
|
||||
@user.friends.include?(new_person).should be true
|
||||
user.reload
|
||||
aspect.reload
|
||||
aspect.people.include?(new_person).should be true
|
||||
user.friends.include?(new_person).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
user4 = Factory(:user)
|
||||
|
||||
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)
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
retraction = Retraction.for(user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
||||
user4.person.destroy
|
||||
user4.destroy
|
||||
@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
|
||||
lambda {user.receive retraction_xml, user2.person}.should change{
|
||||
aspect.reload.people.size}.by(-1)
|
||||
end
|
||||
|
||||
it 'should marshal a profile for a person' do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
#Create person
|
||||
person = @user2.person
|
||||
person = user2.person
|
||||
id = person.id
|
||||
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
|
||||
person.save
|
||||
|
|
@ -167,7 +126,7 @@ describe Diaspora::Parser do
|
|||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
@user.receive xml, person
|
||||
user.receive xml, person
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
person = Person.first(:id => person.id)
|
||||
|
|
|
|||
|
|
@ -6,21 +6,11 @@ require 'spec_helper'
|
|||
|
||||
describe Diaspora::Webhooks do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspect(:name => "losers")
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspect(:name => "losers")
|
||||
friend_users(@user, @aspect, @user2, @aspect2)
|
||||
@user = Factory.build(:user)
|
||||
@post = Factory.build(:status_message, :person => @user.person)
|
||||
end
|
||||
|
||||
describe "body" do
|
||||
before do
|
||||
@post = Factory.build(:status_message, :person => @user.person)
|
||||
end
|
||||
|
||||
it "should add the following methods to Post on inclusion" do
|
||||
@post.respond_to?(:to_diaspora_xml).should be true
|
||||
end
|
||||
|
||||
it "should add the following methods to Post on inclusion" do
|
||||
@post.respond_to?(:to_diaspora_xml).should be true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -63,10 +63,6 @@ describe Aspect do
|
|||
before do
|
||||
aspect
|
||||
user.activate_friend(friend, aspect)
|
||||
aspect2
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
aspect.reload
|
||||
user.reload
|
||||
end
|
||||
|
||||
it 'belong to a user' do
|
||||
|
|
@ -76,7 +72,7 @@ describe Aspect do
|
|||
|
||||
it 'should have people' do
|
||||
aspect.people.all.include?(friend).should be true
|
||||
aspect.people.size.should == 2
|
||||
aspect.people.size.should == 1
|
||||
end
|
||||
|
||||
describe '#aspects_with_person' do
|
||||
|
|
@ -85,10 +81,7 @@ describe Aspect do
|
|||
user.reload
|
||||
aspects = user.aspects_with_person(friend)
|
||||
aspects.size.should == 1
|
||||
aspects.first.id.should == aspect.id
|
||||
aspects.first.people.size.should == 2
|
||||
aspects.first.people.include?(friend).should be true
|
||||
aspects.first.people.include?(user2.person).should be true
|
||||
aspects.first.should == aspect
|
||||
end
|
||||
|
||||
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.should_not include aspect_without_friend
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -150,8 +142,6 @@ describe Aspect do
|
|||
end
|
||||
|
||||
context "aspect management" do
|
||||
|
||||
|
||||
before do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
aspect.reload
|
||||
|
|
|
|||
|
|
@ -5,140 +5,127 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Comment do
|
||||
describe "user" do
|
||||
before do
|
||||
@user = Factory.create :user
|
||||
@aspect = @user.aspect(:name => "Doofuses")
|
||||
let(:user) {Factory.create :user}
|
||||
let(:aspect) {user.aspect(:name => "Doofuses")}
|
||||
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspect(:name => "Lame-faces")
|
||||
end
|
||||
let(:user2) {Factory.create(:user)}
|
||||
let(:aspect2) {user2.aspect(:name => "Lame-faces")}
|
||||
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
|
||||
status = Factory.create(:status_message, :person => @user.person)
|
||||
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"
|
||||
end
|
||||
|
||||
it "should be able to comment on a person's status" do
|
||||
person= Factory.create :person
|
||||
status = Factory.create(:status_message, :person => person)
|
||||
@user.comment "sup dog", :on => status
|
||||
|
||||
user2.comment "sup dog", :on => status
|
||||
status.reload.comments.first.text.should == "sup dog"
|
||||
status.reload.comments.first.person.should == @user.person
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not send out comments when we have no people' do
|
||||
status = Factory.create(:status_message, :person => user.person)
|
||||
User::QUEUE.should_not_receive(:add_post_request)
|
||||
user.comment "sup dog", :on => status
|
||||
end
|
||||
|
||||
describe 'comment propagation' do
|
||||
before do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
|
||||
@person = Factory.create(:person)
|
||||
user.activate_friend(@person, Aspect.first(:id => aspect.id))
|
||||
|
||||
@person2 = Factory.create(:person)
|
||||
@person_status = Factory.build(:status_message, :person => @person)
|
||||
|
||||
user.reload
|
||||
user_status = user.post :status_message, :message => "hi", :to => aspect.id
|
||||
|
||||
aspect.reload
|
||||
user.reload
|
||||
end
|
||||
|
||||
it 'should not send out comments when we have no people' do
|
||||
status = Factory.create(:status_message, :person => @user.person)
|
||||
it 'should receive a comment from a person not on the pod' do
|
||||
user3 = Factory.create :user
|
||||
aspect3 = user3.aspect(:name => "blah")
|
||||
|
||||
friend_users(user, aspect, user3, aspect3)
|
||||
|
||||
comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => user_status)
|
||||
comment.creator_signature = comment.sign_with_key(user3.encryption_key)
|
||||
|
||||
|
||||
comment.post_creator_signature = comment.sign_with_key(user.encryption_key)
|
||||
xml = user.salmon(comment).xml_for(user2)
|
||||
|
||||
user3.person.delete
|
||||
user3.delete
|
||||
|
||||
|
||||
user_status.reload
|
||||
user_status.comments.should == []
|
||||
user.receive_salmon(xml)
|
||||
user_status.reload
|
||||
user_status.comments.include?(comment).should be true
|
||||
end
|
||||
|
||||
it "should send a user's comment on a person's post to that person" do
|
||||
User::QUEUE.should_receive(:add_post_request)
|
||||
user.comment "yo", :on => @person_status
|
||||
end
|
||||
|
||||
it 'should send a user comment on his own post to lots of people' do
|
||||
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
user.comment "yo", :on => user_status
|
||||
end
|
||||
|
||||
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)
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
|
||||
it 'should send a comment a user made on your post to all people' do
|
||||
comment = user2.comment( "balls", :on => user_status)
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
user.receive comment.to_diaspora_xml, user2.person
|
||||
end
|
||||
|
||||
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.comment "sup dog", :on => status
|
||||
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
|
||||
user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
|
||||
describe 'comment propagation' do
|
||||
before do
|
||||
friend_users(@user, Aspect.first(:id => @aspect.id), @user2, @aspect2)
|
||||
|
||||
@person = Factory.create(:person)
|
||||
@user.activate_friend(@person, Aspect.first(:id => @aspect.id))
|
||||
|
||||
@person2 = Factory.create(:person)
|
||||
@person_status = Factory.build(:status_message, :person => @person)
|
||||
|
||||
@user.reload
|
||||
@user_status = @user.post :status_message, :message => "hi", :to => @aspect.id
|
||||
|
||||
@aspect.reload
|
||||
@user.reload
|
||||
end
|
||||
|
||||
it 'should receive a comment from a person not on the pod' do
|
||||
user3 = Factory.create :user
|
||||
aspect3 = user3.aspect(:name => "blah")
|
||||
|
||||
friend_users(@user, @aspect, user3, aspect3)
|
||||
|
||||
comment = Comment.new(:person_id => user3.person.id, :text => "hey", :post => @user_status)
|
||||
comment.creator_signature = comment.sign_with_key(user3.encryption_key)
|
||||
|
||||
|
||||
comment.post_creator_signature = comment.sign_with_key(@user.encryption_key)
|
||||
xml = @user.salmon(comment).xml_for(@user2)
|
||||
|
||||
user3.person.delete
|
||||
user3.delete
|
||||
|
||||
|
||||
@user_status.reload
|
||||
@user_status.comments.should == []
|
||||
@user2.receive_salmon(xml)
|
||||
@user_status.reload
|
||||
@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
|
||||
|
||||
it "should send a user's comment on a person's post to that person" do
|
||||
User::QUEUE.should_receive(:add_post_request)
|
||||
@user.comment "yo", :on => @person_status
|
||||
end
|
||||
|
||||
it 'should send a user comment on his own post to lots of people' do
|
||||
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
@user.comment "yo", :on => @user_status
|
||||
end
|
||||
|
||||
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)
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
@user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
|
||||
it 'should send a comment a user made on your post to all people' do
|
||||
|
||||
comment = @user2.comment( "balls", :on => @user_status)
|
||||
User::QUEUE.should_receive(:add_post_request).twice
|
||||
@user.receive comment.to_diaspora_xml, @user2.person
|
||||
end
|
||||
|
||||
it 'should not send a comment a person made on his own post to anyone' do
|
||||
User::QUEUE.should_not_receive(:add_post_request)
|
||||
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @person_status)
|
||||
@user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
|
||||
it 'should not send a comment a person made on a person post to anyone' do
|
||||
User::QUEUE.should_not_receive(:add_post_request)
|
||||
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
|
||||
@user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
|
||||
it 'should not clear the aspect post array on receiving a comment' do
|
||||
@aspect.post_ids.include?(@user_status.id).should be true
|
||||
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => @user_status)
|
||||
|
||||
@user.receive comment.to_diaspora_xml, @person
|
||||
|
||||
@aspect.reload
|
||||
@aspect.post_ids.include?(@user_status.id).should be true
|
||||
end
|
||||
it 'should not send a comment a person made on a person post to anyone' do
|
||||
User::QUEUE.should_not_receive(:add_post_request)
|
||||
comment = Comment.new(:person_id => @person2.id, :text => "balls", :post => @person_status)
|
||||
user.receive comment.to_diaspora_xml, @person
|
||||
end
|
||||
describe 'serialization' do
|
||||
it 'should serialize the commenter' do
|
||||
commenter = Factory.create(:user)
|
||||
commenter_aspect = commenter.aspect :name => "bruisers"
|
||||
friend_users(@user, @aspect, commenter, commenter_aspect)
|
||||
post = @user.post :status_message, :message => "hello", :to => @aspect.id
|
||||
comment = commenter.comment "Fool!", :on => post
|
||||
comment.person.should_not == @user.person
|
||||
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
|
||||
end
|
||||
|
||||
it 'should not clear the aspect post array on receiving a comment' do
|
||||
aspect.post_ids.include?(user_status.id).should be true
|
||||
comment = Comment.new(:person_id => @person.id, :text => "balls", :post => user_status)
|
||||
|
||||
user.receive comment.to_diaspora_xml, @person
|
||||
|
||||
aspect.reload
|
||||
aspect.post_ids.include?(user_status.id).should be true
|
||||
end
|
||||
end
|
||||
describe 'serialization' do
|
||||
it 'should serialize the commenter' do
|
||||
commenter = Factory.create(:user)
|
||||
commenter_aspect = commenter.aspect :name => "bruisers"
|
||||
friend_users(user, aspect, commenter, commenter_aspect)
|
||||
post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||
comment = commenter.comment "Fool!", :on => post
|
||||
comment.person.should_not == user.person
|
||||
comment.to_diaspora_xml.include?(commenter.person.id.to_s).should be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ describe User do
|
|||
|
||||
before do
|
||||
friend_users(user, aspect, user2, aspect2)
|
||||
friend_users(user, aspect, user3, aspect3)
|
||||
end
|
||||
|
||||
it 'should be able to parse and store a status message from xml' do
|
||||
|
|
@ -94,6 +93,10 @@ describe User do
|
|||
end
|
||||
|
||||
describe 'comments' do
|
||||
before do
|
||||
friend_users(user, aspect, user3, aspect3)
|
||||
end
|
||||
|
||||
it 'should correctly marshal a stranger for the downstream user' do
|
||||
|
||||
post = user.post :status_message, :message => "hello", :to => aspect.id
|
||||
|
|
|
|||
|
|
@ -5,115 +5,103 @@
|
|||
require 'spec_helper'
|
||||
|
||||
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!(:user3) { Factory(:user_with_aspect) }
|
||||
let!(:user4) { Factory(:user_with_aspect) }
|
||||
|
||||
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_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
|
||||
context 'with two posts' do
|
||||
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 }
|
||||
|
||||
|
||||
|
||||
describe "#visible_posts" do
|
||||
it "queries by person id" do
|
||||
user2.visible_posts(:person_id => user2.person.id).include?(status_message1).should == true
|
||||
user2.visible_posts(:person_id => user2.person.id).include?(status_message2).should == true
|
||||
user2.visible_posts(:person_id => user2.person.id).include?(status_message3).should == true
|
||||
user2.visible_posts(:person_id => user2.person.id).include?(status_message4).should == true
|
||||
end
|
||||
it "queries by person id" do
|
||||
query = user2.visible_posts(:person_id => user2.person.id)
|
||||
query.include?(status_message1).should == true
|
||||
query.include?(status_message2).should == true
|
||||
end
|
||||
|
||||
it "selects public posts" do
|
||||
user2.visible_posts(:public => true).include?(status_message2).should == true
|
||||
user2.visible_posts(:public => true).include?(status_message4).should == true
|
||||
end
|
||||
it "selects public posts" do
|
||||
query = user2.visible_posts(:public => true)
|
||||
query.include?(status_message2).should == true
|
||||
query.include?(status_message1).should == false
|
||||
end
|
||||
|
||||
it "selects non public posts" do
|
||||
user2.visible_posts(:public => false).include?(status_message1).should == true
|
||||
user2.visible_posts(:public => false).include?(status_message3).should == true
|
||||
end
|
||||
it "selects non public posts" do
|
||||
query = user2.visible_posts(:public => false)
|
||||
query.include?(status_message1).should == true
|
||||
query.include?(status_message2).should == false
|
||||
end
|
||||
|
||||
it "selects by message contents" do
|
||||
user2.visible_posts(:message => "hi").include?(status_message1).should == true
|
||||
end
|
||||
it "selects by message contents" do
|
||||
user2.visible_posts(:message => "hi").include?(status_message1).should == true
|
||||
end
|
||||
|
||||
it "queries by aspect" do
|
||||
friend_users(user, second_aspect, user4, user4.aspects.first)
|
||||
context 'with two users' do
|
||||
let!(:user) {Factory :user}
|
||||
let!(:first_aspect) {user.aspect(:name => 'bruisers')}
|
||||
let!(:second_aspect) {user.aspect(:name => 'losers')}
|
||||
|
||||
user.receive status_message4.to_diaspora_xml, user2.person
|
||||
user.receive status_message5.to_diaspora_xml, user3.person
|
||||
user.receive status_message6.to_diaspora_xml, user4.person
|
||||
it "queries by aspect" do
|
||||
friend_users(user, first_aspect, user2, user2.aspects.first)
|
||||
user.receive status_message1.to_diaspora_xml, user2.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]
|
||||
user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1]
|
||||
user.visible_posts(:by_members_of => second_aspect).should =~ []
|
||||
end
|
||||
it '#find_visible_post_by_id' do
|
||||
user2.find_visible_post_by_id(status_message1.id).should == status_message1
|
||||
user.find_visible_post_by_id(status_message1.id).should == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
user.find_visible_post_by_id(status_message1.id).should == nil
|
||||
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
|
||||
it 'should find both friends' do
|
||||
user.reload
|
||||
it 'should find a friend' do
|
||||
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(user3.person.id).should == user3.person
|
||||
end
|
||||
|
||||
it 'should not find a non-friend' do
|
||||
user3.find_friend_by_id(user4.person.id).should be nil
|
||||
user = Factory :user
|
||||
user.find_friend_by_id(user2.person.id).should be nil
|
||||
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
|
||||
user.post :album, :name => "Georges", :to => first_aspect.id
|
||||
user.post :album, :name => "Borges", :to => first_aspect.id
|
||||
user.post :album, :name => "Luises", :to => second_aspect.id
|
||||
user.reload
|
||||
user2.post :album, :name => "Georges", :to => first_aspect.id
|
||||
user2.post :album, :name => "Borges", :to => first_aspect.id
|
||||
user2.post :album, :name => "Luises", :to => second_aspect.id
|
||||
user2.reload
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it 'should return the right number of albums' do
|
||||
user.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(first_aspect.reload).should have(2).albums
|
||||
user2.albums_by_aspect(second_aspect.reload).should have(1).album
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue