Skip to content

Commit

Permalink
Merge pull request #3004 from alphagov/content-modelling/731-investig…
Browse files Browse the repository at this point in the history
…ate-html-documents-coming-up-twice-for-location

(731) Ensure only one Organisation is returned when fetching host content.
  • Loading branch information
pezholio authored Nov 27, 2024
2 parents 95c2708 + 46e1365 commit 8a76cab
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 8a76cab

Please sign in to comment.