Replace FactoryGirl with Fabricate for federation factories

This commit is contained in:
Benjamin Neff 2017-04-25 01:10:03 +02:00
parent d79c2e511b
commit 78c7156e72
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
10 changed files with 52 additions and 58 deletions

View file

@ -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

View file

@ -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)

View file

@ -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]

View file

@ -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,

View file

@ -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}"

View file

@ -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,

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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,