From 46e1365a5804de73e0dac1b6a4d6cd19e538ebb9 Mon Sep 17 00:00:00 2001 From: pezholio Date: Wed, 27 Nov 2024 11:19:35 +0000 Subject: [PATCH] Ensure only one Organisation is returned When fetching host content for an organisation which has a translation, multiple rows are returned, one per translation. The updates the join statement, so we only fetch organisation documents in the `en` locale. --- app/queries/get_host_content.rb | 1 + spec/queries/get_host_content_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/queries/get_host_content.rb b/app/queries/get_host_content.rb index 2839c0212..bc0caa7b3 100644 --- a/app/queries/get_host_content.rb +++ b/app/queries/get_host_content.rb @@ -122,6 +122,7 @@ def arel_joins ) .join(TABLES[:org_documents], Arel::Nodes::OuterJoin).on( TABLES[:org_documents][:content_id].eq(TABLES[:primary_links][:target_content_id]), + TABLES[:org_documents][:locale].eq("en"), ) .join(TABLES[:org_editions], Arel::Nodes::OuterJoin).on( TABLES[:org_editions][:document_id].eq(TABLES[:org_documents][:id]), diff --git a/spec/queries/get_host_content_spec.rb b/spec/queries/get_host_content_spec.rb index 1ffdb2de1..857a7cf96 100644 --- a/spec/queries/get_host_content_spec.rb +++ b/spec/queries/get_host_content_spec.rb @@ -106,6 +106,25 @@ expect(results[0].instances).to eq(2) end + + it "returns one row per content block when an organisation has a translation" do + welsh_document = create(:document, locale: "cy", content_id: organisation.content_id) + create(:live_edition, document: welsh_document, base_path: "#{organisation.base_path}.cy") + + create(:live_edition, + details: { + body: "

{{embed:email_address:#{target_content_id}}}

\n", + }, + links_hash: { + primary_publishing_organisation: [organisation.content_id], + embed: [target_content_id], + }, + publishing_app: "example-app") + + results = described_class.new(target_content_id).call + + expect(results.count).to eq(1) + end end context "when there are superseded editions that embed the target content" do