MS IZ fixed a couple of failing specs in the parser
This commit is contained in:
parent
68c4de6c16
commit
38abd51666
5 changed files with 65 additions and 30 deletions
|
|
@ -18,7 +18,7 @@ class PublicsController < ApplicationController
|
|||
end
|
||||
|
||||
def receive
|
||||
user = User.first(:id => params[:id])
|
||||
user = Person.first(:id => params[:id]).owner
|
||||
Rails.logger.debug "PublicsController has received: #{params[:xml]}"
|
||||
store_objects_from_xml params[:xml], user
|
||||
render :nothing => true
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class Person
|
|||
|
||||
before_validation :clean_url
|
||||
|
||||
validates_presence_of :email, :url, :serialized_key, :profile
|
||||
validates_presence_of :email, :url, :profile, :serialized_key
|
||||
validates_format_of :url, :with =>
|
||||
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,13 @@ module Diaspora
|
|||
person = parse_owner_id_from_xml post
|
||||
person.profile = object
|
||||
person.save
|
||||
elsif object.is_a? Request
|
||||
person_string = Nokogiri::XML(xml) { |cfg| cfg.noblanks }.xpath("/XML/posts/post/request/person").to_s
|
||||
person = Person.from_xml person_string
|
||||
person.serialized_key ||= object.exported_key
|
||||
object.person = person
|
||||
object.person.save
|
||||
|
||||
elsif object.respond_to? :person
|
||||
object.person = parse_owner_from_xml post.to_s
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,37 +11,48 @@ describe PublicsController do
|
|||
|
||||
describe 'receive endpoint' do
|
||||
it 'should have a and endpoint and return a 200 on successful receipt of a request' do
|
||||
post :receive, :id =>@user.id
|
||||
post :receive, :id =>@user.person.id
|
||||
response.code.should == '200'
|
||||
end
|
||||
|
||||
it 'should accept a post from another node and save the information' do
|
||||
|
||||
pending
|
||||
person = Factory.create(:person)
|
||||
message = StatusMessage.new(:message => 'foo', :person => person)
|
||||
StatusMessage.all.count.should be 0
|
||||
post :receive, :id => @user.id, :xml => Post.build_xml_for(message)
|
||||
post :receive, :id => @user.person.id, :xml => Post.build_xml_for(message)
|
||||
StatusMessage.all.count.should be 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'friend requests' do
|
||||
before do
|
||||
@user2 = Factory.create(:user)
|
||||
@user2.person.save
|
||||
|
||||
it 'should save requests for the specified user (LOCAL)' do
|
||||
@user2 = Factory.create(:user)
|
||||
@user2.person.save
|
||||
req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
|
||||
@xml = Request.build_xml_for [req]
|
||||
|
||||
req.delete
|
||||
end
|
||||
|
||||
it 'should save requests for the specified user (LOCAL)' do
|
||||
post :receive, :id => @user.person.id, :xml => @xml
|
||||
|
||||
@user.reload
|
||||
@user.pending_requests.size.should be 1
|
||||
end
|
||||
|
||||
it 'should save requests for the specified user (REMOTE)' do
|
||||
@user2.person.delete
|
||||
@user2.delete
|
||||
post :receive, :id => @user.person.id, :xml => @xml
|
||||
|
||||
@user.reload
|
||||
@user.pending_requests.size.should be 1
|
||||
end
|
||||
|
||||
req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
|
||||
xml = Request.build_xml_for [req]
|
||||
|
||||
puts xml
|
||||
|
||||
|
||||
req.delete
|
||||
post :receive, :id =>@user.id, :xml => xml
|
||||
|
||||
@user2.pending_requests.count.should be 1
|
||||
@user.pending_requests.count.should be 1
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ include Diaspora::Parser
|
|||
describe Diaspora::Parser do
|
||||
before do
|
||||
@user = Factory.create(:user, :email => "bob@aol.com")
|
||||
@person = Factory.create(:person, :email => "bill@gates.com")
|
||||
@person = Factory.create(:person_with_private_key, :email => "bill@gates.com")
|
||||
end
|
||||
|
||||
it "should not store posts from me" do
|
||||
status_messages = []
|
||||
10.times { status_messages << Factory.build(:status_message, :person => @user)}
|
||||
xml = Post.build_xml_for(status_messages)
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
StatusMessage.count.should == 0
|
||||
end
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ describe Diaspora::Parser do
|
|||
<post><person></person></post>
|
||||
<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>
|
||||
</posts></XML>"
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
Post.count.should == 0
|
||||
|
||||
end
|
||||
|
|
@ -41,7 +41,7 @@ describe Diaspora::Parser do
|
|||
<post><person></person></post>
|
||||
<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>
|
||||
</posts></XML>"
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
Post.count.should == 0
|
||||
end
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ describe Diaspora::Parser do
|
|||
<post><person></person></post>
|
||||
</posts></XML>"
|
||||
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
Post.count.should == 0
|
||||
end
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ describe Diaspora::Parser do
|
|||
request = Post.build_xml_for( [retraction] )
|
||||
|
||||
StatusMessage.count.should == 1
|
||||
store_objects_from_xml( request )
|
||||
store_objects_from_xml( request, @user )
|
||||
StatusMessage.count.should == 0
|
||||
end
|
||||
|
||||
|
|
@ -116,15 +116,32 @@ describe Diaspora::Parser do
|
|||
|
||||
original_person_id = @person.id
|
||||
xml = Request.build_xml_for [request]
|
||||
|
||||
|
||||
@person.destroy
|
||||
Person.all.count.should be 1
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
Person.all.count.should be 2
|
||||
|
||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||
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
|
||||
xml = Request.build_xml_for [request]
|
||||
|
||||
|
||||
Person.all.count.should be 3
|
||||
store_objects_from_xml(xml, @user)
|
||||
Person.all.count.should be 3
|
||||
|
||||
@user2.reload
|
||||
@user2.person.serialized_key.include?("PRIVATE").should be true
|
||||
|
||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
request = Request.instantiate(:to => @person.url, :from => @user).save
|
||||
|
|
@ -139,7 +156,7 @@ describe Diaspora::Parser do
|
|||
|
||||
@person.destroy
|
||||
request_remote.destroy
|
||||
store_objects_from_xml(xml)
|
||||
store_objects_from_xml(xml, @user)
|
||||
new_person = Person.first(:url => @person.url)
|
||||
new_person.nil?.should be false
|
||||
@user.reload
|
||||
|
|
@ -152,7 +169,7 @@ describe Diaspora::Parser do
|
|||
request = Retraction.build_xml_for( [retraction] )
|
||||
|
||||
Person.count.should == 2
|
||||
store_objects_from_xml( request )
|
||||
store_objects_from_xml( request , @user)
|
||||
Person.count.should == 1
|
||||
end
|
||||
|
||||
|
|
@ -178,7 +195,7 @@ describe Diaspora::Parser do
|
|||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
store_objects_from_xml xml
|
||||
store_objects_from_xml xml, @user
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
person = Person.first(:id => person.id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue