Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
describe Diaspora::Parser do
@user3 = Factory.create :user
@person = @user3.person
ilya
a validé
@user2 = Factory.create(:user)
maxwell
a validé
@aspect2 = @user2.aspect(:name => "pandas")
friend_users(@user, @aspect, @user2, @aspect2)
Maxwell Salzberg
a validé
before do
@xml = Factory.build(:status_message).to_diaspora_xml
Maxwell Salzberg
a validé
end
it 'should be able to correctly handle comments with person in db' do
post = Factory.create(:status_message, :person => @user.person)
danielvincent
a validé
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
danielvincent
a validé
comment = Diaspora::Parser.from_xml(xml)
danielvincent
a validé
comment.person.should == person
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
commenter.delete
commenter.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.profile.should_not be_nil
end
it 'should marshal retractions' do
maxwell
a validé
person = @user2.person
danielvincent
a validé
message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message)
proc {@user.receive xml, person}.should change(StatusMessage, :count).by(-1)
danielvincent
a validé
it "should create a new person upon getting a person request" do
ilya
a validé
person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
@user3.destroy
danielvincent
a validé
@person.destroy
ilya
a validé
Person.all.count.should == person_count -1
ilya
a validé
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
ilya
a validé
end
it "should not create a new person if the person is already here" do
ilya
a validé
person_count = Person.all.count
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person)
original_person_id = @user2.person.id
ilya
a validé
Person.all.count.should be person_count
ilya
a validé
Person.all.count.should be person_count
@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
it "should activate the Person if I initiated a request to that url" do
maxwell
a validé
request = @user.send_friend_request_to( @user3.person, @aspect)
maxwell
a validé
request.reverse_for @user3
maxwell
a validé
@user3.person.destroy
@user3.destroy
maxwell
a validé
@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
it 'should process retraction for a person' do
maxwell
a validé
user4 = Factory(:user)
ilya
a validé
person_count = Person.all.count
maxwell
a validé
request = @user.send_friend_request_to( user4.person, @aspect)
maxwell
a validé
request.reverse_for user4
maxwell
a validé
retraction = Retraction.for(user4)
retraction_xml = retraction.to_diaspora_xml
maxwell
a validé
user4.person.destroy
user4.destroy
@user.receive xml, user4.person
@aspect.reload
aspect_people_count = @aspect.people.size
#They are now friends
ilya
a validé
Person.count.should == person_count
maxwell
a validé
@user.receive retraction_xml, user4.person
@aspect.reload
@aspect.people.size.should == aspect_people_count -1
it 'should marshal a profile for a person' do
maxwell
a validé
person = @user2.person
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
person.save
#Cache profile for checking against marshaled profile
old_profile.first_name.should == 'bob'
#Build xml for profile, clear profile
xml = person.profile.to_diaspora_xml
reloaded_person.profile = nil
reloaded_person.save(:validate => false)
#Make sure profile is cleared
old_profile.first_name.should == 'bob'
#Marshal profile
#Check that marshaled profile is the same as old profile
person.profile.first_name.should == old_profile.first_name
person.profile.last_name.should == old_profile.last_name
person.profile.image_url.should == old_profile.image_url