Skip to content

Commit

Permalink
Merge pull request #2882 from alphagov/content-modelling/562-bug-cont…
Browse files Browse the repository at this point in the history
…ent-appears-in-showing-multiple-times

(562) Ensure only live organisations appear in join
  • Loading branch information
pezholio committed Sep 24, 2024
2 parents 7e79e12 + 4c4d246 commit 88d1450
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/queries/get_embedded_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def host_editions
.joins(:links)
.joins("LEFT JOIN links AS primary_links ON primary_links.edition_id = editions.id AND primary_links.link_type = 'primary_publishing_organisation'")
.joins("LEFT JOIN documents ON documents.content_id = primary_links.target_content_id")
.joins("LEFT JOIN editions AS org_editions ON org_editions.document_id = documents.id")
.joins("LEFT JOIN editions AS org_editions ON org_editions.document_id = documents.id AND org_editions.state = 'published'")
.where(links: { link_type: embedded_link_type, target_content_id: })
.select(
"editions.id, editions.title, editions.base_path, editions.document_type, editions.publishing_app",
Expand Down
18 changes: 13 additions & 5 deletions spec/queries/get_embedded_content_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
RSpec.describe Queries::GetEmbeddedContent do
describe "#call" do
let(:organisation) do
create(:live_edition,
title: "bar",
document_type: "organisation",
schema_name: "organisation",
base_path: "/government/organisations/bar")
edition_params = {
title: "bar",
document: create(:document),
document_type: "organisation",
schema_name: "organisation",
base_path: "/government/organisations/bar",
}

create(:superseded_edition, **edition_params)
live_edition = create(:live_edition, **edition_params.merge({ user_facing_version: 2 }))
create(:draft_edition, **edition_params.merge({ user_facing_version: 3 }))

live_edition
end

let(:content_block) do
Expand Down

0 comments on commit 88d1450

Please sign in to comment.