Skip to content
Extraits de code Groupes Projets
Valider 5286b6be rédigé par maxwell's avatar maxwell
Parcourir les fichiers

DG MS; require XML root node; added header to XML (not yet required)

parent 34df8fa9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -12,7 +12,7 @@ module ApplicationHelper
#i need to check some sort of metadata field
doc.xpath("//post").each do |post| #this is the post wrapper
doc.xpath("/XML/posts/post").each do |post| #this is the post wrapper
post.children.each do|type| #now the text of post itself is the type
#type object to xml is the the thing we want to from_xml
check_and_save_post(type)
......
......@@ -19,14 +19,28 @@ module Diaspora
end
def friends_with_permissions
Friend.only(:url).map{|x| x = x.url + "/receive/"}
Friend.only(:url).map{|x| x = x.url + "receive/"}
end
def self.build_xml_for(posts)
xml = "<posts>"
xml = "<XML>"
xml += Post.generate_header
xml += "<posts>"
posts.each {|x| xml << x.prep_webhook}
xml = xml + "</posts>"
xml += "</posts>"
xml += "</XML>"
end
def self.generate_header
"<head>
<sender>
<email>#{User.first.email}</email>
<url>#{User.first.email}</url>
</sender>
</head>"
end
end
end
end
......
......@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
describe DashboardHelper do
describe ApplicationHelper do
before do
Factory.create(:user)
end
......@@ -18,23 +18,24 @@ describe DashboardHelper do
end
it 'should discard posts where it does not know the type' do
xml = "<posts>
xml = "<XML><posts>
<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>
<post><not_a_real_type></not_a_real_type></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>"
</posts></XML>"
store_posts_from_xml(xml)
Post.count.should == 2
end
it 'should discard types which are not of type post' do
xml = "<posts>
xml = "<XML><posts>
<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>
<post><friend></friend></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>"
</posts></XML>"
store_posts_from_xml(xml)
Post.count.should == 2
end
end
......@@ -7,56 +7,89 @@ describe Diaspora do
describe Webhooks do
before do
@user = Factory.create(:user)
@post = Factory.create(:post)
Factory.create(:user, :email => "bob@aol.com")
end
it "should add the following methods to Post on inclusion" do
@post.respond_to?(:notify_friends).should be true
@post.respond_to?(:prep_webhook).should be true
@post.respond_to?(:friends_with_permissions).should be true
end
describe "header" do
before do
Factory.create(:status_message)
Factory.create(:bookmark)
stream = Post.stream
@xml = Post.build_xml_for(stream)
end
it "should convert an object to a proper webhook" do
@post.prep_webhook.should == "<post>#{@post.to_xml.to_s}</post>"
end
it "should generate" do
@xml.should include "<head>"
@xml.should include "</head>"
end
it "should retrieve all valid friend endpoints" do
Factory.create(:friend, :url => "http://www.bob.com")
Factory.create(:friend, :url => "http://www.alice.com")
Factory.create(:friend, :url => "http://www.jane.com")
it "should provide a sender" do
@xml.should include "<sender>"
@xml.should include "</sender>"
end
@post.friends_with_permissions.should include("http://www.bob.com/receive/")
@post.friends_with_permissions.should include("http://www.alice.com/receive/")
@post.friends_with_permissions.should include("http://www.jane.com/receive/")
end
it "should provide the owner's email" do
@xml.should include "<email>bob@aol.com</email>"
end
it "should send an owners post to their friends" do
Post.stub(:build_xml_for).and_return(true)
Post.should_receive(:build_xml_for).and_return true
@post.save
end
it "should check that it does not send a friends post to an owners friends" do
Post.stub(:build_xml_for).and_return(true)
Post.should_not_receive(:build_xml_for)
Factory.create(:post, :owner => "nottheowner@post.com")
it "should provide the owner's url" do
pending "user does not have url field"
end
end
it "should ensure one url is created for every friend" do
5.times {Factory.create(:friend)}
@post.friends_with_permissions.size.should == 5
end
describe "body" do
before do
@post = Factory.create(:post)
end
it "should add the following methods to Post on inclusion" do
@post.respond_to?(:notify_friends).should be true
@post.respond_to?(:prep_webhook).should be true
@post.respond_to?(:friends_with_permissions).should be true
end
it "should build an xml object containing multiple Post types" do
Factory.create(:status_message)
Factory.create(:bookmark)
it "should convert an object to a proper webhook" do
@post.prep_webhook.should == "<post>#{@post.to_xml.to_s}</post>"
end
stream = Post.stream
xml = Post.build_xml_for(stream)
xml.should include "<status_message>"
xml.should include "<bookmark>"
it "should retrieve all valid friend endpoints" do
Factory.create(:friend, :url => "http://www.bob.com/")
Factory.create(:friend, :url => "http://www.alice.com/")
Factory.create(:friend, :url => "http://www.jane.com/")
@post.friends_with_permissions.should include("http://www.bob.com/receive/")
@post.friends_with_permissions.should include("http://www.alice.com/receive/")
@post.friends_with_permissions.should include("http://www.jane.com/receive/")
end
it "should send an owners post to their friends" do
Post.stub(:build_xml_for).and_return(true)
Post.should_receive(:build_xml_for).and_return true
@post.save
end
it "should check that it does not send a friends post to an owners friends" do
Post.stub(:build_xml_for).and_return(true)
Post.should_not_receive(:build_xml_for)
Factory.create(:post, :owner => "nottheowner@post.com")
end
it "should ensure one url is created for every friend" do
5.times {Factory.create(:friend)}
@post.friends_with_permissions.size.should == 5
end
it "should build an xml object containing multiple Post types" do
Factory.create(:status_message)
Factory.create(:bookmark)
stream = Post.stream
xml = Post.build_xml_for(stream)
xml.should include "<status_message>"
xml.should include "<bookmark>"
end
end
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter