Fix specs for factory_bot 6

This commit is contained in:
Jonne Haß 2021-04-10 23:48:02 +02:00
parent 671e8476ba
commit 3e6bb01199
3 changed files with 13 additions and 4 deletions

View file

@ -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)
p.poll_answers << FactoryBot.build(:poll_answer, poll: p) p.poll_answers << FactoryBot.build(:poll_answer, poll: p)
end end
trait(:with_author) {
association :author
}
end end
factory(:poll_answer) do factory(:poll_answer) do
@ -189,6 +193,11 @@ FactoryBot.define do
factory :poll_participation do factory :poll_participation do
association :author, factory: :person association :author, factory: :person
association :poll_answer 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 } after(:build) {|p| p.poll = p.poll_answer.poll }
end end

View file

@ -4,9 +4,9 @@ describe GonHelper, type: :helper do
include_context :gon include_context :gon
describe "#gon_load_contact" do 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(: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 before do
RequestStore.store[:gon] = Gon::Request.new(controller.request.env) RequestStore.store[:gon] = Gon::Request.new(controller.request.env)

View file

@ -190,7 +190,7 @@ describe Diaspora::Federation::Entities do
end end
it "builds a poll participation" do 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) federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation) 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 it "builds a poll participation with signature" do
signature = FactoryBot.build(:poll_participation_signature) 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) federation_entity = described_class.build(diaspora_entity)
expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation) expect(federation_entity).to be_instance_of(DiasporaFederation::Entities::PollParticipation)