require File.dirname(__FILE__) + '/../spec_helper' include ApplicationHelper include Diaspora::OStatusParser 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 = " \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " store_objects_from_xml(xml) Post.count.should == 0 end it "should reject xml with a sender not in the database" do xml = " foo@example.com \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " store_objects_from_xml(xml) Post.count.should == 0 end it 'should discard types which are not of type post' do xml = " #{Person.first.email} " store_objects_from_xml(xml) Post.count.should == 0 end describe 'ostatus parsing' do it 'should be able to get the hub of an ostatus feed' do xml_path = File.dirname(__FILE__) + '/../fixtures/identica_feed.atom' xml = File.open(xml_path).read Diaspora::OStatusParser::find_hub(xml).should == 'http://identi.ca/main/push/hub' end describe 'subscriber info' do before do #load file xml_path = File.dirname(__FILE__) + '/../fixtures/ostatus_update.xml' @xml = File.open(xml_path).read @xml = Nokogiri::HTML(@xml) end it 'should parse the users service' do Diaspora::OStatusParser::parse_service(@xml).should == 'StatusNet' end it 'should parse the feed_url' do Diaspora::OStatusParser::parse_feed_url(@xml).should == 'http://identi.ca/api/statuses/user_timeline/217769.atom' end it 'should parse the avatar thumbnail' do Diaspora::OStatusParser::parse_avatar_thumbnail(@xml).should == 'http://theme.status.net/0.9.3/identica/default-avatar-profile.png' end it 'should parse the username' do Diaspora::OStatusParser::parse_username(@xml).should == 'danielgrippi' end it 'should parse the profile_url' do Diaspora::OStatusParser::parse_profile_url(@xml).should == 'http://identi.ca/user/217769' end end describe 'entry' do before do #load file xml_path = File.dirname(__FILE__) + '/../fixtures/ostatus_update.xml' @xml = File.open(xml_path).read @xml = Nokogiri::HTML(@xml) end it 'should parse the message' do Diaspora::OStatusParser::parse_message(@xml).should == 'SOAP!' end it 'should parse the permalink' do Diaspora::OStatusParser::parse_permalink(@xml).should == 'http://identi.ca/notice/43074747' end it 'should parse published at date' do Diaspora::OStatusParser::parse_published_at(@xml).should == '2010-07-22T22:15:31+00:00' end it 'should parse the updated at date' do Diaspora::OStatusParser::parse_updated_at(@xml).should == '2010-07-22T22:15:31+00:00' end end 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 "" body.should_not include "" body.should_not include "" body.should_not include "" body.should include "" body.should include "" 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 = " #{comment.to_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 = Request.instantiate(:to =>"http://www.google.com/", :from => @person) original_person_id = @person.id xml = Request.build_xml_for [request] @person.destroy Person.all.count.should be 1 store_objects_from_xml(xml) Person.all.count.should be 2 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 request_remote = Request.new request_remote.destination_url = @user.url request_remote.callback_url = @user.url request_remote.person = @person request_remote.exported_key = @person.export_key xml = Request.build_xml_for [request_remote] @person.destroy request_remote.destroy store_objects_from_xml(xml) Person.first(:url => @person.url).active.should be true end it 'should marshal a retraction for a person' do retraction = Retraction.for(@user) request = Retraction.build_xml_for( [retraction] ) Person.count.should == 2 store_objects_from_xml( request ) Person.count.should == 1 end end end