Newer
Older
require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
describe Diaspora::Parser do
ilya
a validé
@user = Factory.create(:user, :email => "bob@aol.com")
@person = Factory.create(:person_with_private_key, :email => "bill@gates.com")
ilya
a validé
it "should not store posts from me" do
10.times {
message = Factory.build(:status_message, :person => @user)
store_from_xml(xml, @user)
ilya
a validé
StatusMessage.count.should == 0
ilya
a validé
it "should reject xml with no sender" do
xml = "<XML>
<head>
ilya
a validé
<post><status_message>\n <message>Here is another message</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
danielvincent
a validé
<post><person></person></post>
ilya
a validé
<post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
store_from_xml(xml, @user)
ilya
a validé
Post.count.should == 0
maxwell
a validé
ilya
a validé
end
maxwell
a validé
it 'should discard types which are not of type post' do
Maxwell Salzberg
a validé
xml = "<XML>
danielvincent
a validé
<post><person></person></post>
store_from_xml(xml, @user)
maxwell
a validé
end
Maxwell Salzberg
a validé
describe "parsing compliant XML object" do
before do
@xml = Factory.build(:status_message).to_diaspora_xml
Maxwell Salzberg
a validé
end
it 'should be able to parse the body\'s contents' do
body = parse_body_contents_from_xml(@xml).to_s
body.should include "<post>"
body.should include "</post>"
it 'should be able to correctly handle comments' do
danielvincent
a validé
person = Factory.create(:person, :email => "test@testing.com")
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 = parse_from_xml(xml)
danielvincent
a validé
comment.person.should == person
it 'should marshal retractions' do
danielvincent
a validé
person = Factory.create(:person)
message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message)
store_from_xml( request, @user )
StatusMessage.count.should == 0
end
ilya
a validé
danielvincent
a validé
it "should create a new person upon getting a person request" do
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
danielvincent
a validé
@person.destroy
store_from_xml(xml, @user)
Person.first(:_id => original_person_id).serialized_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
@user2 = Factory.create(:user)
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person)
original_person_id = @user2.person.id
Person.all.count.should be 3
store_from_xml(xml, @user)
Person.all.count.should be 3
@user2.reload
@user2.person.serialized_key.include?("PRIVATE").should be true
url = "http://" + request.callback_url.split("/")[2] + "/"
Person.where(:url => url).first.id.should == original_person_id
danielvincent
a validé
it "should activate the Person if I initiated a request to that url" do
request = Request.instantiate(:to => @person.receive_url, :from => @user)
request.save
@user.pending_requests << request
@user.save
request_remote.id = request.id
request_remote.destination_url = @user.receive_url
request_remote.callback_url = @user.receive_url
xml = request_remote.to_diaspora_xml
danielvincent
a validé
@person.destroy
request_remote.destroy
store_from_xml(xml, @user)
new_person = Person.first(:url => @person.url)
new_person.nil?.should be false
@user.reload
@user.friends.include?(new_person).should be true
it 'should process retraction for a person' do
request = retraction.to_diaspora_xml
store_from_xml( request , @user)
it 'should marshal a profile for a person' do
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
store_from_xml xml, @user
#Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id)
person.profile.should_not be nil
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