Newer
Older
require File.dirname(__FILE__) + '/../spec_helper'
include ApplicationHelper
describe "parser in application helper" do
ilya
a validé
@user = Factory.create(:user, :email => "bob@aol.com")
Maxwell Salzberg
a validé
@friend =Factory.create(:friend, :email => "bill@gates.com")
ilya
a validé
it "should not store posts from me" do
ilya
a validé
10.times { status_messages << Factory.build(:status_message, :person => @user)}
ilya
a validé
StatusMessage.count.should == 0
ilya
a validé
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><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></XML>"
ilya
a validé
Post.count.should == 0
maxwell
a validé
ilya
a validé
end
ilya
a validé
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><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></XML>"
ilya
a validé
Post.count.should == 0
end
maxwell
a validé
it 'should discard types which are not of type post' do
Maxwell Salzberg
a validé
xml = "<XML>
<head>
<sender>
ilya
a validé
<email>#{Friend.first.email}</email>
Maxwell Salzberg
a validé
</sender>
maxwell
a validé
<post><friend></friend></post>
maxwell
a validé
end
Maxwell Salzberg
a validé
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)
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_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>"
Maxwell Salzberg
a validé
it 'should be able to extract all posts to an array' do
Maxwell Salzberg
a validé
posts.is_a?(Array).should be true
posts.count.should == 10
it 'should be able to correctly handle comments' do
friend = Factory.create(:friend)
post = Factory.create(:status_message)
comment = Factory.build(:comment, :post => post, :person => friend, :text => "Freedom!")
xml = "<XML><head><sender><email>#{Friend.first.email}</email></sender></head>
<posts>
</posts></XML>"
objects = parse_objects_from_xml(xml)
comment = objects.first
comment.text.should == "Freedom!"
comment.person.should == friend
comment.post.should == post
end
it 'should marshal retractions' do
friend = Factory.create(:friend)
message = Factory.create(:status_message, :person => friend)
retraction = Retraction.for(message)
request = Post.build_xml_for( [retraction] )
StatusMessage.count.should == 1
store_objects_from_xml( request )
StatusMessage.count.should == 0
end
ilya
a validé
it "should create a new friend upon getting a friend request" do
friend_request = FriendRequest.new(:url => "http://www.googles.com/")
friend_request.sender = @friend
xml = "<XML>
<posts><post>
#{friend_request.to_friend_xml.to_s}
</post></posts>
</XML>"
ilya
a validé
@friend.destroy
Friend.count.should be 0
store_objects_from_xml(xml)
Friend.count.should be 1
end