Skip to content

Commit

Permalink
Ensure only one Organisation is returned
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pezholio committed Nov 27, 2024
1 parent 95c2708 commit 46e1365
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/queries/get_host_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
19 changes: 19 additions & 0 deletions spec/queries/get_host_content_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<p>{{embed:email_address:#{target_content_id}}}</p>\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
Expand Down

0 comments on commit 46e1365

Please sign in to comment.