use signature data for federation
This commit is contained in:
parent
b82d1c2ca9
commit
2a6ca1b831
4 changed files with 112 additions and 25 deletions
|
|
@ -35,12 +35,16 @@ module Diaspora
|
||||||
|
|
||||||
def self.comment(comment)
|
def self.comment(comment)
|
||||||
DiasporaFederation::Entities::Comment.new(
|
DiasporaFederation::Entities::Comment.new(
|
||||||
author: comment.diaspora_handle,
|
{
|
||||||
guid: comment.guid,
|
author: comment.diaspora_handle,
|
||||||
parent_guid: comment.post.guid,
|
guid: comment.guid,
|
||||||
text: comment.text,
|
parent_guid: comment.post.guid,
|
||||||
author_signature: comment.author_signature,
|
text: comment.text,
|
||||||
parent: related_entity(comment.post)
|
author_signature: comment.signature.try(:author_signature),
|
||||||
|
parent: related_entity(comment.post)
|
||||||
|
},
|
||||||
|
comment.signature.try(:order),
|
||||||
|
comment.signature.try(:additional_data) || {}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -65,13 +69,17 @@ module Diaspora
|
||||||
|
|
||||||
def self.like(like)
|
def self.like(like)
|
||||||
DiasporaFederation::Entities::Like.new(
|
DiasporaFederation::Entities::Like.new(
|
||||||
author: like.diaspora_handle,
|
{
|
||||||
guid: like.guid,
|
author: like.diaspora_handle,
|
||||||
parent_guid: like.target.guid,
|
guid: like.guid,
|
||||||
positive: like.positive,
|
parent_guid: like.target.guid,
|
||||||
parent_type: Mappings.entity_name_for(like.target),
|
positive: like.positive,
|
||||||
author_signature: like.author_signature,
|
parent_type: Mappings.entity_name_for(like.target),
|
||||||
parent: related_entity(like.target)
|
author_signature: like.signature.try(:author_signature),
|
||||||
|
parent: related_entity(like.target)
|
||||||
|
},
|
||||||
|
like.signature.try(:order),
|
||||||
|
like.signature.try(:additional_data) || {}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -138,12 +146,16 @@ module Diaspora
|
||||||
|
|
||||||
def self.poll_participation(poll_participation)
|
def self.poll_participation(poll_participation)
|
||||||
DiasporaFederation::Entities::PollParticipation.new(
|
DiasporaFederation::Entities::PollParticipation.new(
|
||||||
author: poll_participation.diaspora_handle,
|
{
|
||||||
guid: poll_participation.guid,
|
author: poll_participation.diaspora_handle,
|
||||||
parent_guid: poll_participation.poll.guid,
|
guid: poll_participation.guid,
|
||||||
poll_answer_guid: poll_participation.poll_answer.guid,
|
parent_guid: poll_participation.poll.guid,
|
||||||
author_signature: poll_participation.author_signature,
|
poll_answer_guid: poll_participation.poll_answer.guid,
|
||||||
parent: related_entity(poll_participation.poll)
|
author_signature: poll_participation.signature.try(:author_signature),
|
||||||
|
parent: related_entity(poll_participation.poll)
|
||||||
|
},
|
||||||
|
poll_participation.signature.try(:order),
|
||||||
|
poll_participation.signature.try(:additional_data) || {}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ module Diaspora
|
||||||
validates :author_signature, presence: true
|
validates :author_signature, presence: true
|
||||||
|
|
||||||
serialize :additional_data, Hash
|
serialize :additional_data, Hash
|
||||||
|
|
||||||
|
def order
|
||||||
|
signature_order.order.split
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -304,6 +304,28 @@ FactoryGirl.define do
|
||||||
after(:build) {|m| m.conversation.participants << m.author }
|
after(:build) {|m| m.conversation.participants << m.author }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory(:signature_order) do
|
||||||
|
order "guid parent_guid text author"
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:comment_signature) do
|
||||||
|
author_signature "some signature"
|
||||||
|
association :signature_order, order: "guid parent_guid text author new_property"
|
||||||
|
additional_data { {"new_property" => "some text"} }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:like_signature) do
|
||||||
|
author_signature "some signature"
|
||||||
|
association :signature_order, order: "positive guid parent_type parent_guid author new_property"
|
||||||
|
additional_data { {"new_property" => "some text"} }
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:poll_participation_signature) do
|
||||||
|
author_signature "some signature"
|
||||||
|
association :signature_order, order: "guid parent_guid author poll_answer_guid new_property"
|
||||||
|
additional_data { {"new_property" => "some text"} }
|
||||||
|
end
|
||||||
|
|
||||||
#templates
|
#templates
|
||||||
factory(:status_with_photo_backdrop, :parent => :status_message_with_photo)
|
factory(:status_with_photo_backdrop, :parent => :status_message_with_photo)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ describe Diaspora::Federation::Entities do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a comment" do
|
it "builds a comment" do
|
||||||
diaspora_entity = FactoryGirl.build(:comment, author_signature: "abc")
|
diaspora_entity = FactoryGirl.build(:comment)
|
||||||
federation_entity = described_class.build(diaspora_entity)
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Comment)
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Comment)
|
||||||
|
|
@ -19,7 +19,23 @@ describe Diaspora::Federation::Entities do
|
||||||
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
|
||||||
expect(federation_entity.text).to eq(diaspora_entity.text)
|
expect(federation_entity.text).to eq(diaspora_entity.text)
|
||||||
expect(federation_entity.author_signature).to eq(diaspora_entity.author_signature)
|
expect(federation_entity.author_signature).to be_nil
|
||||||
|
expect(federation_entity.xml_order).to be_nil
|
||||||
|
expect(federation_entity.additional_xml_elements).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds a comment with signature" do
|
||||||
|
diaspora_entity = FactoryGirl.build(:comment, signature: FactoryGirl.build(:comment_signature))
|
||||||
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Comment)
|
||||||
|
expect(federation_entity.author).to eq(diaspora_entity.author.diaspora_handle)
|
||||||
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.post.guid)
|
||||||
|
expect(federation_entity.text).to eq(diaspora_entity.text)
|
||||||
|
expect(federation_entity.author_signature).to eq(diaspora_entity.signature.author_signature)
|
||||||
|
expect(federation_entity.xml_order).to eq(diaspora_entity.signature.signature_order.order.split)
|
||||||
|
expect(federation_entity.additional_xml_elements).to eq(diaspora_entity.signature.additional_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a contact (request)" do
|
it "builds a contact (request)" do
|
||||||
|
|
@ -62,7 +78,7 @@ describe Diaspora::Federation::Entities do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a like" do
|
it "builds a like" do
|
||||||
diaspora_entity = FactoryGirl.build(:like, author_signature: "abc")
|
diaspora_entity = FactoryGirl.build(:like)
|
||||||
federation_entity = described_class.build(diaspora_entity)
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Like)
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Like)
|
||||||
|
|
@ -70,7 +86,23 @@ describe Diaspora::Federation::Entities do
|
||||||
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
expect(federation_entity.parent_guid).to eq(diaspora_entity.target.guid)
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.target.guid)
|
||||||
expect(federation_entity.positive).to eq(diaspora_entity.positive)
|
expect(federation_entity.positive).to eq(diaspora_entity.positive)
|
||||||
expect(federation_entity.author_signature).to eq(diaspora_entity.author_signature)
|
expect(federation_entity.author_signature).to be_nil
|
||||||
|
expect(federation_entity.xml_order).to be_nil
|
||||||
|
expect(federation_entity.additional_xml_elements).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds a like with signature" do
|
||||||
|
diaspora_entity = FactoryGirl.build(:like, signature: FactoryGirl.build(:like_signature))
|
||||||
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Like)
|
||||||
|
expect(federation_entity.author).to eq(diaspora_entity.author.diaspora_handle)
|
||||||
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.target.guid)
|
||||||
|
expect(federation_entity.positive).to eq(diaspora_entity.positive)
|
||||||
|
expect(federation_entity.author_signature).to eq(diaspora_entity.signature.author_signature)
|
||||||
|
expect(federation_entity.xml_order).to eq(diaspora_entity.signature.signature_order.order.split)
|
||||||
|
expect(federation_entity.additional_xml_elements).to eq(diaspora_entity.signature.additional_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a message" do
|
it "builds a message" do
|
||||||
|
|
@ -114,7 +146,7 @@ describe Diaspora::Federation::Entities do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a poll participation" do
|
it "builds a poll participation" do
|
||||||
diaspora_entity = FactoryGirl.build(:poll_participation, author_signature: "abc")
|
diaspora_entity = FactoryGirl.build(:poll_participation)
|
||||||
federation_entity = described_class.build(diaspora_entity)
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)
|
||||||
|
|
@ -122,7 +154,24 @@ describe Diaspora::Federation::Entities do
|
||||||
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
expect(federation_entity.parent_guid).to eq(diaspora_entity.poll_answer.poll.guid)
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.poll_answer.poll.guid)
|
||||||
expect(federation_entity.poll_answer_guid).to eq(diaspora_entity.poll_answer.guid)
|
expect(federation_entity.poll_answer_guid).to eq(diaspora_entity.poll_answer.guid)
|
||||||
expect(federation_entity.author_signature).to eq(diaspora_entity.author_signature)
|
expect(federation_entity.author_signature).to be_nil
|
||||||
|
expect(federation_entity.xml_order).to be_nil
|
||||||
|
expect(federation_entity.additional_xml_elements).to be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "builds a poll participation with signature" do
|
||||||
|
signature = FactoryGirl.build(:poll_participation_signature)
|
||||||
|
diaspora_entity = FactoryGirl.build(:poll_participation, signature: signature)
|
||||||
|
federation_entity = described_class.build(diaspora_entity)
|
||||||
|
|
||||||
|
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)
|
||||||
|
expect(federation_entity.author).to eq(diaspora_entity.author.diaspora_handle)
|
||||||
|
expect(federation_entity.guid).to eq(diaspora_entity.guid)
|
||||||
|
expect(federation_entity.parent_guid).to eq(diaspora_entity.poll_answer.poll.guid)
|
||||||
|
expect(federation_entity.poll_answer_guid).to eq(diaspora_entity.poll_answer.guid)
|
||||||
|
expect(federation_entity.author_signature).to eq(signature.author_signature)
|
||||||
|
expect(federation_entity.xml_order).to eq(signature.signature_order.order.split)
|
||||||
|
expect(federation_entity.additional_xml_elements).to eq(signature.additional_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "builds a profile" do
|
it "builds a profile" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue