From 3e6bb0119971776f8a977effa1ecdaa534972082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Sat, 10 Apr 2021 23:48:02 +0200 Subject: [PATCH] Fix specs for factory_bot 6 --- spec/factories.rb | 9 +++++++++ spec/helpers/gon_helper_spec.rb | 4 ++-- spec/lib/diaspora/federation/entities_spec.rb | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spec/factories.rb b/spec/factories.rb index 3ea0fdf87..4ad2dbd57 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -179,6 +179,10 @@ FactoryBot.define do p.poll_answers << FactoryBot.build(:poll_answer, poll: p) p.poll_answers << FactoryBot.build(:poll_answer, poll: p) end + + trait(:with_author) { + association :author + } end factory(:poll_answer) do @@ -189,6 +193,11 @@ FactoryBot.define do factory :poll_participation do association :author, factory: :person association :poll_answer + + trait(:with_poll_author) do + after(:build) {|p| p.poll.author ||= p.author } + end + after(:build) {|p| p.poll = p.poll_answer.poll } end diff --git a/spec/helpers/gon_helper_spec.rb b/spec/helpers/gon_helper_spec.rb index a4def503f..db6a872d9 100644 --- a/spec/helpers/gon_helper_spec.rb +++ b/spec/helpers/gon_helper_spec.rb @@ -4,9 +4,9 @@ describe GonHelper, type: :helper do include_context :gon describe "#gon_load_contact" do - let(:contact) { FactoryBot.build(:contact) } + let(:contact) { FactoryBot.build(:contact, person: FactoryBot.create(:person)) } let(:current_user) { contact.user } - let(:another_contact) { FactoryBot.build(:contact, user: current_user) } + let(:another_contact) { FactoryBot.build(:contact, user: current_user, person: FactoryBot.create(:person)) } before do RequestStore.store[:gon] = Gon::Request.new(controller.request.env) diff --git a/spec/lib/diaspora/federation/entities_spec.rb b/spec/lib/diaspora/federation/entities_spec.rb index 7a1fac6ea..1835c400c 100644 --- a/spec/lib/diaspora/federation/entities_spec.rb +++ b/spec/lib/diaspora/federation/entities_spec.rb @@ -190,7 +190,7 @@ describe Diaspora::Federation::Entities do end it "builds a poll participation" do - diaspora_entity = FactoryBot.build(:poll_participation) + diaspora_entity = FactoryBot.build(:poll_participation, :with_poll_author) federation_entity = described_class.build(diaspora_entity) expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation) @@ -204,7 +204,7 @@ describe Diaspora::Federation::Entities do it "builds a poll participation with signature" do signature = FactoryBot.build(:poll_participation_signature) - diaspora_entity = FactoryBot.build(:poll_participation, signature: signature) + diaspora_entity = FactoryBot.build(:poll_participation, :with_poll_author, signature: signature) federation_entity = described_class.build(diaspora_entity) expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)