Merge remote branch 'upstream/master' into ubuntu

This commit is contained in:
Alec Leamas 2010-10-13 10:01:56 +02:00
commit 747c95515e
19 changed files with 241 additions and 202 deletions

View file

@ -8,7 +8,7 @@ gem 'devise', '1.1.3'
gem 'devise-mongo_mapper', :git => 'git://github.com/collectiveidea/devise-mongo_mapper'
gem 'devise_invitable', '~> 0.3.4'
#Mongo
gem 'mongo_mapper', :branch => 'rails3', :git => 'http://github.com/jnunemaker/mongomapper.git'
gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git'
gem 'bson_ext', '1.1'
gem 'bson', '1.1'
@ -32,7 +32,7 @@ gem 'thin'
#Websocket
gem 'em-websocket'
gem 'magent', :git => 'http://github.com/dcu/magent.git'
gem 'magent', :git => 'git://github.com/dcu/magent.git'
#File uploading
gem 'carrierwave', :git => 'git://github.com/rsofaer/carrierwave.git' , :branch => 'master' #Untested mongomapper branch

View file

@ -13,6 +13,15 @@ GIT
devise-mongo_mapper (0.0.1)
devise (~> 1.1.0)
GIT
remote: git://github.com/dcu/magent.git
revision: fe08cc6e9d4c1772035f84bcfb665d17b00ac625
specs:
magent (1.0.0)
em-websocket
mongo
uuidtools
GIT
remote: git://github.com/igrigorik/em-http-request.git
revision: bf62d67fc72d6e701be5037e239dd470194b8e45
@ -22,6 +31,16 @@ GIT
addressable (>= 2.0.0)
eventmachine (>= 0.12.9)
GIT
remote: git://github.com/jnunemaker/mongomapper.git
revision: fd59b0ab068be7321f8e84b9dc12fb4fa6b8535d
branch: rails3
specs:
mongo_mapper (0.8.4)
activemodel (~> 3.0.0)
activesupport (~> 3.0.0)
plucky (~> 0.3.6)
GIT
remote: git://github.com/rsofaer/carrierwave.git
revision: 9edb8bdddd2236742a85bfd7b260387498d01f88
@ -47,25 +66,6 @@ GIT
capistrano (>= 2.5.5)
highline (>= 1.4.0)
GIT
remote: http://github.com/dcu/magent.git
revision: 5d664351b305141158fc69fc495456414821adb3
specs:
magent (1.0.0)
em-websocket
mongo
uuidtools
GIT
remote: http://github.com/jnunemaker/mongomapper.git
revision: fd59b0ab068be7321f8e84b9dc12fb4fa6b8535d
branch: rails3
specs:
mongo_mapper (0.8.4)
activemodel (~> 3.0.0)
activesupport (~> 3.0.0)
plucky (~> 0.3.6)
GEM
remote: http://rubygems.org/
specs:
@ -96,7 +96,7 @@ GEM
activemodel (= 3.0.0)
activesupport (= 3.0.0)
activesupport (3.0.0)
addressable (2.2.1)
addressable (2.2.2)
arel (1.0.1)
activesupport (~> 3.0.0)
aws (2.3.21)
@ -172,7 +172,7 @@ GEM
mini_fb (1.1.3)
hashie
rest-client
mini_magick (2.1)
mini_magick (2.3)
subexec (~> 0.0.4)
mocha (0.9.8)
rake

View file

@ -34,6 +34,7 @@ class Person
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
def self.search(query)
return Person.all if query.to_s.empty?
qTokens = query.to_s.strip.split(" ")
fullQueryText = Regexp.escape( query.to_s.strip )
p = []

5
ci.sh
View file

@ -4,6 +4,7 @@ echo "**************************************************************************
echo "* ruby 1.8.7-p249 build *" &&
echo "*************************************************************************************************" &&
echo "" &&
rm Gemfile.lock &&
source /usr/local/rvm/scripts/rvm &&
rvm use ruby-1.8.7-p249 &&
bundle install &&
@ -13,8 +14,8 @@ echo "**************************************************************************
echo "* ruby 1.9.2-p0 build *" &&
echo "*************************************************************************************************" &&
echo "" &&
rm Gemfile.lock &&
source /usr/local/rvm/scripts/rvm &&
rvm use ruby-1.9.2-p0 &&
bundle install &&
bundle exec rake ci &&
rm Gemfile.lock
bundle exec rake ci

View file

@ -5,28 +5,49 @@ module Diaspora
salmon = Salmon::SalmonSlap.parse salmon_xml, self
if salmon.verified_for_key?(salmon.author.public_key)
Rails.logger.info("data in salmon: #{salmon.parsed_data}")
self.receive(salmon.parsed_data)
self.receive(salmon.parsed_data, salmon.author)
end
end
def receive xml
def receive xml, salmon_author
object = Diaspora::Parser.from_xml(xml)
Rails.logger.debug("Receiving object for #{self.real_name}:\n#{object.inspect}")
Rails.logger.debug("From: #{object.person.inspect}") if object.person
if object.is_a? Retraction
receive_retraction object, xml
elsif object.is_a? Request
receive_request object, xml
elsif object.is_a? Profile
receive_profile object, xml
elsif object.is_a?(Comment)
receive_comment object, xml
sender_in_xml = sender(object, xml)
if (salmon_author == sender_in_xml)
if object.is_a? Retraction
receive_retraction object, xml
elsif object.is_a? Request
receive_request object, sender_in_xml
elsif object.is_a? Profile
receive_profile object, xml
elsif object.is_a?(Comment)
receive_comment object, xml
else
receive_post object, xml
end
else
receive_post object, xml
raise "Malicious Post, #{salmon_author.real_name} with id #{salmon_author.id} is sending a #{object.class} as #{sender_in_xml.real_name} with id #{sender_in_xml.id} "
end
end
def sender(object, xml)
if object.is_a? Retraction
sender = object.person
elsif object.is_a? Request
sender = object.person
elsif object.is_a? Profile
sender = Diaspora::Parser.owner_id_from_xml xml
elsif object.is_a?(Comment)
sender = (owns?(object.post))? object.person : object.post.person
else
sender = object.person
end
sender
end
def receive_retraction retraction, xml
if retraction.type == 'Person'
Rails.logger.info( "the person id is #{retraction.post_id} the friend found is #{visible_person_by_id(retraction.post_id).inspect}")
@ -40,8 +61,7 @@ module Diaspora
end
end
def receive_request request, xml
person = Diaspora::Parser.parse_or_find_person_from_xml( xml )
def receive_request request, person
person.serialized_public_key ||= request.exported_key
request.person = person
request.person.save
@ -59,12 +79,12 @@ module Diaspora
def receive_comment comment, xml
comment.person = Diaspora::Parser.parse_or_find_person_from_xml( xml ).save if comment.person.nil?
raise "In receive for #{self.real_name}, signature was not valid on: #{comment.inspect}" unless comment.post.person == self.person || comment.verify_post_creator_signature
self.visible_people = self.visible_people | [comment.person]
self.save
Rails.logger.debug("The person parsed from comment xml is #{comment.person.inspect}") unless comment.person.nil?
comment.person.save
Rails.logger.debug("From: #{comment.person.inspect}") if comment.person
raise "In receive for #{self.real_name}, signature was not valid on: #{comment.inspect}" unless comment.post.person == self.person || comment.verify_post_creator_signature
comment.save
unless owns?(comment)
dispatch_comment comment

View file

@ -113,7 +113,7 @@ HEADER
if @author
@author
else
Person.by_webfinger @author_email
@author ||= Person.by_webfinger @author_email
end
end

View file

@ -195,8 +195,8 @@ li.message {
li.message .content .from a {
font-weight: bold; }
li.message .content div.info {
color: #eeeeee;
font-size: 11px; }
color: #444444;
font-size: 13px; }
li.message .content div.info a {
color: #cccccc; }
li.message .content div.info .time {

View file

@ -266,8 +266,8 @@ li.message
:size 14px
div.info
:color #eee
:font-size 11px
:color #444
:font-size 13px
a
:color #ccc
.time

View file

@ -55,7 +55,7 @@ describe Diaspora::Parser do
xml = retraction.to_diaspora_xml
StatusMessage.count.should == 1
@user.receive xml
@user.receive xml, person
StatusMessage.count.should == 0
end
@ -69,7 +69,7 @@ describe Diaspora::Parser do
@user3.destroy
@person.destroy
Person.all.count.should == person_count -1
@user.receive xml
@user.receive xml, @person
Person.all.count.should == person_count
Person.first(:_id => original_person_id).serialized_public_key.include?("PUBLIC").should be true
@ -85,7 +85,7 @@ describe Diaspora::Parser do
xml = request.to_diaspora_xml
Person.all.count.should be person_count
@user.receive xml
@user.receive xml, @user2.person
Person.all.count.should be person_count
@user2.reload
@ -106,7 +106,7 @@ describe Diaspora::Parser do
@user2.person.destroy
@user2.destroy
@user.receive xml
@user.receive xml, @user2.person
new_person = Person.first(:url => @user2.person.url)
new_person.nil?.should be false
@ -128,14 +128,16 @@ describe Diaspora::Parser do
@user2.person.destroy
@user2.destroy
@user.receive xml
@user.receive xml, @user2.person
@aspect.reload
aspect_people_count = @aspect.people.size
#They are now friends
Person.count.should == person_count
@user.receive retraction_xml
@user.receive retraction_xml, @user2.person
@aspect.reload
@aspect.people.size.should == aspect_people_count -1
@ -163,7 +165,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob'
#Marshal profile
@user.receive xml
@user.receive xml, person
#Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id)

View file

@ -86,7 +86,7 @@ describe Aspect do
message = @user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
aspect.reload
aspect.posts.include?(message).should be true
@ -100,13 +100,14 @@ describe Aspect do
message = @user2.post(:status_message, :message => "Hey Dude", :to => aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
aspect.reload
aspect.post_ids.include?(message.id).should be true
retraction = @user2.retract(message)
@user.receive retraction.to_diaspora_xml
@user.receive retraction.to_diaspora_xml, @user2.person
aspect.reload
aspect.post_ids.include?(message.id).should be false
@ -151,7 +152,7 @@ describe Aspect do
it 'should move all the by that user to the new aspect' do
message = @user2.post(:status_message, :message => "Hey Dude", :to => @aspect2.id)
@user.receive message.to_diaspora_xml
@user.receive message.to_diaspora_xml, @user2.person
@aspect.reload
@aspect.posts.count.should == 1

View file

@ -53,6 +53,30 @@ describe Comment do
@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
@ -73,33 +97,33 @@ describe Comment 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)
User::QUEUE.should_receive(:add_post_request).twice
@user.receive(comment.to_diaspora_xml)
@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)
@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)
@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)
@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)
@user.receive comment.to_diaspora_xml, @person
@aspect.reload
@aspect.post_ids.include?(@user_status.id).should be true

View file

@ -43,6 +43,7 @@ describe Person do
it 'should have a profile in its xml' do
@xml.include?("first_name").should == true
end
end
@ -54,7 +55,7 @@ describe Person do
person_two.owns?(person_message).should be false
end
it 'should delete all of user except comments upon user deletion' do
it 'should delete all of user posts except comments upon user deletion' do
person = Factory.create(:person)
Factory.create(:status_message, :person => person)

View file

@ -115,7 +115,7 @@ describe Photo do
id = @photo.id
@photo.destroy
@user.receive xml
@user.receive xml, @photo.person
new_photo = Photo.first(:id => id)
new_photo.url.nil?.should be false

View file

@ -28,38 +28,35 @@ describe User do
user.raw_visible_posts.count.should be 1
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :person => user3.person)
user.receive_salmon(user3.salmon(malicious_message).xml_for(user.person))
proc{user.receive_salmon(user3.salmon(malicious_message).xml_for(user.person))}.should raise_error /Malicious Post/
user.raw_visible_posts.count.should be 1
user.raw_visible_posts.first.message.should == "store this!"
end
it 'ovewrites messages which apear to ' do
it 'ovewrites messages which apear to be from the same user' do
original_message = user2.post :status_message, :message => 'store this!', :to => aspect2.id
user.receive_salmon(user2.salmon(original_message).xml_for(user.person))
user.raw_visible_posts.count.should be 1
malicious_message = Factory.build( :status_message, :id => original_message.id, :message => 'BAD!!!', :person => user2.person)
user.receive_salmon(user3.salmon(malicious_message).xml_for(user.person))
proc{user.receive_salmon(user3.salmon(malicious_message).xml_for(user.person))}.should raise_error /Malicious Post/
user.raw_visible_posts.count.should be 1
user.raw_visible_posts.first.message.should == "store this!"
end
it 'overites another persons profile' do
pending "don't allow profile overwriting"
profile = user2.profile.clone
profile.first_name = "Not BOB"
user2.reload
user2.profile.first_name.should == "Robert"
user.receive_salmon(user3.salmon(profile).xml_for(user.person))
proc{user.receive_salmon(user3.salmon(profile).xml_for(user.person))}.should raise_error /Malicious Post/
user2.reload
user2.profile.first_name.should == "Robert"
end
it 'overwrites requests' do
pending
end
end
end

View file

@ -28,7 +28,7 @@ describe User do
user2.destroy
status_message.destroy
StatusMessage.all.size.should == 0
user.receive( xml )
user.receive xml , user2.person
Post.all(:person_id => person.id).first.message.should == 'store this!'
StatusMessage.all.size.should == 1
@ -40,7 +40,7 @@ describe User do
(0..5).each{ |n|
status_message = user2.post :status_message, :message => "store this #{n}!", :to => aspect2.id
xml = status_message.to_diaspora_xml
user.receive( xml )
user.receive xml, user2.person
}
user.aspects.size.should == num_aspects
@ -60,7 +60,7 @@ describe User do
it 'should be removed on unfriending' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
@ -75,7 +75,7 @@ describe User do
it 'should be remove a post if the noone links to it' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
@ -92,7 +92,7 @@ describe User do
it 'should keep track of user references for one person ' do
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user.reload
user.raw_visible_posts.count.should == 1
@ -116,9 +116,9 @@ describe User do
user3.activate_friend(user2.person, aspect3)
status_message = user2.post :status_message, :message => "hi", :to => aspect2.id
user.receive status_message.to_diaspora_xml
user.receive status_message.to_diaspora_xml, user2.person
user3.receive status_message.to_diaspora_xml
user3.receive status_message.to_diaspora_xml, user2.person
user.reload
user3.reload
@ -145,11 +145,11 @@ describe User do
post = user.post :status_message, :message => "hello", :to => aspect.id
user2.receive post.to_diaspora_xml
user3.receive post.to_diaspora_xml
user2.receive post.to_diaspora_xml, user.person
user3.receive post.to_diaspora_xml, user.person
comment = user2.comment('tada',:on => post)
user.receive comment.to_diaspora_xml
user.receive comment.to_diaspora_xml, user2.person
user.reload
commenter_id = user2.person.id
@ -159,7 +159,7 @@ describe User do
comment_id = comment.id
comment.delete
user3.receive comment.to_diaspora_xml
user3.receive comment.to_diaspora_xml, user.person
user3.reload
new_comment = Comment.find_by_id(comment_id)

View file

@ -5,74 +5,69 @@
require 'spec_helper'
describe User do
before do
@user = Factory.create(:user)
@aspect = @user.aspect(:name => 'heroes')
end
let(:user) {Factory.create :user}
let(:aspect) {user.aspect(:name => 'heroes')}
let(:friend) { Factory.create(:person) }
describe 'friend requesting' do
let(:person_one) {Factory.create :person}
let(:person_two) {Factory.create :person}
let(:user2) { Factory.create :user}
let(:aspect2) { user2.aspect(:name => "aspect two")}
context 'friend requesting' do
it "should assign a request to a aspect" do
friend = Factory.create(:person)
aspect = @user.aspect(:name => "Dudes")
aspect.requests.size.should == 0
@user.send_friend_request_to(friend, aspect)
user.send_friend_request_to(friend, aspect)
aspect.reload
aspect.requests.size.should == 1
end
it "should be able to accept a pending friend request" do
friend = Factory.create(:person)
r = Request.instantiate(:to => @user.receive_url, :from => friend)
r = Request.instantiate(:to => user.receive_url, :from => friend)
r.save
Person.all.count.should == 2
Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id, @aspect.id)
Request.for_user(@user).all.count.should == 0
Request.for_user(user).all.count.should == 1
user.accept_friend_request(r.id, aspect.id)
Request.for_user(user).all.count.should == 0
end
it 'should be able to ignore a pending friend request' do
friend = Factory.create(:person)
r = Request.instantiate(:to => @user.receive_url, :from => friend)
r = Request.instantiate(:to => user.receive_url, :from => friend)
r.save
Person.count.should == 2
@user.ignore_friend_request(r.id)
user.ignore_friend_request(r.id)
Person.count.should == 2
Request.count.should == 0
end
it 'should not be able to friend request an existing friend' do
friend = Factory.create(:person)
user.friends << friend
user.save
@user.friends << friend
@user.save
proc { @user.send_friend_request_to(friend, @aspect) }.should raise_error
proc { user.send_friend_request_to(friend, aspect) }.should raise_error
end
describe 'multiple users accepting/rejecting the same person' do
before do
@person_one = Factory.create :person
@person_one.save
user.pending_requests.empty?.should be true
user.friends.empty?.should be true
user2.pending_requests.empty?.should be true
user2.friends.empty?.should be true
@user2 = Factory.create :user
@aspect2 = @user2.aspect(:name => "aspect two")
@request = Request.instantiate(:to => user.receive_url, :from => person_one)
@request_two = Request.instantiate(:to => user2.receive_url, :from => person_one)
@request_three = Request.instantiate(:to => user2.receive_url, :from => user.person)
@user.pending_requests.empty?.should be true
@user.friends.empty?.should be true
@user2.pending_requests.empty?.should be true
@user2.friends.empty?.should be true
@request = Request.instantiate(:to => @user.receive_url, :from => @person_one)
@request_two = Request.instantiate(:to => @user2.receive_url, :from => @person_one)
@request_three = Request.instantiate(:to => @user2.receive_url, :from => @user.person)
@req_xml = @request.to_diaspora_xml
@req_two_xml = @request_two.to_diaspora_xml
@req_xml = @request.to_diaspora_xml
@req_two_xml = @request_two.to_diaspora_xml
@req_three_xml = @request_three.to_diaspora_xml
@request.destroy
@ -81,129 +76,126 @@ describe User do
end
it 'should befriend the user other user on the same pod' do
@user2.receive @req_three_xml
@user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_three.id, @aspect2.id
@user2.friends.include?(@user.person).should be true
user2.receive @req_three_xml, user.person
user2.pending_requests.size.should be 1
user2.accept_friend_request @request_three.id, aspect2.id
user2.friends.include?(user.person).should be true
Person.all.count.should be 3
end
it 'should not delete the ignored user on the same pod' do
@user2.receive @req_three_xml
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_three.id
@user2.friends.include?(@user.person).should be false
user2.receive @req_three_xml, user.person
user2.pending_requests.size.should be 1
user2.ignore_friend_request @request_three.id
user2.friends.include?(user.person).should be false
Person.all.count.should be 3
end
it 'should both users should befriend the same person' do
@user.receive @req_xml
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id, @aspect.id
@user.friends.include?(@person_one).should be true
user.receive @req_xml, person_one
user.pending_requests.size.should be 1
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
@user2.receive @req_two_xml
@user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_two.id, @aspect2.id
@user2.friends.include?(@person_one).should be true
user2.receive @req_two_xml, person_one
user2.pending_requests.size.should be 1
user2.accept_friend_request @request_two.id, aspect2.id
user2.friends.include?(person_one).should be true
Person.all.count.should be 3
end
it 'should keep the person around if one of the users rejects him' do
@user.receive @req_xml
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id, @aspect.id
@user.friends.include?(@person_one).should be true
user.receive @req_xml, person_one
user.pending_requests.size.should be 1
user.accept_friend_request @request.id, aspect.id
user.friends.include?(person_one).should be true
@user2.receive @req_two_xml
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_two.id
@user2.friends.include?(@person_one).should be false
user2.receive @req_two_xml, person_one
user2.pending_requests.size.should be 1
user2.ignore_friend_request @request_two.id
user2.friends.include?(person_one).should be false
Person.all.count.should be 3
end
it 'should keep the person around if the users ignores them' do
@user.receive @req_xml
@user.pending_requests.size.should be 1
@user.ignore_friend_request @user.pending_requests.first.id
@user.friends.include?(@person_one).should be false
user.receive @req_xml, person_one
user.pending_requests.size.should be 1
user.ignore_friend_request user.pending_requests.first.id
user.friends.include?(person_one).should be false
@user2.receive @req_two_xml
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @user2.pending_requests.first.id #@request_two.id
@user2.friends.include?(@person_one).should be false
user2.receive @req_two_xml, person_one
user2.pending_requests.size.should be 1
user2.ignore_friend_request user2.pending_requests.first.id #@request_two.id
user2.friends.include?(person_one).should be false
Person.all.count.should be 3
end
end
describe 'a user accepting rejecting multiple people' do
before do
@person_one = Factory.create :person
@person_two = Factory.create :person
user.pending_requests.empty?.should be true
user.friends.empty?.should be true
@user.pending_requests.empty?.should be true
@user.friends.empty?.should be true
@request = Request.instantiate(:to => @user.receive_url, :from => @person_one)
@request_two = Request.instantiate(:to => @user.receive_url, :from => @person_two)
@request = Request.instantiate(:to => user.receive_url, :from => person_one)
@request_two = Request.instantiate(:to => user.receive_url, :from => person_two)
end
it "keeps the right counts of friends" do
@user.receive_friend_request @request
user.receive_friend_request @request
@person_two.destroy
@user.pending_requests.size.should be 1
@user.friends.size.should be 0
person_two.destroy
user.pending_requests.size.should be 1
user.friends.size.should be 0
@user.receive_friend_request @request_two
@user.pending_requests.size.should be 2
@user.friends.size.should be 0
user.receive_friend_request @request_two
user.pending_requests.size.should be 2
user.friends.size.should be 0
@user.accept_friend_request @request.id, @aspect.id
@user.pending_requests.size.should be 1
@user.friends.size.should be 1
@user.friends.include?(@person_one).should be true
user.accept_friend_request @request.id, aspect.id
user.pending_requests.size.should be 1
user.friends.size.should be 1
user.friends.include?(person_one).should be true
@user.ignore_friend_request @request_two.id
@user.pending_requests.size.should be 0
@user.friends.size.should be 1
@user.friends.include?(@person_two).should be false
user.ignore_friend_request @request_two.id
user.pending_requests.size.should be 0
user.friends.size.should be 1
user.friends.include?(person_two).should be false
end
end
describe 'unfriending' do
before do
@user2 = Factory.create :user
@aspect2 = @user2.aspect(:name => "Gross people")
friend_users(@user, @aspect, @user2, @aspect2)
friend_users(user,aspect, user2, aspect2)
user.reload
user2.reload
end
it 'should unfriend the other user on the same seed' do
@user.friends(true).count.should == 1
@user2.friends(true).count.should == 1
user.friends.count.should == 1
user2.friends.count.should == 1
@user2.unfriend @user.person
user2.unfriend user.person
user2.reload
@user2.friends(true).count.should == 0
@user.unfriended_by @user2.person
user2.friends.count.should == 0
user.unfriended_by user2.person
@aspect.reload.people(true).count.should == 0
@aspect2.reload.people(true).count.should == 0
aspect.reload.people.count.should == 0
aspect2.reload.people.count.should == 0
end
context 'with a post' do
before do
@message = @user.post(:status_message, :message => "hi", :to => @aspect.id)
@user2.receive @message.to_diaspora_xml.to_s
@user2.unfriend @user.person
@user.unfriended_by @user2.person
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
user2.receive @message.to_diaspora_xml.to_s, user.person
user2.unfriend user.person
user.unfriended_by user2.person
end
it "deletes the unfriended user's posts from visible_posts" do
@user.raw_visible_posts(true).include?(@message.id).should be_false
user.reload.raw_visible_posts.include?(@message.id).should be_false
end
it "deletes the unfriended user's posts from the aspect's posts" do
@aspect2.posts(true).include?(@message).should be_false
aspect2.posts.include?(@message).should be_false
end
end
end

View file

@ -10,11 +10,15 @@ describe User do
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
@ -44,20 +48,15 @@ describe User do
end
it "queries by aspect" do
user3 = Factory(:user_with_aspect)
status_message2 = user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id
user4 = Factory(:user_with_aspect)
status_message3 = user4.post :status_message, :message => "yooo", :to => user4.aspects.first.id
friend_users(user, second_aspect, user3, user3.aspects.first)
friend_users(user, second_aspect, user4, user4.aspects.first)
user.receive status_message1.to_diaspora_xml
user.receive status_message2.to_diaspora_xml
user.receive status_message3.to_diaspora_xml
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
user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1]
user.visible_posts(:by_members_of => second_aspect).should =~ [status_message2, status_message3]
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

View file

@ -82,7 +82,7 @@ ImageUploader.enable_processing = false
request = user1.send_friend_request_to(user2.person, aspect1)
reversed_request = user2.accept_friend_request( request.id, aspect2.id)
user1.reload
user1.receive reversed_request.to_diaspora_xml
user1.receive reversed_request.to_diaspora_xml, user2.person
user1.reload
aspect1.reload
user2.reload

View file

@ -43,11 +43,12 @@ describe 'user encryption' do
xml = request.to_diaspora_xml
remote_user.person.destroy
remote_user.destroy
remote_user.person.delete
remote_user.delete
person_count = Person.all.count
proc {@user.receive xml}.should_not raise_error /ignature was not valid/
@user.receive xml, remote_user.person
Person.all.count.should == person_count + 1
new_person = Person.first(:id => id)
new_person.exported_key.should == original_key