From e3fe92876a5460cc8b702bb27e74e154bf5fa129 Mon Sep 17 00:00:00 2001 From: Ynda Jas Date: Thu, 24 Oct 2024 16:17:45 +0100 Subject: [PATCH] Move factory to live edition factory file This looks like it belongs in the live edition factory, not the edition factory. The fact that live editions have their own factory is a little unusual and probably led to this misplacement I've also changed it to be a trait rather than a specific factory. I'm not sure that the distinction in how they're used is clear, but `with_***` sounds trait-like --- spec/factories/edition.rb | 12 ------------ spec/factories/live_edition.rb | 11 +++++++++++ spec/service_consumers/pact_helper.rb | 3 ++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/factories/edition.rb b/spec/factories/edition.rb index f85e4bcc7..4e049534b 100644 --- a/spec/factories/edition.rb +++ b/spec/factories/edition.rb @@ -94,16 +94,4 @@ schema_name { "contact" } document_type { "contact" } end - - factory :live_edition_with_embedded_content, parent: :edition do - base_path { "/#{SecureRandom.uuid}" } - details { { body: "{{embed:#{embedded_content_type}:#{embedded_content_id}" } } - state { "published" } - - transient do - embedded_content_id { SecureRandom.uuid } - embedded_content_type { "content_block_email_address" } - links_hash { { embed: [embedded_content_id] } } - end - end end diff --git a/spec/factories/live_edition.rb b/spec/factories/live_edition.rb index ba7b5751d..d21b37b4b 100644 --- a/spec/factories/live_edition.rb +++ b/spec/factories/live_edition.rb @@ -29,6 +29,17 @@ with_draft end + trait :with_embedded_content do + base_path { "/#{SecureRandom.uuid}" } + details { { body: "{{embed:#{embedded_content_type}:#{embedded_content_id}" } } + + transient do + embedded_content_id { SecureRandom.uuid } + embedded_content_type { "content_block_email_address" } + links_hash { { embed: [embedded_content_id] } } + end + end + after(:create) do |live_edition, evaluator| unless evaluator.published_at live_edition.update!(published_at: live_edition.created_at) diff --git a/spec/service_consumers/pact_helper.rb b/spec/service_consumers/pact_helper.rb index 88bbc153a..0ec933563 100644 --- a/spec/service_consumers/pact_helper.rb +++ b/spec/service_consumers/pact_helper.rb @@ -657,7 +657,8 @@ def url_encode(str) reusable_edition = create(:live_edition, document: reusable_document) document = create(:document, content_id: "d66d6552-2627-4451-9dbc-cadbbd2005a1") - live_edition_with_embedded_edition = create(:live_edition_with_embedded_content, + live_edition_with_embedded_edition = create(:live_edition, + :with_embedded_content, document:, embedded_content_id: reusable_edition.content_id, title: "foo",