relay relayables after receive

also refactored relayable specs to use `let`
This commit is contained in:
Benjamin Neff 2016-06-15 00:38:29 +02:00
parent 91c6c74ca0
commit b39f3ccc74
14 changed files with 192 additions and 214 deletions

View file

@ -51,11 +51,12 @@ module Diaspora
def self.comment(comment)
DiasporaFederation::Entities::Comment.new(
author: comment.diaspora_handle,
guid: comment.guid,
parent_guid: comment.post.guid,
text: comment.text,
parent: related_entity(comment.post)
author: comment.diaspora_handle,
guid: comment.guid,
parent_guid: comment.post.guid,
text: comment.text,
author_signature: comment.author_signature,
parent: related_entity(comment.post)
)
end
@ -80,12 +81,13 @@ module Diaspora
def self.like(like)
DiasporaFederation::Entities::Like.new(
author: like.diaspora_handle,
guid: like.guid,
parent_guid: like.target.guid,
positive: like.positive,
parent_type: like.target.class.base_class.to_s,
parent: related_entity(like.target)
author: like.diaspora_handle,
guid: like.guid,
parent_guid: like.target.guid,
positive: like.positive,
parent_type: like.target.class.base_class.to_s,
author_signature: like.author_signature,
parent: related_entity(like.target)
)
end
@ -105,6 +107,7 @@ module Diaspora
created_at: message.created_at,
parent_guid: message.conversation.guid,
conversation_guid: message.conversation.guid,
author_signature: message.author_signature,
parent: related_entity(message.conversation)
)
end
@ -155,6 +158,7 @@ module Diaspora
guid: poll_participation.guid,
parent_guid: poll_participation.poll.guid,
poll_answer_guid: poll_participation.poll_answer.guid,
author_signature: poll_participation.author_signature,
parent: related_entity(poll_participation.poll)
)
end

View file

@ -8,15 +8,14 @@ module Diaspora
end
def self.comment(entity)
author = author_of(entity)
ignore_existing_guid(Comment, entity.guid, author) do
receive_relayable(Comment, entity) do
Comment.new(
author: author,
author: author_of(entity),
guid: entity.guid,
created_at: entity.created_at,
text: entity.text,
commentable: Post.find_by(guid: entity.parent_guid)
).tap {|comment| save_relayable(comment, entity) }
)
end
end
@ -40,21 +39,18 @@ module Diaspora
end
def self.like(entity)
author = author_of(entity)
ignore_existing_guid(Like, entity.guid, author) do
receive_relayable(Like, entity) do
Like.new(
author: author,
author: author_of(entity),
guid: entity.guid,
positive: entity.positive,
target: entity.parent_type.constantize.find_by(guid: entity.parent_guid)
).tap {|like| save_relayable(like, entity) }
)
end
end
def self.message(entity)
ignore_existing_guid(Message, entity.guid, author_of(entity)) do
build_message(entity).tap(&:save!)
end
save_message(entity).tap {|message| relay_relayable(message) if message }
end
def self.participation(entity)
@ -89,14 +85,13 @@ module Diaspora
end
def self.poll_participation(entity)
author = author_of(entity)
ignore_existing_guid(PollParticipation, entity.guid, author) do
receive_relayable(PollParticipation, entity) do
PollParticipation.new(
author: author,
author: author_of(entity),
guid: entity.guid,
poll: Poll.find_by(guid: entity.parent_guid),
poll_answer_guid: entity.poll_answer_guid
).tap {|poll_participation| save_relayable(poll_participation, entity) }
)
end
end
@ -201,6 +196,16 @@ module Diaspora
end
private_class_method :build_poll
def self.save_message(entity)
ignore_existing_guid(Message, entity.guid, author_of(entity)) do
build_message(entity).tap do |message|
message.author_signature = entity.author_signature if message.conversation.author.local?
message.save!
end
end
end
private_class_method :save_message
def self.save_photo(entity)
Photo.create!(
author: author_of(entity),
@ -217,11 +222,20 @@ module Diaspora
end
private_class_method :save_photo
def self.save_relayable(relayable, entity)
retract_if_author_ignored(relayable)
def self.receive_relayable(klass, entity)
save_relayable(klass, entity) { yield }.tap {|relayable| relay_relayable(relayable) if relayable }
end
private_class_method :receive_relayable
relayable.author_signature = entity.author_signature if relayable.parent.author.local?
relayable.save!
def self.save_relayable(klass, entity)
ignore_existing_guid(klass, entity.guid, author_of(entity)) do
yield.tap do |relayable|
retract_if_author_ignored(relayable)
relayable.author_signature = entity.author_signature if relayable.parent.author.local?
relayable.save!
end
end
end
private_class_method :save_relayable
@ -255,6 +269,12 @@ module Diaspora
end
private_class_method :retract_if_author_ignored
def self.relay_relayable(relayable)
parent_author = relayable.parent.author.owner
Diaspora::Federation::Dispatcher.defer_dispatch(parent_author, relayable) if parent_author
end
private_class_method :relay_relayable
# check if the object already exists, otherwise save it.
# if save fails (probably because of a second object received parallel),
# check again if an object with the same guid already exists, but maybe has a different author.

View file

@ -31,9 +31,13 @@ module Diaspora
# @return [Array<Person>]
def subscribers
if parent.author.local?
parent.subscribers
if author.local?
parent.subscribers
else
parent.subscribers.select(&:remote?)
end
else
[parent.author]
[parent.author, author]
end
end

View file

@ -33,12 +33,13 @@ end
def create_relayable_entity(entity_name, parent, diaspora_id)
expect(DiasporaFederation.callbacks).to receive(:trigger).with(
:fetch_private_key, alice.diaspora_handle
).and_return(nil) if parent == local_parent
).at_least(1).times.and_return(nil) if parent == local_parent
parent_guid = parent.guid
FactoryGirl.build(
entity_name,
conversation_guid: parent.guid,
parent_guid: parent.guid,
conversation_guid: parent_guid,
parent_guid: parent_guid,
author: diaspora_id,
poll_answer_guid: parent.respond_to?(:poll_answers) ? parent.poll_answers.first.guid : nil,
parent: Diaspora::Federation::Entities.related_entity(parent)

View file

@ -11,7 +11,7 @@ describe Diaspora::Federation::Entities do
end
it "builds a comment" do
diaspora_entity = FactoryGirl.build(:comment)
diaspora_entity = FactoryGirl.build(:comment, author_signature: "abc")
federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Comment)
@ -19,6 +19,7 @@ describe Diaspora::Federation::Entities do
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.author_signature)
end
it "builds a contact (request)" do
@ -60,7 +61,7 @@ describe Diaspora::Federation::Entities do
end
it "builds a like" do
diaspora_entity = FactoryGirl.build(:like)
diaspora_entity = FactoryGirl.build(:like, author_signature: "abc")
federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Like)
@ -68,10 +69,11 @@ describe Diaspora::Federation::Entities do
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.author_signature)
end
it "builds a message" do
diaspora_entity = FactoryGirl.create(:message)
diaspora_entity = FactoryGirl.create(:message, author_signature: "abc")
federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::Message)
@ -80,6 +82,7 @@ describe Diaspora::Federation::Entities do
expect(federation_entity.conversation_guid).to eq(diaspora_entity.conversation.guid)
expect(federation_entity.text).to eq(diaspora_entity.text)
expect(federation_entity.created_at).to eq(diaspora_entity.created_at)
expect(federation_entity.author_signature).to eq(diaspora_entity.author_signature)
end
it "builds a participation" do
@ -110,7 +113,7 @@ describe Diaspora::Federation::Entities do
end
it "builds a poll participation" do
diaspora_entity = FactoryGirl.build(:poll_participation)
diaspora_entity = FactoryGirl.build(:poll_participation, author_signature: "abc")
federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)
@ -118,6 +121,7 @@ describe Diaspora::Federation::Entities do
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(diaspora_entity.author_signature)
end
it "builds a profile" do

View file

@ -42,6 +42,7 @@ describe Diaspora::Federation::Receive do
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
end
describe ".contact" do
@ -158,6 +159,7 @@ describe Diaspora::Federation::Receive do
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
end
describe ".message" do
@ -196,9 +198,9 @@ describe Diaspora::Federation::Receive do
expect(msg.conversation).to eq(conv)
end
it_behaves_like "it ignores existing object received twice", Message, :message do
let(:entity) { message_entity }
end
let(:entity) { message_entity }
it_behaves_like "it ignores existing object received twice", Message, :message
it_behaves_like "it relays relayables", Message, :message
end
describe ".participation" do
@ -323,6 +325,7 @@ describe Diaspora::Federation::Receive do
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
end
describe ".profile" do

View file

@ -3,9 +3,8 @@
# the COPYRIGHT file.
require "spec_helper"
require Rails.root.join("spec", "shared_behaviors", "relayable")
describe Comment, :type => :model do
describe Comment, type: :model do
let(:alices_aspect) { alice.aspects.first }
let(:status_bob) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
let(:comment_alice) { alice.comment!(status_bob, "why so formal?") }
@ -67,25 +66,13 @@ describe Comment, :type => :model do
end
end
describe "it is relayable" do
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(:object_by_parent_author) { local_luke.comment!(local_parent, "yo!") }
let(:object_by_recipient) { local_leia.build_comment(text: "yo", post: local_parent) }
let(:dup_object_by_parent_author) { object_by_parent_author.dup }
it_behaves_like "it is relayable" do
let(:remote_parent) { FactoryGirl.create(:status_message, author: remote_raphael) }
let(:local_parent) { local_luke.post(:status_message, text: "hi", to: local_luke.aspects.first) }
let(:object_on_local_parent) { local_luke.comment!(local_parent, "yo!") }
let(:object_on_remote_parent) { local_luke.comment!(remote_parent, "Yeah, it was great") }
before do
# shared_behaviors/relayable.rb is still using instance variables, so we need to define them here.
# Suggestion: refactor all specs using shared_behaviors/relayable.rb to use "let"
@object_by_parent_author = object_by_parent_author
@object_by_recipient = object_by_recipient
@dup_object_by_parent_author = dup_object_by_parent_author
@object_on_remote_parent = object_on_remote_parent
end
let(:remote_object_on_local_parent) { FactoryGirl.create(:comment, post: local_parent, author: remote_raphael) }
let(:relayable) { Comment::Generator.new(alice, status_bob, "why so formal?").build }
it_should_behave_like "it is relayable"
end
describe "tags" do

View file

@ -2,21 +2,18 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require Rails.root.join("spec", "shared_behaviors", "relayable")
require "spec_helper"
describe Like, :type => :model do
before do
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
end
describe Like, type: :model do
let(:status) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
it 'has a valid factory' do
it "has a valid factory" do
expect(FactoryGirl.build(:like)).to be_valid
end
describe "#destroy" do
before do
@like = alice.like!(@status)
@like = alice.like!(status)
end
it "should delete a participation" do
@ -24,42 +21,34 @@ describe Like, :type => :model do
end
it "should decrease count participation" do
alice.comment!(@status, "Are you there?")
alice.comment!(status, "Are you there?")
@like.destroy
participations = Participation.where(target_id: @like.target_id, author_id: @like.author_id)
expect(participations.first.count).to eq(1)
end
end
describe 'counter cache' do
it 'increments the counter cache on its post' do
describe "counter cache" do
it "increments the counter cache on its post" do
expect {
alice.like!(@status)
}.to change{ @status.reload.likes_count }.by(1)
alice.like!(status)
}.to change { status.reload.likes_count }.by(1)
end
it 'increments the counter cache on its comment' do
comment = FactoryGirl.create(:comment, :post => @status)
it "increments the counter cache on its comment" do
comment = FactoryGirl.create(:comment, post: status)
expect {
alice.like!(comment)
}.to change{ comment.reload.likes_count }.by(1)
}.to change { comment.reload.likes_count }.by(1)
end
end
describe 'it is relayable' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.like!(@local_parent)
@object_by_recipient = @local_leia.like!(@local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.like!(@remote_parent)
end
let(:relayable) { Like::Generator.new(alice, @status).build }
it_should_behave_like "it is relayable"
it_behaves_like "it is relayable" do
let(:remote_parent) { FactoryGirl.create(:status_message, author: remote_raphael) }
let(:local_parent) { local_luke.post(:status_message, text: "hi", to: local_luke.aspects.first) }
let(:object_on_local_parent) { local_luke.like!(local_parent) }
let(:object_on_remote_parent) { local_luke.like!(remote_parent) }
let(:remote_object_on_local_parent) { FactoryGirl.create(:like, target: local_parent, author: remote_raphael) }
let(:relayable) { Like::Generator.new(alice, status).build }
end
end

View file

@ -2,70 +2,50 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require Rails.root.join("spec", "shared_behaviors", "relayable")
require "spec_helper"
describe Message, :type => :model do
before do
@create_hash = {
:author => bob.person,
:participant_ids => [bob.person.id, alice.person.id],
:subject => "cool stuff",
:messages_attributes => [ {:author => bob.person, :text => 'stuff'} ]
describe Message, type: :model do
let(:create_hash) {
{
author: bob.person,
participant_ids: [bob.person.id, alice.person.id],
subject: "cool stuff",
messages_attributes: [{author: bob.person, text: "stuff"}]
}
}
let(:conversation) { Conversation.create!(create_hash) }
let(:message) { conversation.messages.first }
@conversation = Conversation.create!(@create_hash)
@message = @conversation.messages.first
end
it 'validates that the author is a participant in the conversation' do
message = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @conversation.id)
it "validates that the author is a participant in the conversation" do
message = Message.new(text: "yo", author: eve.person, conversation_id: conversation.id)
expect(message).not_to be_valid
end
describe 'it is relayable' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
cnv_hash = {
:author => @remote_raphael,
:participant_ids => [@local_luke.person, @local_leia.person, @remote_raphael].map(&:id),
:subject => 'cool story, bro',
:messages_attributes => [ {:author => @remote_raphael, :text => 'hey'} ]
it_behaves_like "it is relayable" do
let(:cnv_hash) {
{
participant_ids: [local_luke.person, local_leia.person, remote_raphael].map(&:id),
subject: "cool story, bro",
messages_attributes: [{author: remote_raphael, text: "hey"}]
}
}
let(:remote_parent) { Conversation.create(cnv_hash.merge(author: remote_raphael)) }
let(:local_parent) { Conversation.create(cnv_hash.merge(author: local_luke.person)) }
let(:object_on_local_parent) { Message.create(author: local_luke.person, text: "yo", conversation: local_parent) }
let(:object_on_remote_parent) { Message.create(author: local_luke.person, text: "yo", conversation: remote_parent) }
let(:remote_object_on_local_parent) {
Message.create(author: remote_raphael, text: "yo", conversation: local_parent)
}
let(:relayable) { Message.new(author: alice.person, text: "ohai!", conversation: conversation) }
end
@remote_parent = Conversation.create(cnv_hash.dup)
describe "#increase_unread" do
it "increments the conversation visibility for the conversation" do
conf = ConversationVisibility.find_by(conversation_id: conversation.id, person_id: alice.person.id)
expect(conf.unread).to eq(0)
cnv_hash[:author] = @local_luke.person
@local_parent = Conversation.create(cnv_hash)
msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent}
@object_by_parent_author = Message.create(msg_hash.dup)
Diaspora::Federation::Dispatcher.build(@local_luke, @object_by_parent_author).dispatch
msg_hash[:author] = @local_leia.person
@object_by_recipient = Message.create(msg_hash.dup)
@dup_object_by_parent_author = @object_by_parent_author.dup
msg_hash[:author] = @local_luke.person
msg_hash[:conversation] = @remote_parent
@object_on_remote_parent = Message.create(msg_hash)
Diaspora::Federation::Dispatcher.build(@local_luke, @object_on_remote_parent).dispatch
end
let(:relayable) { Message.new(author: @alice.person, text: "ohai!", conversation: @conversation) }
it_should_behave_like "it is relayable"
describe '#increase_unread' do
it 'increments the conversation visiblity for the conversation' do
expect(ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id,
:person_id => @local_luke.person.id).first.unread).to eq(0)
@object_by_recipient.increase_unread(@local_luke)
expect(ConversationVisibility.where(:conversation_id => @object_by_recipient.reload.conversation.id,
:person_id => @local_luke.person.id).first.unread).to eq(1)
end
message.increase_unread(alice)
expect(conf.reload.unread).to eq(1)
end
end
end

View file

@ -1,29 +1,22 @@
require "spec_helper"
describe Participation, :type => :model do
describe 'it is relayable' do
before do
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
describe Participation, type: :model do
let(:status) { bob.post(:status_message, text: "hello", to: bob.aspects.first.id) }
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.create(:status_message, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "foobar", :to => @local_luke.aspects.first
@object_by_parent_author = @local_luke.participate!(@local_parent)
@object_by_recipient = @local_leia.participate!(@local_parent)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.participate!(@remote_parent)
end
let(:relayable) { Participation::Generator.new(alice, @status).build }
it_should_behave_like "it is relayable"
it_behaves_like "it is relayable" do
let(:remote_parent) { FactoryGirl.create(:status_message, author: remote_raphael) }
let(:local_parent) { local_luke.post(:status_message, text: "hi", to: local_luke.aspects.first) }
let(:object_on_local_parent) { local_luke.participate!(local_parent) }
let(:object_on_remote_parent) { local_luke.participate!(remote_parent) }
let(:remote_object_on_local_parent) {
FactoryGirl.create(:participation, target: local_parent, author: remote_raphael)
}
let(:relayable) { Participation::Generator.new(alice, status).build }
end
describe "#unparticipate" do
before do
@status = bob.post(:status_message, text: "hello", to: bob.aspects.first.id)
@like = alice.like!(@status)
@like = alice.like!(status)
end
it "retract participation" do
@ -33,7 +26,7 @@ describe Participation, :type => :model do
end
it "retract one of multiple participations" do
comment = alice.comment!(@status, "bro")
comment = alice.comment!(status, "bro")
comment.author.participations.first.unparticipate!
participations = Participation.where(target_id: @like.target_id, author_id: @like.author_id)
expect(participations.count).to eq(1)
@ -41,7 +34,7 @@ describe Participation, :type => :model do
end
it "retract all of multiple participations" do
alice.comment!(@status, "bro")
alice.comment!(status, "bro")
alice.participations.first.unparticipate!
alice.participations.first.unparticipate!
expect(Participation.where(target_id: @like.target_id, author_id: @like.author_id).count).to eq(0)

View file

@ -1,7 +1,6 @@
require 'spec_helper'
require Rails.root.join("spec", "shared_behaviors", "relayable")
require "spec_helper"
describe PollParticipation, :type => :model do
describe PollParticipation, type: :model do
before do
@alices_aspect = alice.aspects.first
@status = bob.post(:status_message, :text => "hello", :to => bob.aspects.first.id)
@ -27,25 +26,20 @@ describe PollParticipation, :type => :model do
end
end
describe 'it is relayable' do
before do
@local_luke, @local_leia, @remote_raphael = set_up_friends
@remote_parent = FactoryGirl.build(:status_message_with_poll, :author => @remote_raphael)
@local_parent = @local_luke.post :status_message, :text => "hi", :to => @local_luke.aspects.first
@poll2 = Poll.new(:question => 'Who is now in charge?')
@poll2.poll_answers.build(:answer => "a")
@poll2.poll_answers.build(:answer => "b")
@local_parent.poll = @poll2
@object_by_parent_author = @local_luke.participate_in_poll!(@local_parent, @poll2.poll_answers.first)
@object_by_recipient = @local_leia.participate_in_poll!(@local_parent, @poll2.poll_answers.first)
@dup_object_by_parent_author = @object_by_parent_author.dup
@object_on_remote_parent = @local_luke.participate_in_poll!(@remote_parent, @remote_parent.poll.poll_answers.first)
end
let(:relayable) { PollParticipation::Generator.new(alice, @status, @poll.poll_answers.first).build }
it_should_behave_like "it is relayable"
it_behaves_like "it is relayable" do
let(:remote_parent) { FactoryGirl.create(:status_message_with_poll, author: remote_raphael) }
let(:local_parent) {
FactoryGirl.create(:status_message_with_poll, author: local_luke.person).tap do |status_message|
local_luke.add_to_streams(status_message, [local_luke.aspects.first])
end
}
let(:object_on_local_parent) { local_luke.participate_in_poll!(local_parent, local_parent.poll.poll_answers.first) }
let(:object_on_remote_parent) {
local_luke.participate_in_poll!(remote_parent, remote_parent.poll.poll_answers.first)
}
let(:remote_object_on_local_parent) {
FactoryGirl.create(:poll_participation, poll_answer: local_parent.poll.poll_answers.first, author: remote_raphael)
}
let(:relayable) { PollParticipation::Generator.new(alice, @status, @poll.poll_answers.first).build }
end
end

View file

@ -52,3 +52,15 @@ shared_examples_for "it rejects if the parent author ignores the author" do |kla
end
end
end
shared_examples_for "it relays relayables" do |klass, method|
it "dispatches the received relayable" do
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch) do |parent_author, relayable|
expect(parent_author).to eq(alice)
expect(relayable).to be_instance_of(klass)
expect(relayable.guid).to eq(entity.guid)
end
Diaspora::Federation::Receive.public_send(method, entity)
end
end

View file

@ -44,28 +44,19 @@ shared_examples_for "it is relayable" do
end
end
context 'propagation' do
describe '#receive' do
it 'dispatches when the person receiving is the parent author' do
skip # TODO
p = Postzord::Dispatcher.build(@local_luke, @object_by_recipient)
expect(p).to receive(:post)
allow(p.class).to receive(:new).and_return(p)
@object_by_recipient.receive(@local_luke, @local_leia.person)
end
describe "#subscribers" do
it "returns the parents original audience, if the parent is local" do
expect(object_on_local_parent.subscribers.map(&:id))
.to match_array([local_leia.person, remote_raphael].map(&:id))
end
describe '#subscribers' do
it 'returns the posts original audience, if the post is owned by the user' do
expect(@object_by_parent_author.subscribers.map(&:id))
.to match_array([@local_leia.person, @remote_raphael].map(&:id))
end
it "returns remote persons of the parents original audience, if the parent is local, but the author is remote" do
expect(remote_object_on_local_parent.subscribers.map(&:id)).to match_array([remote_raphael].map(&:id))
end
it 'returns the owner of the original post, if the user owns the object' do
skip # TODO
expect(@object_by_recipient.subscribers.map(&:id)).to match_array([@local_luke.person].map(&:id))
end
it "returns the author of parent and author of relayable (for local delivery), if the parent is not local" do
expect(object_on_remote_parent.subscribers.map(&:id))
.to match_array([remote_raphael, local_luke.person].map(&:id))
end
end
end

View file

@ -23,10 +23,6 @@ UnprocessedImage.enable_processing = false
Rails.application.routes.default_url_options[:host] = AppConfig.pod_uri.host
Rails.application.routes.default_url_options[:port] = AppConfig.pod_uri.port
def set_up_friends
[local_luke, local_leia, remote_raphael]
end
def alice
@alice ||= User.find_by(username: "alice")
end