extract mappings between diaspora and the federation gem
This commit is contained in:
parent
7bdf4921fd
commit
65f03b2d08
9 changed files with 184 additions and 140 deletions
|
|
@ -74,7 +74,7 @@ DiasporaFederation.configure do |config|
|
|||
end
|
||||
|
||||
on :fetch_related_entity do |entity_type, guid|
|
||||
entity = entity_type.constantize.find_by(guid: guid)
|
||||
entity = Diaspora::Federation::Mappings.model_class_for(entity_type).find_by(guid: guid)
|
||||
Diaspora::Federation::Entities.related_entity(entity) if entity
|
||||
end
|
||||
|
||||
|
|
@ -97,39 +97,13 @@ DiasporaFederation.configure do |config|
|
|||
when DiasporaFederation::Entities::Retraction
|
||||
Diaspora::Federation::Receive.retraction(entity, recipient_id)
|
||||
else
|
||||
persisted = case entity
|
||||
when DiasporaFederation::Entities::Comment
|
||||
Diaspora::Federation::Receive.comment(entity)
|
||||
when DiasporaFederation::Entities::Contact
|
||||
Diaspora::Federation::Receive.contact(entity)
|
||||
when DiasporaFederation::Entities::Conversation
|
||||
Diaspora::Federation::Receive.conversation(entity)
|
||||
when DiasporaFederation::Entities::Like
|
||||
Diaspora::Federation::Receive.like(entity)
|
||||
when DiasporaFederation::Entities::Message
|
||||
Diaspora::Federation::Receive.message(entity)
|
||||
when DiasporaFederation::Entities::Participation
|
||||
Diaspora::Federation::Receive.participation(entity)
|
||||
when DiasporaFederation::Entities::Photo
|
||||
Diaspora::Federation::Receive.photo(entity)
|
||||
when DiasporaFederation::Entities::PollParticipation
|
||||
Diaspora::Federation::Receive.poll_participation(entity)
|
||||
when DiasporaFederation::Entities::Profile
|
||||
Diaspora::Federation::Receive.profile(entity)
|
||||
when DiasporaFederation::Entities::Reshare
|
||||
Diaspora::Federation::Receive.reshare(entity)
|
||||
when DiasporaFederation::Entities::StatusMessage
|
||||
Diaspora::Federation::Receive.status_message(entity)
|
||||
else
|
||||
raise DiasporaFederation::Entity::UnknownEntity, "unknown entity: #{entity.class}"
|
||||
end
|
||||
|
||||
persisted = Diaspora::Federation::Receive.perform(entity)
|
||||
Workers::ReceiveLocal.perform_async(persisted.class.to_s, persisted.id, [recipient_id].compact) if persisted
|
||||
end
|
||||
end
|
||||
|
||||
on :fetch_public_entity do |entity_type, guid|
|
||||
entity = entity_type.constantize.find_by(guid: guid, public: true)
|
||||
entity = Diaspora::Federation::Mappings.model_class_for(entity_type).find_by(guid: guid, public: true)
|
||||
Diaspora::Federation::Entities.post(entity) if entity.is_a? Post
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -12,4 +12,5 @@ end
|
|||
|
||||
require "diaspora/federation/dispatcher"
|
||||
require "diaspora/federation/entities"
|
||||
require "diaspora/federation/mappings"
|
||||
require "diaspora/federation/receive"
|
||||
|
|
|
|||
|
|
@ -2,23 +2,7 @@ module Diaspora
|
|||
module Federation
|
||||
module Entities
|
||||
def self.build(entity)
|
||||
case entity
|
||||
when AccountDeletion then account_deletion(entity)
|
||||
when Comment then comment(entity)
|
||||
when Contact then contact(entity)
|
||||
when Conversation then conversation(entity)
|
||||
when Like then like(entity)
|
||||
when Message then message(entity)
|
||||
when Participation then participation(entity)
|
||||
when Photo then photo(entity)
|
||||
when PollParticipation then poll_participation(entity)
|
||||
when Profile then profile(entity)
|
||||
when Reshare then reshare(entity)
|
||||
when Retraction then build_retraction(entity)
|
||||
when StatusMessage then status_message(entity)
|
||||
else
|
||||
raise DiasporaFederation::Entity::UnknownEntity, "unknown entity: #{entity.class}"
|
||||
end
|
||||
public_send(Mappings.builder_for(entity.class), entity)
|
||||
end
|
||||
|
||||
def self.build_retraction(retraction)
|
||||
|
|
@ -85,7 +69,7 @@ module Diaspora
|
|||
guid: like.guid,
|
||||
parent_guid: like.target.guid,
|
||||
positive: like.positive,
|
||||
parent_type: like.target.class.base_class.to_s,
|
||||
parent_type: Mappings.entity_name_for(like.target),
|
||||
author_signature: like.author_signature,
|
||||
parent: related_entity(like.target)
|
||||
)
|
||||
|
|
@ -117,7 +101,7 @@ module Diaspora
|
|||
author: participation.diaspora_handle,
|
||||
guid: participation.guid,
|
||||
parent_guid: participation.target.guid,
|
||||
parent_type: participation.target.class.base_class.to_s,
|
||||
parent_type: Mappings.entity_name_for(participation.target),
|
||||
parent: related_entity(participation.target)
|
||||
)
|
||||
end
|
||||
|
|
@ -185,7 +169,7 @@ module Diaspora
|
|||
def self.relayable_retraction(target, sender)
|
||||
DiasporaFederation::Entities::RelayableRetraction.new(
|
||||
target_guid: target.guid,
|
||||
target_type: target.class.base_class.to_s,
|
||||
target_type: Mappings.entity_name_for(target),
|
||||
target: related_entity(target),
|
||||
author: sender.diaspora_handle
|
||||
)
|
||||
|
|
@ -206,17 +190,18 @@ module Diaspora
|
|||
def self.retraction(target)
|
||||
case target
|
||||
when Contact
|
||||
# TODO: deprecated
|
||||
author = target.user.diaspora_handle
|
||||
DiasporaFederation::Entities::Retraction.new(
|
||||
target_guid: target.user.guid,
|
||||
target_type: Person.to_s,
|
||||
target_type: "Person",
|
||||
target: DiasporaFederation::Entities::RelatedEntity.new(author: author, local: true),
|
||||
author: author
|
||||
)
|
||||
else
|
||||
DiasporaFederation::Entities::Retraction.new(
|
||||
target_guid: target.guid,
|
||||
target_type: target.class.base_class.to_s,
|
||||
target_type: Mappings.entity_name_for(target),
|
||||
target: related_entity(target),
|
||||
author: target.diaspora_handle
|
||||
)
|
||||
|
|
@ -227,7 +212,7 @@ module Diaspora
|
|||
def self.signed_retraction(target, sender)
|
||||
DiasporaFederation::Entities::SignedRetraction.new(
|
||||
target_guid: target.guid,
|
||||
target_type: target.class.base_class.to_s,
|
||||
target_type: Mappings.entity_name_for(target),
|
||||
target: related_entity(target),
|
||||
author: sender.diaspora_handle
|
||||
)
|
||||
|
|
|
|||
81
lib/diaspora/federation/mappings.rb
Normal file
81
lib/diaspora/federation/mappings.rb
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
module Diaspora
|
||||
module Federation
|
||||
module Mappings
|
||||
# used in Diaspora::Federation::Receive
|
||||
def self.receiver_for(federation_class)
|
||||
fetch_from(ENTITY_RECEIVERS, federation_class)
|
||||
end
|
||||
|
||||
# used in Diaspora::Federation::Entities
|
||||
def self.builder_for(diaspora_class)
|
||||
fetch_from(ENTITY_BUILDERS, diaspora_class)
|
||||
end
|
||||
|
||||
def self.model_class_for(entity_name)
|
||||
fetch_from(ENTITY_MODELS, entity_name)
|
||||
end
|
||||
|
||||
def self.entity_name_for(model)
|
||||
fetch_from(ENTITY_NAMES, model.class.base_class)
|
||||
end
|
||||
|
||||
private_class_method def self.fetch_from(mapping, key)
|
||||
mapping.fetch(key) { raise DiasporaFederation::Entity::UnknownEntity, "unknown entity: #{key}" }
|
||||
end
|
||||
|
||||
ENTITY_RECEIVERS = {
|
||||
DiasporaFederation::Entities::Comment => :comment,
|
||||
DiasporaFederation::Entities::Contact => :contact,
|
||||
DiasporaFederation::Entities::Conversation => :conversation,
|
||||
DiasporaFederation::Entities::Like => :like,
|
||||
DiasporaFederation::Entities::Message => :message,
|
||||
DiasporaFederation::Entities::Participation => :participation,
|
||||
DiasporaFederation::Entities::Photo => :photo,
|
||||
DiasporaFederation::Entities::PollParticipation => :poll_participation,
|
||||
DiasporaFederation::Entities::Profile => :profile,
|
||||
DiasporaFederation::Entities::Reshare => :reshare,
|
||||
DiasporaFederation::Entities::StatusMessage => :status_message
|
||||
}.freeze
|
||||
|
||||
ENTITY_BUILDERS = {
|
||||
AccountDeletion => :account_deletion,
|
||||
Comment => :comment,
|
||||
Contact => :contact,
|
||||
Conversation => :conversation,
|
||||
Like => :like,
|
||||
Message => :message,
|
||||
Participation => :participation,
|
||||
Photo => :photo,
|
||||
PollParticipation => :poll_participation,
|
||||
Profile => :profile,
|
||||
Reshare => :reshare,
|
||||
Retraction => :build_retraction,
|
||||
StatusMessage => :status_message
|
||||
}.freeze
|
||||
|
||||
ENTITY_MODELS = {
|
||||
"Comment" => Comment,
|
||||
"Conversation" => Conversation,
|
||||
"Like" => Like,
|
||||
"Participation" => Participation,
|
||||
"PollParticipation" => PollParticipation,
|
||||
"Photo" => Photo,
|
||||
"Poll" => Poll,
|
||||
"Post" => Post,
|
||||
# TODO: deprecated
|
||||
"Person" => Person,
|
||||
"Reshare" => Post,
|
||||
"StatusMessage" => Post
|
||||
}.freeze
|
||||
|
||||
ENTITY_NAMES = {
|
||||
Comment => "Comment",
|
||||
Like => "Like",
|
||||
Participation => "Participation",
|
||||
PollParticipation => "PollParticipation",
|
||||
Photo => "Photo",
|
||||
Post => "Post"
|
||||
}.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3,6 +3,10 @@ module Diaspora
|
|||
module Receive
|
||||
extend Diaspora::Logging
|
||||
|
||||
def self.perform(entity)
|
||||
public_send(Mappings.receiver_for(entity.class), entity)
|
||||
end
|
||||
|
||||
def self.account_deletion(entity)
|
||||
AccountDeletion.create!(person: author_of(entity), diaspora_handle: entity.author)
|
||||
end
|
||||
|
|
@ -49,7 +53,7 @@ module Diaspora
|
|||
author: author_of(entity),
|
||||
guid: entity.guid,
|
||||
positive: entity.positive,
|
||||
target: entity.parent_type.constantize.find_by(guid: entity.parent_guid)
|
||||
target: Mappings.model_class_for(entity.parent_type).find_by(guid: entity.parent_guid)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
@ -61,7 +65,7 @@ module Diaspora
|
|||
def self.participation(entity)
|
||||
author = author_of(entity)
|
||||
ignore_existing_guid(Participation, entity.guid, author) do
|
||||
parent = entity.parent_type.constantize.find_by(guid: entity.parent_guid)
|
||||
parent = Mappings.model_class_for(entity.parent_type).find_by(guid: entity.parent_guid)
|
||||
|
||||
Participation.create!(author: author, guid: entity.guid, target: parent) if parent.author.local?
|
||||
end
|
||||
|
|
@ -134,7 +138,8 @@ module Diaspora
|
|||
end
|
||||
|
||||
def self.retraction(entity, recipient_id)
|
||||
object = entity.target_type.constantize.where(guid: entity.target_guid).take!
|
||||
model_class = Diaspora::Federation::Mappings.model_class_for(entity.target_type)
|
||||
object = model_class.where(guid: entity.target_guid).take!
|
||||
|
||||
case object
|
||||
when Person
|
||||
|
|
|
|||
|
|
@ -346,38 +346,35 @@ describe "diaspora federation callbacks" do
|
|||
DiasporaFederation.callbacks.trigger(:receive_entity, retraction, 42)
|
||||
end
|
||||
|
||||
%i(comment contact conversation like message participation photo
|
||||
poll_participation profile reshare status_message).each do |entity|
|
||||
it "receives a #{entity}" do
|
||||
received = FactoryGirl.build("#{entity}_entity")
|
||||
persisted = FactoryGirl.create(entity)
|
||||
it "receives a entity" do
|
||||
received = FactoryGirl.build(:status_message_entity)
|
||||
persisted = FactoryGirl.create(:status_message)
|
||||
|
||||
expect(Diaspora::Federation::Receive).to receive(entity).with(received).and_return(persisted)
|
||||
expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(persisted)
|
||||
expect(Workers::ReceiveLocal).to receive(:perform_async).with(persisted.class.to_s, persisted.id, [])
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:receive_entity, received, nil)
|
||||
end
|
||||
|
||||
it "receives a #{entity} for a recipient" do
|
||||
received = FactoryGirl.build("#{entity}_entity")
|
||||
persisted = FactoryGirl.create(entity)
|
||||
it "receives a entity for a recipient" do
|
||||
received = FactoryGirl.build(:status_message_entity)
|
||||
persisted = FactoryGirl.create(:status_message)
|
||||
|
||||
expect(Diaspora::Federation::Receive).to receive(entity).with(received).and_return(persisted)
|
||||
expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(persisted)
|
||||
expect(Workers::ReceiveLocal).to receive(:perform_async).with(persisted.class.to_s, persisted.id, [42])
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:receive_entity, received, 42)
|
||||
end
|
||||
|
||||
it "does not trigger a ReceiveLocal job if Receive.#{entity} returned nil" do
|
||||
received = FactoryGirl.build("#{entity}_entity")
|
||||
it "does not trigger a ReceiveLocal job if Receive.perform returned nil" do
|
||||
received = FactoryGirl.build(:status_message_entity)
|
||||
|
||||
expect(Diaspora::Federation::Receive).to receive(entity).with(received).and_return(nil)
|
||||
expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(nil)
|
||||
expect(Workers::ReceiveLocal).not_to receive(:perform_async)
|
||||
|
||||
DiasporaFederation.callbacks.trigger(:receive_entity, received, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ":fetch_public_entity" do
|
||||
it "fetches a Post" do
|
||||
|
|
|
|||
|
|
@ -59,9 +59,10 @@ describe "attack vectors", type: :request do
|
|||
it "should not receive contact retractions from another person" do
|
||||
# we are banking on bob being friends with alice and eve
|
||||
# here, alice is trying to disconnect bob and eve
|
||||
expect(bob.contacts(true).find_by(person_id: eve.person.id)).to be_sharing
|
||||
contact = bob.contacts(true).find_by(person_id: eve.person.id)
|
||||
expect(contact).to be_sharing
|
||||
|
||||
post_message(generate_xml(Diaspora::Federation::Entities.retraction(eve.person), alice, bob), bob)
|
||||
post_message(generate_xml(Diaspora::Federation::Entities.retraction(contact), alice, bob), bob)
|
||||
|
||||
expect(bob.contacts(true).find_by(person_id: eve.person.id)).to be_sharing
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe Diaspora::Federation::Receive do
|
|||
let(:comment_entity) { FactoryGirl.build(:comment_entity, author: sender.diaspora_handle, parent_guid: post.guid) }
|
||||
|
||||
it "saves the comment" do
|
||||
received = Diaspora::Federation::Receive.comment(comment_entity)
|
||||
received = Diaspora::Federation::Receive.perform(comment_entity)
|
||||
|
||||
comment = Comment.find_by!(guid: comment_entity.guid)
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the comment to the post" do
|
||||
Diaspora::Federation::Receive.comment(comment_entity)
|
||||
Diaspora::Federation::Receive.perform(comment_entity)
|
||||
|
||||
comment = Comment.find_by!(guid: comment_entity.guid)
|
||||
|
||||
|
|
@ -40,9 +40,9 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
let(:entity) { comment_entity }
|
||||
it_behaves_like "it ignores existing object received twice", Comment, :comment
|
||||
it_behaves_like "it rejects if the parent author ignores the author", Comment, :comment
|
||||
it_behaves_like "it relays relayables", Comment, :comment
|
||||
it_behaves_like "it ignores existing object received twice", Comment
|
||||
it_behaves_like "it rejects if the parent author ignores the author", Comment
|
||||
it_behaves_like "it relays relayables", Comment
|
||||
end
|
||||
|
||||
describe ".contact" do
|
||||
|
|
@ -51,7 +51,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "creates the contact if it doesn't exist" do
|
||||
received = Diaspora::Federation::Receive.contact(contact_entity)
|
||||
received = Diaspora::Federation::Receive.perform(contact_entity)
|
||||
|
||||
contact = alice.contacts.find_by!(person_id: sender.id)
|
||||
|
||||
|
|
@ -62,7 +62,7 @@ describe Diaspora::Federation::Receive do
|
|||
it "updates the contact if it exists" do
|
||||
alice.contacts.find_or_initialize_by(person_id: sender.id, receiving: true, sharing: false).save!
|
||||
|
||||
received = Diaspora::Federation::Receive.contact(contact_entity)
|
||||
received = Diaspora::Federation::Receive.perform(contact_entity)
|
||||
|
||||
contact = alice.contacts.find_by!(person_id: sender.id)
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ describe Diaspora::Federation::Receive do
|
|||
|
||||
expect_any_instance_of(Contact).not_to receive(:save!)
|
||||
|
||||
expect(Diaspora::Federation::Receive.contact(contact_entity)).to be_nil
|
||||
expect(Diaspora::Federation::Receive.perform(contact_entity)).to be_nil
|
||||
end
|
||||
|
||||
context "sharing=false" do
|
||||
|
|
@ -91,7 +91,7 @@ describe Diaspora::Federation::Receive do
|
|||
it "disconnects, if currently connected" do
|
||||
alice.contacts.find_or_initialize_by(person_id: sender.id, receiving: true, sharing: true).save!
|
||||
|
||||
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
|
||||
received = Diaspora::Federation::Receive.perform(unshare_contact_entity)
|
||||
expect(received).to be_nil
|
||||
|
||||
contact = alice.contacts.find_by!(person_id: sender.id)
|
||||
|
|
@ -101,7 +101,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "does nothing, if already disconnected" do
|
||||
received = Diaspora::Federation::Receive.contact(unshare_contact_entity)
|
||||
received = Diaspora::Federation::Receive.perform(unshare_contact_entity)
|
||||
expect(received).to be_nil
|
||||
expect(alice.contacts.find_by(person_id: sender.id)).to be_nil
|
||||
end
|
||||
|
|
@ -129,7 +129,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the conversation" do
|
||||
received = Diaspora::Federation::Receive.conversation(conversation_entity)
|
||||
received = Diaspora::Federation::Receive.perform(conversation_entity)
|
||||
|
||||
conv = Conversation.find_by!(guid: conversation_entity.guid)
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "saves the message" do
|
||||
Diaspora::Federation::Receive.conversation(conversation_entity)
|
||||
Diaspora::Federation::Receive.perform(conversation_entity)
|
||||
|
||||
conv = Conversation.find_by!(guid: conversation_entity.guid)
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "creates appropriate visibilities" do
|
||||
Diaspora::Federation::Receive.conversation(conversation_entity)
|
||||
Diaspora::Federation::Receive.perform(conversation_entity)
|
||||
|
||||
conv = Conversation.find_by!(guid: conversation_entity.guid)
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ describe Diaspora::Federation::Receive do
|
|||
expect(conv.participants).to include(alice.person, bob.person)
|
||||
end
|
||||
|
||||
it_behaves_like "it ignores existing object received twice", Conversation, :conversation do
|
||||
it_behaves_like "it ignores existing object received twice", Conversation do
|
||||
let(:entity) { conversation_entity }
|
||||
end
|
||||
end
|
||||
|
|
@ -167,7 +167,7 @@ describe Diaspora::Federation::Receive do
|
|||
let(:like_entity) { FactoryGirl.build(:like_entity, author: sender.diaspora_handle, parent_guid: post.guid) }
|
||||
|
||||
it "saves the like" do
|
||||
received = Diaspora::Federation::Receive.like(like_entity)
|
||||
received = Diaspora::Federation::Receive.perform(like_entity)
|
||||
|
||||
like = Like.find_by!(guid: like_entity.guid)
|
||||
|
||||
|
|
@ -177,7 +177,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the like to the post" do
|
||||
Diaspora::Federation::Receive.like(like_entity)
|
||||
Diaspora::Federation::Receive.perform(like_entity)
|
||||
|
||||
like = Like.find_by!(guid: like_entity.guid)
|
||||
|
||||
|
|
@ -186,9 +186,9 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
let(:entity) { like_entity }
|
||||
it_behaves_like "it ignores existing object received twice", Like, :like
|
||||
it_behaves_like "it rejects if the parent author ignores the author", Like, :like
|
||||
it_behaves_like "it relays relayables", Like, :like
|
||||
it_behaves_like "it ignores existing object received twice", Like
|
||||
it_behaves_like "it rejects if the parent author ignores the author", Like
|
||||
it_behaves_like "it relays relayables", Like
|
||||
end
|
||||
|
||||
describe ".message" do
|
||||
|
|
@ -208,7 +208,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the message" do
|
||||
received = Diaspora::Federation::Receive.message(message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(message_entity)
|
||||
|
||||
msg = Message.find_by!(guid: message_entity.guid)
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the message to the conversation" do
|
||||
msg = Diaspora::Federation::Receive.message(message_entity)
|
||||
msg = Diaspora::Federation::Receive.perform(message_entity)
|
||||
|
||||
conv = Conversation.find_by!(guid: conversation.guid)
|
||||
|
||||
|
|
@ -228,8 +228,8 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
let(:entity) { message_entity }
|
||||
it_behaves_like "it ignores existing object received twice", Message, :message
|
||||
it_behaves_like "it relays relayables", Message, :message
|
||||
it_behaves_like "it ignores existing object received twice", Message
|
||||
it_behaves_like "it relays relayables", Message
|
||||
end
|
||||
|
||||
describe ".participation" do
|
||||
|
|
@ -238,7 +238,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the participation" do
|
||||
received = Diaspora::Federation::Receive.participation(participation_entity)
|
||||
received = Diaspora::Federation::Receive.perform(participation_entity)
|
||||
|
||||
participation = Participation.find_by!(guid: participation_entity.guid)
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the participation to the post" do
|
||||
Diaspora::Federation::Receive.participation(participation_entity)
|
||||
Diaspora::Federation::Receive.perform(participation_entity)
|
||||
|
||||
participation = Participation.find_by!(guid: participation_entity.guid)
|
||||
|
||||
|
|
@ -263,12 +263,12 @@ describe Diaspora::Federation::Receive do
|
|||
parent_guid: remote_post.guid
|
||||
)
|
||||
|
||||
expect(Diaspora::Federation::Receive.participation(remote_participation)).to be_nil
|
||||
expect(Diaspora::Federation::Receive.perform(remote_participation)).to be_nil
|
||||
|
||||
expect(Participation.exists?(guid: remote_participation.guid)).to be_falsey
|
||||
end
|
||||
|
||||
it_behaves_like "it ignores existing object received twice", Participation, :participation do
|
||||
it_behaves_like "it ignores existing object received twice", Participation do
|
||||
let(:entity) { participation_entity }
|
||||
end
|
||||
end
|
||||
|
|
@ -277,7 +277,7 @@ describe Diaspora::Federation::Receive do
|
|||
let(:photo_entity) { FactoryGirl.build(:photo_entity, author: sender.diaspora_handle) }
|
||||
|
||||
it "saves the photo if it does not already exist" do
|
||||
received = Diaspora::Federation::Receive.photo(photo_entity)
|
||||
received = Diaspora::Federation::Receive.perform(photo_entity)
|
||||
|
||||
photo = Photo.find_by!(guid: photo_entity.guid)
|
||||
|
||||
|
|
@ -288,13 +288,13 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "updates the photo if it is already persisted" do
|
||||
Diaspora::Federation::Receive.photo(photo_entity)
|
||||
Diaspora::Federation::Receive.perform(photo_entity)
|
||||
|
||||
photo = Photo.find_by!(guid: photo_entity.guid)
|
||||
photo.remote_photo_name = "foobar.jpg"
|
||||
photo.save
|
||||
|
||||
received = Diaspora::Federation::Receive.photo(photo_entity)
|
||||
received = Diaspora::Federation::Receive.perform(photo_entity)
|
||||
photo.reload
|
||||
|
||||
expect(received).to eq(photo)
|
||||
|
|
@ -303,7 +303,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "does not update the photo if the author mismatches" do
|
||||
Diaspora::Federation::Receive.photo(photo_entity)
|
||||
Diaspora::Federation::Receive.perform(photo_entity)
|
||||
|
||||
photo = Photo.find_by!(guid: photo_entity.guid)
|
||||
photo.remote_photo_name = "foobar.jpg"
|
||||
|
|
@ -311,7 +311,7 @@ describe Diaspora::Federation::Receive do
|
|||
photo.save
|
||||
|
||||
expect {
|
||||
Diaspora::Federation::Receive.photo(photo_entity)
|
||||
Diaspora::Federation::Receive.perform(photo_entity)
|
||||
}.to raise_error Diaspora::Federation::InvalidAuthor
|
||||
|
||||
photo.reload
|
||||
|
|
@ -333,7 +333,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the poll participation" do
|
||||
received = Diaspora::Federation::Receive.poll_participation(poll_participation_entity)
|
||||
received = Diaspora::Federation::Receive.perform(poll_participation_entity)
|
||||
|
||||
poll_participation = PollParticipation.find_by!(guid: poll_participation_entity.guid)
|
||||
|
||||
|
|
@ -343,7 +343,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the poll participation to the poll" do
|
||||
Diaspora::Federation::Receive.poll_participation(poll_participation_entity)
|
||||
Diaspora::Federation::Receive.perform(poll_participation_entity)
|
||||
|
||||
poll_participation = PollParticipation.find_by!(guid: poll_participation_entity.guid)
|
||||
|
||||
|
|
@ -352,16 +352,16 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
let(:entity) { poll_participation_entity }
|
||||
it_behaves_like "it ignores existing object received twice", PollParticipation, :poll_participation
|
||||
it_behaves_like "it rejects if the parent author ignores the author", PollParticipation, :poll_participation
|
||||
it_behaves_like "it relays relayables", PollParticipation, :poll_participation
|
||||
it_behaves_like "it ignores existing object received twice", PollParticipation
|
||||
it_behaves_like "it rejects if the parent author ignores the author", PollParticipation
|
||||
it_behaves_like "it relays relayables", PollParticipation
|
||||
end
|
||||
|
||||
describe ".profile" do
|
||||
let(:profile_entity) { FactoryGirl.build(:profile_entity, author: sender.diaspora_handle) }
|
||||
|
||||
it "updates the profile of the person" do
|
||||
received = Diaspora::Federation::Receive.profile(profile_entity)
|
||||
received = Diaspora::Federation::Receive.perform(profile_entity)
|
||||
|
||||
profile = Profile.find(sender.profile.id)
|
||||
|
||||
|
|
@ -381,7 +381,7 @@ describe Diaspora::Federation::Receive do
|
|||
let(:reshare_entity) { FactoryGirl.build(:reshare_entity, author: sender.diaspora_handle, root_guid: post.guid) }
|
||||
|
||||
it "saves the reshare" do
|
||||
received = Diaspora::Federation::Receive.reshare(reshare_entity)
|
||||
received = Diaspora::Federation::Receive.perform(reshare_entity)
|
||||
|
||||
reshare = Reshare.find_by!(guid: reshare_entity.guid)
|
||||
|
||||
|
|
@ -390,7 +390,7 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "attaches the reshare to the post" do
|
||||
Diaspora::Federation::Receive.reshare(reshare_entity)
|
||||
Diaspora::Federation::Receive.perform(reshare_entity)
|
||||
|
||||
reshare = Reshare.find_by!(guid: reshare_entity.guid)
|
||||
|
||||
|
|
@ -399,7 +399,7 @@ describe Diaspora::Federation::Receive do
|
|||
expect(reshare.created_at.iso8601).to eq(reshare_entity.created_at.iso8601)
|
||||
end
|
||||
|
||||
it_behaves_like "it ignores existing object received twice", Reshare, :reshare do
|
||||
it_behaves_like "it ignores existing object received twice", Reshare do
|
||||
let(:entity) { reshare_entity }
|
||||
end
|
||||
end
|
||||
|
|
@ -502,7 +502,7 @@ describe Diaspora::Federation::Receive do
|
|||
let(:status_message_entity) { FactoryGirl.build(:status_message_entity, author: sender.diaspora_handle) }
|
||||
|
||||
it "saves the status message" do
|
||||
received = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
status_message = StatusMessage.find_by!(guid: status_message_entity.guid)
|
||||
|
||||
|
|
@ -519,19 +519,19 @@ describe Diaspora::Federation::Receive do
|
|||
end
|
||||
|
||||
it "returns the status message if it already exists" do
|
||||
first = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
second = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
first = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
second = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
expect(second).not_to be_nil
|
||||
expect(first).to eq(second)
|
||||
end
|
||||
|
||||
it "does not change anything if the status message already exists" do
|
||||
Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
expect_any_instance_of(StatusMessage).not_to receive(:create_or_update)
|
||||
|
||||
Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -542,7 +542,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the status message" do
|
||||
received = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
status_message = StatusMessage.find_by!(guid: status_message_entity.guid)
|
||||
|
||||
|
|
@ -563,7 +563,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the status message" do
|
||||
received = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
status_message = StatusMessage.find_by!(guid: status_message_entity.guid)
|
||||
|
||||
|
|
@ -594,7 +594,7 @@ describe Diaspora::Federation::Receive do
|
|||
}
|
||||
|
||||
it "saves the status message and photos" do
|
||||
received = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
status_message = StatusMessage.find_by!(guid: status_message_entity.guid)
|
||||
|
||||
|
|
@ -609,7 +609,7 @@ describe Diaspora::Federation::Receive do
|
|||
received_photo.text = "foobar"
|
||||
received_photo.save!
|
||||
|
||||
received = Diaspora::Federation::Receive.status_message(status_message_entity)
|
||||
received = Diaspora::Federation::Receive.perform(status_message_entity)
|
||||
|
||||
status_message = StatusMessage.find_by!(guid: status_message_entity.guid)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
require "spec_helper"
|
||||
|
||||
shared_examples_for "it ignores existing object received twice" do |klass, method|
|
||||
shared_examples_for "it ignores existing object received twice" do |klass|
|
||||
it "return nil if the #{klass} already exists" do
|
||||
expect(Diaspora::Federation::Receive.public_send(method, entity)).not_to be_nil
|
||||
expect(Diaspora::Federation::Receive.public_send(method, entity)).to be_nil
|
||||
expect(Diaspora::Federation::Receive.public_send(:perform, entity)).not_to be_nil
|
||||
expect(Diaspora::Federation::Receive.public_send(:perform, entity)).to be_nil
|
||||
end
|
||||
|
||||
it "does not change anything if the #{klass} already exists" do
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
|
||||
expect_any_instance_of(klass).not_to receive(:create_or_update)
|
||||
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "it rejects if the parent author ignores the author" do |klass, method|
|
||||
shared_examples_for "it rejects if the parent author ignores the author" do |klass|
|
||||
it "saves the relayable if the author is not ignored" do
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
|
||||
expect(klass.find_by!(guid: entity.guid)).to be_instance_of(klass)
|
||||
end
|
||||
|
|
@ -29,7 +29,7 @@ shared_examples_for "it rejects if the parent author ignores the author" do |kla
|
|||
|
||||
it "raises an error and does not save the relayable" do
|
||||
expect {
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
}.to raise_error Diaspora::Federation::AuthorIgnored
|
||||
|
||||
expect(klass.find_by(guid: entity.guid)).to be_nil
|
||||
|
|
@ -47,13 +47,13 @@ shared_examples_for "it rejects if the parent author ignores the author" do |kla
|
|||
expect(dispatcher).to receive(:dispatch)
|
||||
|
||||
expect {
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
}.to raise_error Diaspora::Federation::AuthorIgnored
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples_for "it relays relayables" do |klass, method|
|
||||
shared_examples_for "it relays relayables" do |klass|
|
||||
it "dispatches the received relayable" do
|
||||
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) do |parent_author, relayable|
|
||||
expect(parent_author).to eq(alice)
|
||||
|
|
@ -61,6 +61,6 @@ shared_examples_for "it relays relayables" do |klass, method|
|
|||
expect(relayable.guid).to eq(entity.guid)
|
||||
end
|
||||
|
||||
Diaspora::Federation::Receive.public_send(method, entity)
|
||||
Diaspora::Federation::Receive.public_send(:perform, entity)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue