diff --git a/spec/factories.rb b/spec/factories.rb index f0f645799..817ed4b2c 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -21,6 +21,7 @@ FactoryGirl.define do gender "robot" location "Earth" birthday Date.today + association :person end factory :profile_with_image_url, :parent => :profile do @@ -70,7 +71,6 @@ FactoryGirl.define do serialized_private_key OpenSSL::PKey::RSA.generate(1024).export after(:build) do |u| u.person = FactoryGirl.build(:person, - profile: FactoryGirl.build(:profile), pod: nil, serialized_public_key: u.encryption_key.public_key.export, diaspora_handle: "#{u.username}#{User.diaspora_id_host}") @@ -149,16 +149,29 @@ FactoryGirl.define do lng 13.409779 end + factory :participation do + association :author, factory: :person + association :target, factory: :status_message + end + factory(:poll) do - sequence(:question) { |n| "What do you think about #{n} ninjas?" } + sequence(:question) {|n| "What do you think about #{n} ninjas?" } + association :status_message after(:build) do |p| - p.poll_answers << FactoryGirl.build(:poll_answer) - p.poll_answers << FactoryGirl.build(:poll_answer) + p.poll_answers << FactoryGirl.build(:poll_answer, poll: p) + p.poll_answers << FactoryGirl.build(:poll_answer, poll: p) end end factory(:poll_answer) do - sequence(:answer) { |n| "#{n} questionmarks" } + sequence(:answer) {|n| "#{n} questionmarks" } + association :poll + end + + factory :poll_participation do + association :author, factory: :person + association :poll_answer + after(:build) {|p| p.poll = p.poll_answer.poll } end factory(:photo) do @@ -286,8 +299,10 @@ FactoryGirl.define do end factory(:message) do - association(:author, factory: :person) - sequence(:text) { |n| "message text ##{n}" } + association :author, factory: :person + association :conversation + sequence(:text) {|n| "message text ##{n}" } + after(:build) {|m| m.conversation.participants << m.author } end factory(:message_with_conversation, parent: :message) do diff --git a/spec/federation_callbacks_spec.rb b/spec/federation_callbacks_spec.rb index 4ea7fb9b0..094a7edce 100644 --- a/spec/federation_callbacks_spec.rb +++ b/spec/federation_callbacks_spec.rb @@ -109,7 +109,8 @@ describe "diaspora federation callbacks" do FactoryGirl.attributes_for( :federation_person_from_webfinger, profile: DiasporaFederation::Entities::Profile.new( - FactoryGirl.attributes_for(:federation_profile_from_hcard_with_image_url)) + FactoryGirl.attributes_for(:federation_profile_from_hcard_with_image_url) + ) ) ) @@ -326,6 +327,58 @@ describe "diaspora federation callbacks" do end end + describe ":receive_entity" do + it "receives an AccountDeletion" do + account_deletion = FactoryGirl.build(:account_deletion_entity) + + expect(Diaspora::Federation::Receive).to receive(:account_deletion).with(account_deletion) + expect(Workers::ReceiveLocal).not_to receive(:perform_async) + + DiasporaFederation.callbacks.trigger(:receive_entity, account_deletion, nil) + end + + it "receives a Retraction" do + retraction = FactoryGirl.build(:retraction_entity) + + expect(Diaspora::Federation::Receive).to receive(:retraction).with(retraction, 42) + expect(Workers::ReceiveLocal).not_to receive(:perform_async) + + 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) + + expect(Diaspora::Federation::Receive).to receive(entity).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) + + expect(Diaspora::Federation::Receive).to receive(entity).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") + + expect(Diaspora::Federation::Receive).to receive(entity).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 post = FactoryGirl.create(:status_message, author: alice.person, public: true)