138 lines
4.4 KiB
Ruby
138 lines
4.4 KiB
Ruby
require File.dirname(__FILE__) + '/../spec_helper'
|
|
|
|
include ApplicationHelper
|
|
|
|
describe "parser in application helper" do
|
|
before do
|
|
@user = Factory.create(:user, :email => "bob@aol.com")
|
|
@person = Factory.create(:person, :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)
|
|
StatusMessage.count.should == 0
|
|
end
|
|
|
|
it "should reject xml with no sender" do
|
|
xml = "<XML>
|
|
<head>
|
|
</head><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><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)
|
|
Post.count.should == 0
|
|
|
|
end
|
|
|
|
it "should reject xml with a sender not in the database" do
|
|
xml = "<XML>
|
|
<head>
|
|
<sender>
|
|
<email>foo@example.com</email>
|
|
</sender>
|
|
</head><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><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)
|
|
Post.count.should == 0
|
|
end
|
|
|
|
it 'should discard types which are not of type post' do
|
|
xml = "<XML>
|
|
<head>
|
|
<sender>
|
|
<email>#{Person.first.email}</email>
|
|
</sender>
|
|
</head>
|
|
<posts>
|
|
<post><person></person></post>
|
|
</posts></XML>"
|
|
|
|
store_objects_from_xml(xml)
|
|
Post.count.should == 0
|
|
end
|
|
|
|
|
|
describe "parsing compliant XML object" do
|
|
before do
|
|
@status_messages = []
|
|
10.times { @status_messages << Factory.build(:status_message)}
|
|
@xml = Post.build_xml_for(@status_messages)
|
|
end
|
|
|
|
it 'should be able to parse the body\'s contents' do
|
|
body = parse_body_contents_from_xml(@xml).to_s
|
|
body.should_not include "<head>"
|
|
body.should_not include "</head>"
|
|
body.should_not include "<posts>"
|
|
body.should_not include "</posts>"
|
|
body.should include "<post>"
|
|
body.should include "</post>"
|
|
end
|
|
|
|
it 'should be able to extract all posts to an array' do
|
|
posts = parse_objects_from_xml(@xml)
|
|
posts.is_a?(Array).should be true
|
|
posts.count.should == 10
|
|
end
|
|
|
|
it 'should be able to correctly handle comments' do
|
|
person = Factory.create(:person, :email => "test@testing.com")
|
|
post = Factory.create(:status_message)
|
|
comment = Factory.build(:comment, :post => post, :person => person, :text => "Freedom!")
|
|
xml = "<XML>
|
|
<posts>
|
|
<post>#{comment.to_xml}</post>
|
|
</posts></XML>"
|
|
|
|
objects = parse_objects_from_xml(xml)
|
|
comment = objects.first
|
|
comment.text.should == "Freedom!"
|
|
comment.person.should == person
|
|
comment.post.should == post
|
|
end
|
|
|
|
it 'should marshal retractions' do
|
|
person = Factory.create(:person)
|
|
message = Factory.create(:status_message, :person => person)
|
|
retraction = Retraction.for(message)
|
|
request = Post.build_xml_for( [retraction] )
|
|
|
|
StatusMessage.count.should == 1
|
|
store_objects_from_xml( request )
|
|
StatusMessage.count.should == 0
|
|
end
|
|
|
|
it "should create a new person upon getting a person request" do
|
|
request = PersonRequest.new(:url => "http://www.googles.com/")
|
|
request.person = @person
|
|
|
|
xml = Post.build_xml_for [request]
|
|
|
|
@person.destroy
|
|
@user.destroy
|
|
Person.count.should be 0
|
|
store_objects_from_xml(xml)
|
|
Person.count.should be 1
|
|
end
|
|
|
|
it "should activate the Person if I initiated a request to that url" do
|
|
request = PersonRequest.create(:url => @person.url, :person => @user)
|
|
request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
|
|
request_remote.person = @person.clone
|
|
|
|
xml = Post.build_xml_for [request_remote]
|
|
|
|
Person.where(:url => @person.url).first.active.should be true
|
|
end
|
|
|
|
end
|
|
end
|
|
|