remove xml specs
This commit is contained in:
parent
d2219aa58f
commit
fa5a35ed4a
13 changed files with 0 additions and 595 deletions
|
|
@ -40,52 +40,4 @@ describe RelayableRetraction do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'xml' do
|
|
||||||
before do
|
|
||||||
@comment = @local_leia.comment!(@local_parent, "yo")
|
|
||||||
@retraction = described_class.build(@local_leia, @comment)
|
|
||||||
@retraction.parent_author_signature = 'PARENTSIGNATURE'
|
|
||||||
@retraction.target_author_signature = 'TARGETSIGNATURE'
|
|
||||||
@xml = @retraction.to_xml.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#to_xml' do
|
|
||||||
it 'serializes target_guid' do
|
|
||||||
expect(@xml).to include(@comment.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes target_type' do
|
|
||||||
expect(@xml).to include(@comment.class.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes sender_handle' do
|
|
||||||
expect(@xml).to include(@local_leia.diaspora_handle)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes signatures' do
|
|
||||||
expect(@xml).to include('TARGETSIGNATURE')
|
|
||||||
expect(@xml).to include('PARENTSIGNATURE')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '.from_xml' do
|
|
||||||
before do
|
|
||||||
@marshalled = described_class.from_xml(@xml)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the target' do
|
|
||||||
expect(@marshalled.target).to eq(@comment)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the sender' do
|
|
||||||
expect(@marshalled.sender).to eq(@local_leia.person)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the signature' do
|
|
||||||
expect(@marshalled.target_author_signature).to eq('TARGETSIGNATURE')
|
|
||||||
expect(@marshalled.parent_author_signature).to eq('PARENTSIGNATURE')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
|
||||||
# the COPYRIGHT file.
|
|
||||||
|
|
||||||
require "spec_helper"
|
|
||||||
|
|
||||||
describe Diaspora::Parser do
|
|
||||||
describe "parsing compliant XML object" do
|
|
||||||
it "should be able to correctly parse comment fields" do
|
|
||||||
user = FactoryGirl.create(:user)
|
|
||||||
|
|
||||||
post = alice.post :status_message, text: "hello", to: alice.aspects.first.id
|
|
||||||
comment = FactoryGirl.build(
|
|
||||||
:comment_entity,
|
|
||||||
parent_guid: post.guid,
|
|
||||||
author: user.diaspora_handle,
|
|
||||||
text: "Freedom!"
|
|
||||||
)
|
|
||||||
xml = Diaspora::Federation.xml(comment).to_xml
|
|
||||||
comment_from_xml = Diaspora::Parser.from_xml(xml)
|
|
||||||
expect(comment_from_xml.diaspora_handle).to eq(user.diaspora_handle)
|
|
||||||
expect(comment_from_xml.post).to eq(post)
|
|
||||||
expect(comment_from_xml.text).to eq("Freedom!")
|
|
||||||
expect(comment_from_xml).not_to be comment
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -62,16 +62,4 @@ describe AccountDeletion, :type => :model do
|
||||||
expect(account_deletion_new.subscribers).to eq([remote_raphael])
|
expect(account_deletion_new.subscribers).to eq([remote_raphael])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "serialization" do
|
|
||||||
let(:xml) { account_deletion_new.to_xml.to_s }
|
|
||||||
|
|
||||||
it "should have a diaspora_handle" do
|
|
||||||
expect(xml.include?(alice.person.diaspora_handle)).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the xml" do
|
|
||||||
expect(AccountDeletion.from_xml(xml)).to be_valid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -67,46 +67,6 @@ describe Comment, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "xml" do
|
|
||||||
let(:commenter) { create(:user) }
|
|
||||||
let(:commenter_aspect) { commenter.aspects.create(name: "bruisers") }
|
|
||||||
let(:post) { alice.post :status_message, text: "hello", to: alices_aspect.id }
|
|
||||||
let(:comment) { commenter.comment!(post, "Fool!") }
|
|
||||||
let(:xml) { comment.to_xml.to_s }
|
|
||||||
|
|
||||||
before do
|
|
||||||
connect_users(alice, alices_aspect, commenter, commenter_aspect)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the sender handle" do
|
|
||||||
expect(xml.include?(commenter.diaspora_handle)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the post_guid" do
|
|
||||||
expect(xml).to include(post.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "marshalling" do
|
|
||||||
let(:marshalled_comment) { Comment.from_xml(xml) }
|
|
||||||
|
|
||||||
it "marshals the author" do
|
|
||||||
expect(marshalled_comment.author).to eq(commenter.person)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the post" do
|
|
||||||
expect(marshalled_comment.post).to eq(post)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "tries to fetch a missing parent" do
|
|
||||||
guid = post.guid
|
|
||||||
marshalled_comment
|
|
||||||
post.destroy
|
|
||||||
expect_any_instance_of(Comment).to receive(:fetch_parent).with(guid).and_return(nil)
|
|
||||||
Comment.from_xml(xml)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "it is relayable" do
|
describe "it is relayable" do
|
||||||
let(:remote_parent) { build(:status_message, author: remote_raphael) }
|
let(:remote_parent) { build(:status_message, author: remote_raphael) }
|
||||||
let(:local_parent) { local_luke.post :status_message, text: "hi", to: local_luke.aspects.first }
|
let(:local_parent) { local_luke.post :status_message, text: "hi", to: local_luke.aspects.first }
|
||||||
|
|
|
||||||
|
|
@ -70,37 +70,6 @@ describe Conversation, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "transport" do
|
|
||||||
let(:conversation_message) { conversation.messages.first }
|
|
||||||
let(:xml) { conversation.to_diaspora_xml }
|
|
||||||
|
|
||||||
before do
|
|
||||||
conversation
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "serialization" do
|
|
||||||
it "serializes the message" do
|
|
||||||
expect(xml.gsub(/\s/, "")).to include(conversation_message.to_xml.to_s.gsub(/\s/, ""))
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the participants" do
|
|
||||||
create_hash[:participant_ids].each do |id|
|
|
||||||
expect(xml).to include(Person.find(id).diaspora_handle)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the created_at time" do
|
|
||||||
expect(xml).to include(conversation_message.created_at.to_s)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#subscribers" do
|
|
||||||
it "returns the recipients for the post owner" do
|
|
||||||
expect(conversation.subscribers).to eq(user1.contacts.map(&:person))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#invalid parameters" do
|
describe "#invalid parameters" do
|
||||||
context "local author" do
|
context "local author" do
|
||||||
let(:invalid_hash) {
|
let(:invalid_hash) {
|
||||||
|
|
|
||||||
|
|
@ -46,36 +46,6 @@ describe Like, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'xml' do
|
|
||||||
before do
|
|
||||||
alices_aspect = alice.aspects.first
|
|
||||||
|
|
||||||
@liker = FactoryGirl.create(:user)
|
|
||||||
@liker_aspect = @liker.aspects.create(:name => "dummies")
|
|
||||||
connect_users(alice, alices_aspect, @liker, @liker_aspect)
|
|
||||||
@post = alice.post(:status_message, :text => "huhu", :to => alices_aspect.id)
|
|
||||||
@like = @liker.like!(@post)
|
|
||||||
@xml = @like.to_xml.to_s
|
|
||||||
end
|
|
||||||
it 'serializes the sender handle' do
|
|
||||||
expect(@xml.include?(@liker.diaspora_handle)).to be true
|
|
||||||
end
|
|
||||||
it' serializes the post_guid' do
|
|
||||||
expect(@xml).to include(@post.guid)
|
|
||||||
end
|
|
||||||
describe 'marshalling' do
|
|
||||||
before do
|
|
||||||
@marshalled_like = Like.from_xml(@xml)
|
|
||||||
end
|
|
||||||
it 'marshals the author' do
|
|
||||||
expect(@marshalled_like.author).to eq(@liker.person)
|
|
||||||
end
|
|
||||||
it 'marshals the post' do
|
|
||||||
expect(@marshalled_like.target).to eq(@post)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'it is relayable' do
|
describe 'it is relayable' do
|
||||||
before do
|
before do
|
||||||
@local_luke, @local_leia, @remote_raphael = set_up_friends
|
@local_luke, @local_leia, @remote_raphael = set_up_friends
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ describe Message, :type => :model do
|
||||||
|
|
||||||
@conversation = Conversation.create!(@create_hash)
|
@conversation = Conversation.create!(@create_hash)
|
||||||
@message = @conversation.messages.first
|
@message = @conversation.messages.first
|
||||||
@xml = @message.to_diaspora_xml
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates that the author is a participant in the conversation' do
|
it 'validates that the author is a participant in the conversation' do
|
||||||
|
|
@ -34,24 +33,6 @@ describe Message, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'serialization' do
|
|
||||||
it 'serializes the text' do
|
|
||||||
expect(@xml).to include(@message.text)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the author_handle' do
|
|
||||||
expect(@xml).to include(@message.author.diaspora_handle)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the created_at time' do
|
|
||||||
expect(@xml).to include(@message.created_at.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the conversation_guid time' do
|
|
||||||
expect(@xml).to include(@message.conversation.guid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'it is relayable' do
|
describe 'it is relayable' do
|
||||||
before do
|
before do
|
||||||
@local_luke, @local_leia, @remote_raphael = set_up_friends
|
@local_luke, @local_leia, @remote_raphael = set_up_friends
|
||||||
|
|
|
||||||
|
|
@ -240,21 +240,6 @@ describe Person, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'XML' do
|
|
||||||
before do
|
|
||||||
@xml = @person.to_xml.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should serialize to xml' do
|
|
||||||
expect(@xml.include?("person")).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should have a profile in its xml' do
|
|
||||||
expect(@xml.include?("first_name")).to eq(true)
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it '#owns? posts' do
|
it '#owns? posts' do
|
||||||
person_message = FactoryGirl.create(:status_message, :author => @person)
|
person_message = FactoryGirl.create(:status_message, :author => @person)
|
||||||
person_two = FactoryGirl.create(:person)
|
person_two = FactoryGirl.create(:person)
|
||||||
|
|
|
||||||
|
|
@ -185,31 +185,6 @@ describe Photo, :type => :model do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'serialization' do
|
|
||||||
before do
|
|
||||||
skip # TODO
|
|
||||||
@saved_photo = with_carrierwave_processing do
|
|
||||||
@user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id)
|
|
||||||
end
|
|
||||||
@xml = @saved_photo.to_xml.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the url' do
|
|
||||||
expect(@xml.include?(@saved_photo.remote_photo_path)).to be true
|
|
||||||
expect(@xml.include?(@saved_photo.remote_photo_name)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the diaspora_handle' do
|
|
||||||
expect(@xml.include?(@user.diaspora_handle)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the height and width' do
|
|
||||||
expect(@xml).to include 'height'
|
|
||||||
expect(@xml.include?('width')).to be true
|
|
||||||
expect(@xml.include?('40')).to be true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "remote photos" do
|
describe "remote photos" do
|
||||||
it "should set the remote_photo on marshalling" do
|
it "should set the remote_photo on marshalling" do
|
||||||
url = @saved_photo.url
|
url = @saved_photo.url
|
||||||
|
|
|
||||||
|
|
@ -25,56 +25,6 @@ describe PollParticipation, :type => :model do
|
||||||
bob.participate_in_poll!(@status, @poll.poll_answers.first)
|
bob.participate_in_poll!(@status, @poll.poll_answers.first)
|
||||||
}.to_not raise_error
|
}.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'xml' do
|
|
||||||
before do
|
|
||||||
@poll_participant = FactoryGirl.create(:user)
|
|
||||||
@poll_participant_aspect = @poll_participant.aspects.create(:name => "bruisers")
|
|
||||||
connect_users(alice, @alices_aspect, @poll_participant, @poll_participant_aspect)
|
|
||||||
@poll = Poll.new(:question => "hi")
|
|
||||||
@poll.poll_answers.build(:answer => "a")
|
|
||||||
@poll.poll_answers.build(:answer => "b")
|
|
||||||
@post = alice.post :status_message, :text => "hello", :to => @alices_aspect.id
|
|
||||||
@post.poll = @poll
|
|
||||||
@poll_participation = @poll_participant.participate_in_poll!(@post, @poll.poll_answers.first)
|
|
||||||
@xml = @poll_participation.to_xml.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the class name' do
|
|
||||||
expect(@xml.include?(PollParticipation.name.underscore.to_s)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the sender handle' do
|
|
||||||
expect(@xml.include?(@poll_participation.diaspora_handle)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the poll_guid' do
|
|
||||||
expect(@xml).to include(@poll.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'serializes the poll_answer_guid' do
|
|
||||||
expect(@xml).to include(@poll_participation.poll_answer.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'marshalling' do
|
|
||||||
before do
|
|
||||||
@marshalled_poll_participation = PollParticipation.from_xml(@xml)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the author' do
|
|
||||||
expect(@marshalled_poll_participation.author).to eq(@poll_participant.person)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the answer' do
|
|
||||||
expect(@marshalled_poll_participation.poll_answer).to eq(@poll_participation.poll_answer)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'marshals the poll' do
|
|
||||||
expect(@marshalled_poll_participation.poll).to eq(@poll)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'it is relayable' do
|
describe 'it is relayable' do
|
||||||
|
|
|
||||||
|
|
@ -161,42 +161,6 @@ describe Profile, :type => :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#from_xml' do
|
|
||||||
it 'should make a valid profile object' do
|
|
||||||
@profile = FactoryGirl.build(:profile)
|
|
||||||
@profile.tag_string = '#big #rafi #style'
|
|
||||||
xml = @profile.to_xml
|
|
||||||
|
|
||||||
new_profile = Profile.from_xml(xml.to_s)
|
|
||||||
expect(new_profile.tag_string).not_to be_blank
|
|
||||||
expect(new_profile.tag_string).to include('#rafi')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'serialization' do
|
|
||||||
let(:person) { FactoryGirl.build(:person, diaspora_handle: "foobar@localhost") }
|
|
||||||
|
|
||||||
it 'should include persons diaspora handle' do
|
|
||||||
xml = Diaspora::Federation.xml(Diaspora::Federation::Entities.profile(person.profile)).to_xml
|
|
||||||
expect(xml).to include "foobar"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'includes tags' do
|
|
||||||
person.profile.tag_string = '#one'
|
|
||||||
person.profile.build_tags
|
|
||||||
person.profile.save
|
|
||||||
xml = Diaspora::Federation.xml(Diaspora::Federation::Entities.profile(person.profile)).to_xml
|
|
||||||
expect(xml).to include "#one"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'includes location' do
|
|
||||||
person.profile.location = 'Dark Side, Moon'
|
|
||||||
person.profile.save
|
|
||||||
xml = Diaspora::Federation.xml(Diaspora::Federation::Entities.profile(person.profile)).to_xml
|
|
||||||
expect(xml).to include "Dark Side, Moon"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#image_url' do
|
describe '#image_url' do
|
||||||
before do
|
before do
|
||||||
@profile = FactoryGirl.build(:profile)
|
@profile = FactoryGirl.build(:profile)
|
||||||
|
|
|
||||||
|
|
@ -94,163 +94,6 @@ describe Reshare, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "XML" do
|
|
||||||
let(:reshare) { build(:reshare) }
|
|
||||||
let(:xml) { reshare.to_xml.to_s }
|
|
||||||
|
|
||||||
before do
|
|
||||||
skip # TODO
|
|
||||||
end
|
|
||||||
|
|
||||||
context "serialization" do
|
|
||||||
it "serializes root_diaspora_id" do
|
|
||||||
expect(xml).to include("root_diaspora_id")
|
|
||||||
expect(xml).to include(reshare.author.diaspora_handle)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes root_guid" do
|
|
||||||
expect(xml).to include("root_guid")
|
|
||||||
expect(xml).to include(reshare.root.guid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "marshalling" do
|
|
||||||
let(:root_object) { reshare.root }
|
|
||||||
|
|
||||||
context "local" do
|
|
||||||
let(:original_author) { reshare.root.author }
|
|
||||||
|
|
||||||
it "marshals the guid" do
|
|
||||||
expect(Reshare.from_xml(xml).root_guid).to eq(root_object.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fetches the root post from root_guid" do
|
|
||||||
expect(Reshare.from_xml(xml).root).to eq(root_object)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fetches the root author from root_diaspora_id" do
|
|
||||||
expect(Reshare.from_xml(xml).root.author).to eq(original_author)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "destroy" do
|
|
||||||
it "allows you to destroy the reshare if the root post is missing" do
|
|
||||||
reshare
|
|
||||||
reshare.root = nil
|
|
||||||
|
|
||||||
expect {
|
|
||||||
reshare.destroy
|
|
||||||
}.to_not raise_error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "remote" do
|
|
||||||
before do
|
|
||||||
# root_object = reshare.root
|
|
||||||
root_object.delete
|
|
||||||
@response = double
|
|
||||||
allow(@response).to receive(:status).and_return(200)
|
|
||||||
allow(@response).to receive(:success?).and_return(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fetches the root author from root_diaspora_id" do
|
|
||||||
@original_profile = reshare.root.author.profile.dup
|
|
||||||
reshare.root.author.profile.delete
|
|
||||||
@original_author = reshare.root.author.dup
|
|
||||||
reshare.root.author.delete
|
|
||||||
|
|
||||||
@original_author.profile = @original_profile
|
|
||||||
|
|
||||||
expect(Person).to receive(:find_or_fetch_by_identifier).and_return(@original_author)
|
|
||||||
|
|
||||||
allow(@response).to receive(:body).and_return(
|
|
||||||
Diaspora::Federation.xml(Diaspora::Federation::Entities.status_message(root_object)).to_xml
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(Faraday.default_connection).to receive(:get).with(
|
|
||||||
URI.join(
|
|
||||||
@original_author.url,
|
|
||||||
Rails.application.routes.url_helpers.short_post_path(
|
|
||||||
root_object.guid,
|
|
||||||
format: "xml"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).and_return(@response)
|
|
||||||
Reshare.from_xml(xml)
|
|
||||||
end
|
|
||||||
|
|
||||||
context "fetching post" do
|
|
||||||
it "raises if the post is not found" do
|
|
||||||
allow(@response).to receive(:status).and_return(404)
|
|
||||||
expect(Faraday.default_connection).to receive(:get).and_return(@response)
|
|
||||||
|
|
||||||
expect {
|
|
||||||
Reshare.from_xml(xml)
|
|
||||||
}.to raise_error(Diaspora::PostNotFetchable)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "raises if there's another error receiving the post" do
|
|
||||||
allow(@response).to receive(:status).and_return(500)
|
|
||||||
allow(@response).to receive(:success?).and_return(false)
|
|
||||||
expect(Faraday.default_connection).to receive(:get).and_return(@response)
|
|
||||||
|
|
||||||
expect {
|
|
||||||
Reshare.from_xml(xml)
|
|
||||||
}.to raise_error RuntimeError
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "saving the post" do
|
|
||||||
before do
|
|
||||||
allow(@response).to receive(:body).and_return(
|
|
||||||
Diaspora::Federation.xml(Diaspora::Federation::Entities.status_message(root_object)).to_xml
|
|
||||||
)
|
|
||||||
allow(Faraday.default_connection).to receive(:get).with(
|
|
||||||
URI.join(
|
|
||||||
reshare.root.author.url,
|
|
||||||
Rails.application.routes.url_helpers.short_post_path(
|
|
||||||
root_object.guid,
|
|
||||||
format: "xml"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
).and_return(@response)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "fetches the root post from root_guid" do
|
|
||||||
root = Reshare.from_xml(xml).root
|
|
||||||
|
|
||||||
%i(text guid diaspora_handle type public).each do |attr|
|
|
||||||
expect(root.send(attr)).to eq(reshare.root.send(attr))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "correctly saves the type" do
|
|
||||||
expect(Reshare.from_xml(xml).root.reload.type).to eq("StatusMessage")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "correctly sets the author" do
|
|
||||||
@original_author = reshare.root.author
|
|
||||||
expect(Reshare.from_xml(xml).root.reload.author.reload).to eq(@original_author)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "verifies that the author of the post received is the same as the author in the reshare xml" do
|
|
||||||
@original_author = reshare.root.author.dup
|
|
||||||
xml = reshare.to_xml.to_s
|
|
||||||
|
|
||||||
different_person = FactoryGirl.build(:person)
|
|
||||||
expect(Person).to receive(:find_or_fetch_by_identifier).and_return(different_person)
|
|
||||||
|
|
||||||
allow(different_person).to receive(:url).and_return(@original_author.url)
|
|
||||||
|
|
||||||
expect {
|
|
||||||
Reshare.from_xml(xml)
|
|
||||||
}.to raise_error /^Diaspora ID \(.+\) in the root does not match the Diaspora ID \(.+\) specified in the reshare!$/
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#post_location" do
|
describe "#post_location" do
|
||||||
let(:status_message) { build(:status_message, text: "This is a status_message", author: bob.person, public: true) }
|
let(:status_message) { build(:status_message, text: "This is a status_message", author: bob.person, public: true) }
|
||||||
let(:reshare) { create(:reshare, root: status_message) }
|
let(:reshare) { create(:reshare, root: status_message) }
|
||||||
|
|
|
||||||
|
|
@ -260,111 +260,6 @@ describe StatusMessage, type: :model do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "XML" do
|
|
||||||
let(:message) { FactoryGirl.build(:status_message, text: "I hate WALRUSES!", author: user.person) }
|
|
||||||
let(:xml) { message.to_xml.to_s }
|
|
||||||
let(:marshalled) { StatusMessage.from_xml(xml) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
skip # TODO
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the escaped, unprocessed message" do
|
|
||||||
text = "[url](http://example.org)<script> alert('xss should be federated');</script>"
|
|
||||||
message.text = text
|
|
||||||
expect(xml).to include Builder::XChar.encode(text)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the message" do
|
|
||||||
expect(xml).to include "<raw_message>I hate WALRUSES!</raw_message>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the author address" do
|
|
||||||
expect(xml).to include(user.person.diaspora_handle)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".from_xml" do
|
|
||||||
it "marshals the message" do
|
|
||||||
expect(marshalled.text).to eq("I hate WALRUSES!")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the guid" do
|
|
||||||
expect(marshalled.guid).to eq(message.guid)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the author" do
|
|
||||||
expect(marshalled.author).to eq(message.author)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the diaspora_handle" do
|
|
||||||
expect(marshalled.diaspora_handle).to eq(message.diaspora_handle)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with some photos" do
|
|
||||||
before do
|
|
||||||
message.photos << FactoryGirl.build(:photo)
|
|
||||||
message.photos << FactoryGirl.build(:photo)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the photos" do
|
|
||||||
expect(xml).to include "photo"
|
|
||||||
expect(xml).to include message.photos.first.remote_photo_path
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".from_xml" do
|
|
||||||
it "marshals the photos" do
|
|
||||||
expect(marshalled.photos.size).to eq(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "handles existing photos" do
|
|
||||||
message.photos.each(&:save!)
|
|
||||||
expect(marshalled).to be_valid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a location" do
|
|
||||||
before do
|
|
||||||
message.location = FactoryGirl.build(:location)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the location" do
|
|
||||||
expect(xml).to include "location"
|
|
||||||
expect(xml).to include "lat"
|
|
||||||
expect(xml).to include "lng"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".from_xml" do
|
|
||||||
it "marshals the location" do
|
|
||||||
expect(marshalled.location).to be_present
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with a poll" do
|
|
||||||
before do
|
|
||||||
message.poll = FactoryGirl.build(:poll)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "serializes the poll" do
|
|
||||||
expect(xml).to include "poll"
|
|
||||||
expect(xml).to include "question"
|
|
||||||
expect(xml).to include "poll_answer"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ".from_xml" do
|
|
||||||
it "marshals the poll" do
|
|
||||||
expect(marshalled.poll).to be_present
|
|
||||||
end
|
|
||||||
|
|
||||||
it "marshals the poll answers" do
|
|
||||||
expect(marshalled.poll.poll_answers.size).to eq(2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "oembed" do
|
describe "oembed" do
|
||||||
let(:youtube_url) { "https://www.youtube.com/watch?v=3PtFwlKfvHI" }
|
let(:youtube_url) { "https://www.youtube.com/watch?v=3PtFwlKfvHI" }
|
||||||
let(:message_text) { "#{youtube_url} is so cool. so is this link -> https://joindiaspora.com" }
|
let(:message_text) { "#{youtube_url} is so cool. so is this link -> https://joindiaspora.com" }
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue