From 78c7156e722b0453e70d56ab18305a32bfa8f6f5 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Tue, 25 Apr 2017 01:10:03 +0200 Subject: [PATCH] Replace FactoryGirl with Fabricate for federation factories --- spec/factories.rb | 3 +- spec/federation_callbacks_spec.rb | 20 +++--- spec/helper_methods.rb | 2 +- .../federation/federation_helper.rb | 2 +- .../receive_federation_messages_spec.rb | 12 ++-- .../federation/shared_receive_retraction.rb | 2 +- .../federation/shared_receive_stream_items.rb | 4 +- spec/integration/mentioning_spec.rb | 2 +- spec/lib/diaspora/federation/receive_spec.rb | 61 +++++++++---------- .../notifications/private_message_spec.rb | 2 +- 10 files changed, 52 insertions(+), 58 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index d89eb7d95..e6ce43525 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -10,8 +10,7 @@ def r_str SecureRandom.hex(3) end -require "diaspora_federation/test" -DiasporaFederation::Test::Factories.federation_factories +require "diaspora_federation/test/factories" FactoryGirl.define do factory :profile do diff --git a/spec/federation_callbacks_spec.rb b/spec/federation_callbacks_spec.rb index 253484ded..df72b7b78 100644 --- a/spec/federation_callbacks_spec.rb +++ b/spec/federation_callbacks_spec.rb @@ -203,7 +203,7 @@ describe "diaspora federation callbacks" do it "returns nil for an unknown id" do expect( - DiasporaFederation.callbacks.trigger(:fetch_private_key, FactoryGirl.generate(:diaspora_id)) + DiasporaFederation.callbacks.trigger(:fetch_private_key, Fabricate.sequence(:diaspora_id)) ).to be_nil end end @@ -225,7 +225,7 @@ describe "diaspora federation callbacks" do end it "returns nil for an unknown person" do - diaspora_id = FactoryGirl.generate(:diaspora_id) + diaspora_id = Fabricate.sequence(:diaspora_id) expect(Person).to receive(:find_or_fetch_by_identifier).with(diaspora_id) .and_raise(DiasporaFederation::Discovery::DiscoveryError) @@ -295,7 +295,7 @@ describe "diaspora federation callbacks" do it "returns nil for a non-existing guid" do expect( - DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", FactoryGirl.generate(:guid)) + DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Post", Fabricate.sequence(:guid)) ).to be_nil end end @@ -337,7 +337,7 @@ describe "diaspora federation callbacks" do describe ":receive_entity" do it "receives an AccountDeletion" do - account_deletion = FactoryGirl.build(:account_deletion_entity, author: remote_person.diaspora_handle) + account_deletion = Fabricate(:account_deletion_entity, author: remote_person.diaspora_handle) expect(Diaspora::Federation::Receive).to receive(:account_deletion).with(account_deletion) expect(Workers::ReceiveLocal).not_to receive(:perform_async) @@ -346,7 +346,7 @@ describe "diaspora federation callbacks" do end it "receives a Retraction" do - retraction = FactoryGirl.build(:retraction_entity, author: remote_person.diaspora_handle) + retraction = Fabricate(:retraction_entity, author: remote_person.diaspora_handle) expect(Diaspora::Federation::Receive).to receive(:retraction).with(retraction, 42) expect(Workers::ReceiveLocal).not_to receive(:perform_async) @@ -355,7 +355,7 @@ describe "diaspora federation callbacks" do end it "receives a entity" do - received = FactoryGirl.build(:status_message_entity, author: remote_person.diaspora_handle) + received = Fabricate(:status_message_entity, author: remote_person.diaspora_handle) persisted = FactoryGirl.create(:status_message) expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(persisted) @@ -365,7 +365,7 @@ describe "diaspora federation callbacks" do end it "calls schedule_check_if_needed on the senders pod" do - received = FactoryGirl.build(:status_message_entity, author: remote_person.diaspora_handle) + received = Fabricate(:status_message_entity, author: remote_person.diaspora_handle) persisted = FactoryGirl.create(:status_message) expect(Person).to receive(:by_account_identifier).with(received.author).and_return(remote_person) @@ -377,7 +377,7 @@ describe "diaspora federation callbacks" do end it "receives a entity for a recipient" do - received = FactoryGirl.build(:status_message_entity, author: remote_person.diaspora_handle) + received = Fabricate(:status_message_entity, author: remote_person.diaspora_handle) persisted = FactoryGirl.create(:status_message) expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(persisted) @@ -387,7 +387,7 @@ describe "diaspora federation callbacks" do end it "does not trigger a ReceiveLocal job if Receive.perform returned nil" do - received = FactoryGirl.build(:status_message_entity, author: remote_person.diaspora_handle) + received = Fabricate(:status_message_entity, author: remote_person.diaspora_handle) expect(Diaspora::Federation::Receive).to receive(:perform).with(received).and_return(nil) expect(Workers::ReceiveLocal).not_to receive(:perform_async) @@ -460,7 +460,7 @@ describe "diaspora federation callbacks" do end it "forwards the DiscoveryError" do - diaspora_id = FactoryGirl.generate(:diaspora_id) + diaspora_id = Fabricate.sequence(:diaspora_id) expect(Person).to receive(:find_or_fetch_by_identifier).with(diaspora_id) .and_raise(DiasporaFederation::Discovery::DiscoveryError) diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index c1992dc82..c23ee2440 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -52,7 +52,7 @@ module HelperMethods end def build_relayable_federation_entity(type, data={}, additional_xml_elements={}) - attributes = FactoryGirl.attributes_for("#{type}_entity".to_sym, data) + attributes = Fabricate.attributes_for("#{type}_entity".to_sym, data) entity_class = "DiasporaFederation::Entities::#{type.capitalize}".constantize signable_fields = attributes.keys - [:author_signature] diff --git a/spec/integration/federation/federation_helper.rb b/spec/integration/federation/federation_helper.rb index afc880792..56e8a86f9 100644 --- a/spec/integration/federation/federation_helper.rb +++ b/spec/integration/federation/federation_helper.rb @@ -36,7 +36,7 @@ def create_relayable_entity(entity_name, parent, diaspora_id) ).at_least(1).times.and_return(nil) if parent == local_parent parent_guid = parent.guid - FactoryGirl.build( + Fabricate( entity_name, conversation_guid: parent_guid, parent_guid: parent_guid, diff --git a/spec/integration/federation/receive_federation_messages_spec.rb b/spec/integration/federation/receive_federation_messages_spec.rb index 85a2b142d..d16676468 100644 --- a/spec/integration/federation/receive_federation_messages_spec.rb +++ b/spec/integration/federation/receive_federation_messages_spec.rb @@ -21,7 +21,7 @@ describe "Receive federation messages feature" do end it "rejects account deletion with wrong diaspora_id" do - delete_id = FactoryGirl.generate(:diaspora_id) + delete_id = Fabricate.sequence(:diaspora_id) post_message(generate_xml(DiasporaFederation::Entities::AccountDeletion.new(diaspora_id: delete_id), sender)) expect(AccountDeletion.exists?(diaspora_handle: delete_id)).to be_falsey @@ -31,7 +31,7 @@ describe "Receive federation messages feature" do context "reshare" do it "reshare of public post passes" do post = FactoryGirl.create(:status_message, author: alice.person, public: true) - reshare = FactoryGirl.build( + reshare = Fabricate( :reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id) expect(Participation::Generator).to receive(:new).with( @@ -46,7 +46,7 @@ describe "Receive federation messages feature" do it "reshare of private post fails" do post = FactoryGirl.create(:status_message, author: alice.person, public: false) - reshare = FactoryGirl.build( + reshare = Fabricate( :reshare_entity, root_author: alice.diaspora_handle, root_guid: post.guid, author: sender_id) expect { post_message(generate_xml(reshare, sender)) @@ -74,7 +74,7 @@ describe "Receive federation messages feature" do let(:recipient) { alice } it "treats sharing request recive correctly" do - entity = FactoryGirl.build(:request_entity, author: sender_id, recipient: alice.diaspora_handle) + entity = Fabricate(:request_entity, author: sender_id, recipient: alice.diaspora_handle) expect(Workers::ReceiveLocal).to receive(:perform_async).and_call_original @@ -105,7 +105,7 @@ describe "Receive federation messages feature" do it_behaves_like "messages which can't be send without sharing" it "treats profile receive correctly" do - entity = FactoryGirl.build(:profile_entity, author: sender_id) + entity = Fabricate(:profile_entity, author: sender_id) post_message(generate_xml(entity, sender, alice), alice) received_profile = sender.profile.reload @@ -115,7 +115,7 @@ describe "Receive federation messages feature" do end it "receives conversation correctly" do - entity = FactoryGirl.build( + entity = Fabricate( :conversation_entity, author: sender_id, participants: "#{sender_id};#{alice.diaspora_handle}" diff --git a/spec/integration/federation/shared_receive_retraction.rb b/spec/integration/federation/shared_receive_retraction.rb index afa415993..b54588524 100644 --- a/spec/integration/federation/shared_receive_retraction.rb +++ b/spec/integration/federation/shared_receive_retraction.rb @@ -1,5 +1,5 @@ def retraction_entity(entity_name, target_object, sender) - FactoryGirl.build( + Fabricate( entity_name, author: sender.diaspora_handle, target_guid: target_object.guid, diff --git a/spec/integration/federation/shared_receive_stream_items.rb b/spec/integration/federation/shared_receive_stream_items.rb index 391c194cf..67d5766b0 100644 --- a/spec/integration/federation/shared_receive_stream_items.rb +++ b/spec/integration/federation/shared_receive_stream_items.rb @@ -4,7 +4,7 @@ shared_examples_for "messages which are indifferent about sharing fact" do let(:public) { recipient.nil? } it "treats status message receive correctly" do - entity = FactoryGirl.build(:status_message_entity, author: sender_id, public: public) + entity = Fabricate(:status_message_entity, author: sender_id, public: public) post_message(generate_xml(entity, sender, recipient), recipient) @@ -13,7 +13,7 @@ shared_examples_for "messages which are indifferent about sharing fact" do it "doesn't accept status message with wrong signature" do allow(sender).to receive(:encryption_key).and_return(OpenSSL::PKey::RSA.new(1024)) - entity = FactoryGirl.build(:status_message_entity, author: sender_id, public: public) + entity = Fabricate(:status_message_entity, author: sender_id, public: public) post_message(generate_xml(entity, sender, recipient), recipient) diff --git a/spec/integration/mentioning_spec.rb b/spec/integration/mentioning_spec.rb index 367758bf8..94bd5f8cf 100644 --- a/spec/integration/mentioning_spec.rb +++ b/spec/integration/mentioning_spec.rb @@ -73,7 +73,7 @@ module MentioningSpecHelpers end def receive_status_message_via_federation(text, *recipients) - entity = FactoryGirl.build( + entity = Fabricate( :status_message_entity, author: remote_raphael.diaspora_handle, text: text, diff --git a/spec/lib/diaspora/federation/receive_spec.rb b/spec/lib/diaspora/federation/receive_spec.rb index c31f6332d..680a34190 100644 --- a/spec/lib/diaspora/federation/receive_spec.rb +++ b/spec/lib/diaspora/federation/receive_spec.rb @@ -3,7 +3,7 @@ describe Diaspora::Federation::Receive do let(:post) { FactoryGirl.create(:status_message, text: "hello", public: true, author: alice.person) } describe ".account_deletion" do - let(:account_deletion_entity) { FactoryGirl.build(:account_deletion_entity, author: sender.diaspora_handle) } + let(:account_deletion_entity) { Fabricate(:account_deletion_entity, author: sender.diaspora_handle) } it "saves the account deletion" do Diaspora::Federation::Receive.account_deletion(account_deletion_entity) @@ -66,7 +66,7 @@ describe Diaspora::Federation::Receive do describe ".contact" do let(:contact_entity) { - FactoryGirl.build(:contact_entity, author: sender.diaspora_handle, recipient: alice.diaspora_handle) + Fabricate(:contact_entity, author: sender.diaspora_handle, recipient: alice.diaspora_handle) } it "creates the contact if it doesn't exist" do @@ -99,7 +99,7 @@ describe Diaspora::Federation::Receive do context "sharing=false" do let(:unshare_contact_entity) { - FactoryGirl.build( + Fabricate( :contact_entity, author: sender.diaspora_handle, recipient: alice.diaspora_handle, @@ -128,9 +128,9 @@ describe Diaspora::Federation::Receive do end describe ".conversation" do - let(:conv_guid) { FactoryGirl.generate(:guid) } + let(:conv_guid) { Fabricate.sequence(:guid) } let(:message_entity) { - FactoryGirl.build( + Fabricate( :message_entity, author: alice.diaspora_handle, parent_guid: conv_guid, @@ -138,7 +138,7 @@ describe Diaspora::Federation::Receive do ) } let(:conversation_entity) { - FactoryGirl.build( + Fabricate( :conversation_entity, guid: conv_guid, author: alice.diaspora_handle, @@ -184,7 +184,7 @@ describe Diaspora::Federation::Receive do describe ".like" do let(:like_data) { - FactoryGirl.attributes_for( + Fabricate.attributes_for( :like_entity, author: sender.diaspora_handle, parent_guid: post.guid, @@ -241,7 +241,7 @@ describe Diaspora::Federation::Receive do end } let(:message_entity) { - FactoryGirl.build( + Fabricate( :message_entity, author: sender.diaspora_handle, parent_guid: conversation.guid, @@ -276,7 +276,7 @@ describe Diaspora::Federation::Receive do describe ".participation" do let(:participation_entity) { - FactoryGirl.build(:participation_entity, author: sender.diaspora_handle, parent_guid: post.guid) + Fabricate(:participation_entity, author: sender.diaspora_handle, parent_guid: post.guid) } it "saves the participation" do @@ -303,7 +303,7 @@ describe Diaspora::Federation::Receive do end describe ".photo" do - let(:photo_entity) { FactoryGirl.build(:photo_entity, author: sender.diaspora_handle) } + let(:photo_entity) { Fabricate(:photo_entity, author: sender.diaspora_handle) } it "saves the photo if it does not already exist" do received = Diaspora::Federation::Receive.perform(photo_entity) @@ -353,7 +353,7 @@ describe Diaspora::Federation::Receive do describe ".poll_participation" do let(:post_with_poll) { FactoryGirl.create(:status_message_with_poll, author: alice.person) } let(:poll_participation_data) { - FactoryGirl.attributes_for( + Fabricate.attributes_for( :poll_participation_entity, author: sender.diaspora_handle, parent_guid: post_with_poll.poll.guid, @@ -406,7 +406,7 @@ describe Diaspora::Federation::Receive do end describe ".profile" do - let(:profile_entity) { FactoryGirl.build(:profile_entity, author: sender.diaspora_handle) } + let(:profile_entity) { Fabricate(:profile_entity, author: sender.diaspora_handle) } it "updates the profile of the person" do received = Diaspora::Federation::Receive.perform(profile_entity) @@ -426,7 +426,7 @@ describe Diaspora::Federation::Receive do end describe ".reshare" do - let(:reshare_entity) { FactoryGirl.build(:reshare_entity, author: sender.diaspora_handle, root_guid: post.guid) } + let(:reshare_entity) { Fabricate(:reshare_entity, author: sender.diaspora_handle, root_guid: post.guid) } it "saves the reshare" do received = Diaspora::Federation::Receive.perform(reshare_entity) @@ -456,7 +456,7 @@ describe Diaspora::Federation::Receive do it "destroys the post" do remote_post = FactoryGirl.create(:status_message, author: sender, public: true) - retraction = FactoryGirl.build( + retraction = Fabricate( :retraction_entity, author: sender.diaspora_handle, target_guid: remote_post.guid, @@ -471,12 +471,7 @@ describe Diaspora::Federation::Receive do end it "raises when the post does not exist" do - retraction = FactoryGirl.build( - :retraction_entity, - author: sender.diaspora_handle, - target_guid: FactoryGirl.generate(:guid), - target_type: "Post" - ) + retraction = Fabricate(:retraction_entity, author: sender.diaspora_handle, target_type: "Post") expect { Diaspora::Federation::Receive.retraction(retraction, nil) @@ -486,7 +481,7 @@ describe Diaspora::Federation::Receive do it "disconnects on Person-Retraction" do alice.contacts.find_or_initialize_by(person_id: sender.id, receiving: true, sharing: true).save! - retraction = FactoryGirl.build( + retraction = Fabricate( :retraction_entity, author: sender.diaspora_handle, target_guid: sender.guid, @@ -506,7 +501,7 @@ describe Diaspora::Federation::Receive do local_post = FactoryGirl.create(:status_message, author: alice.person, public: true) remote_comment = FactoryGirl.create(:comment, author: sender, post: local_post) - retraction = FactoryGirl.build( + retraction = Fabricate( :retraction_entity, author: sender.diaspora_handle, target_guid: remote_comment.guid, @@ -529,7 +524,7 @@ describe Diaspora::Federation::Receive do remote_post = FactoryGirl.create(:status_message, author: sender, public: true) remote_comment = FactoryGirl.create(:comment, author: sender, post: remote_post) - retraction = FactoryGirl.build( + retraction = Fabricate( :retraction_entity, author: sender.diaspora_handle, target_guid: remote_comment.guid, @@ -547,7 +542,7 @@ describe Diaspora::Federation::Receive do describe ".status_message" do context "basic status message" do - let(:status_message_entity) { FactoryGirl.build(:status_message_entity, author: sender.diaspora_handle) } + let(:status_message_entity) { Fabricate(:status_message_entity, author: sender.diaspora_handle) } it "saves the status message" do received = Diaspora::Federation::Receive.perform(status_message_entity) @@ -583,7 +578,7 @@ describe Diaspora::Federation::Receive do end it "finds the correct author if the author is not lowercase" do - status_message_entity = FactoryGirl.build(:status_message_entity, author: sender.diaspora_handle.upcase) + status_message_entity = Fabricate(:status_message_entity, author: sender.diaspora_handle.upcase) received = Diaspora::Federation::Receive.perform(status_message_entity) @@ -595,9 +590,9 @@ describe Diaspora::Federation::Receive do end context "with poll" do - let(:poll_entity) { FactoryGirl.build(:poll_entity) } + let(:poll_entity) { Fabricate(:poll_entity) } let(:status_message_entity) { - FactoryGirl.build(:status_message_entity, author: sender.diaspora_handle, poll: poll_entity) + Fabricate(:status_message_entity, author: sender.diaspora_handle, poll: poll_entity) } it "saves the status message" do @@ -616,9 +611,9 @@ describe Diaspora::Federation::Receive do end context "with location" do - let(:location_entity) { FactoryGirl.build(:location_entity) } + let(:location_entity) { Fabricate(:location_entity) } let(:status_message_entity) { - FactoryGirl.build(:status_message_entity, author: sender.diaspora_handle, location: location_entity) + Fabricate(:status_message_entity, author: sender.diaspora_handle, location: location_entity) } it "saves the status message" do @@ -636,15 +631,15 @@ describe Diaspora::Federation::Receive do end context "with photos" do - let(:status_message_guid) { FactoryGirl.generate(:guid) } + let(:status_message_guid) { Fabricate.sequence(:guid) } let(:photo1) { - FactoryGirl.build(:photo_entity, author: sender.diaspora_handle, status_message_guid: status_message_guid) + Fabricate(:photo_entity, author: sender.diaspora_handle, status_message_guid: status_message_guid) } let(:photo2) { - FactoryGirl.build(:photo_entity, author: sender.diaspora_handle, status_message_guid: status_message_guid) + Fabricate(:photo_entity, author: sender.diaspora_handle, status_message_guid: status_message_guid) } let(:status_message_entity) { - FactoryGirl.build( + Fabricate( :status_message_entity, author: sender.diaspora_handle, guid: status_message_guid, diff --git a/spec/models/notifications/private_message_spec.rb b/spec/models/notifications/private_message_spec.rb index 4ab3b0d79..327312ff6 100644 --- a/spec/models/notifications/private_message_spec.rb +++ b/spec/models/notifications/private_message_spec.rb @@ -4,7 +4,7 @@ describe Notifications::PrivateMessage, type: :model do let(:conversation) { - conv_guid = FactoryGirl.generate(:guid) + conv_guid = Fabricate.sequence(:guid) Conversation.create( guid: conv_guid,