Skip to content

Commit

Permalink
Maintain lead organisations first when publishing HTML attachments
Browse files Browse the repository at this point in the history
- add test for ordering.
- update existing test to handle new mock requirements
- add delegation for call_for_evidence and consultation_response so
  that they can retrieve lead and supporting organisations
  separately to pass to presenter.
  • Loading branch information
KludgeKML committed Jun 18, 2024
1 parent 1fc69b6 commit 3f7a05f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/call_for_evidence_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def access_limited_object

delegate :organisations, to: :parent_attachable

delegate :lead_organisations, to: :parent_attachable

delegate :supporting_organisations, to: :parent_attachable

delegate :alternative_format_contact_email, to: :call_for_evidence

delegate :publicly_visible?, to: :parent_attachable
Expand Down
4 changes: 4 additions & 0 deletions app/models/consultation_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def access_limited_object

delegate :organisations, to: :parent_attachable

delegate :lead_organisations, to: :parent_attachable

delegate :supporting_organisations, to: :parent_attachable

delegate :alternative_format_contact_email, to: :consultation

delegate :publicly_visible?, to: :parent_attachable
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/publishing_api/html_attachment_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def links
def edition_links
{
parent: parent_content_ids, # please use the breadcrumb component when migrating document_type to government-frontend
organisations: parent.organisations.pluck(:content_id).uniq,
organisations: (parent.lead_organisations.pluck(:content_id) + parent.supporting_organisations.pluck(:content_id)).uniq,
primary_publishing_organisation:,
government: government_id,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,34 @@ def present(record)
html_attachment = HtmlAttachment.last
# if an organisation has multiple translations, pluck returns
# duplicate content_ids because it constructs a left outer join
html_attachment.attachable.organisations.expects(:pluck).with(:content_id).returns(%w[abcdef abcdef])
lead_orgs = mock
lead_orgs.expects(:pluck).with(:content_id).returns(%w[abcdef])
html_attachment.attachable.expects(:lead_organisations).returns(lead_orgs).twice

supporting_orgs = mock
supporting_orgs.expects(:pluck).with(:content_id).returns(%w[abcdef])
html_attachment.attachable.expects(:supporting_organisations).returns(supporting_orgs)

assert_equal %w[abcdef], present(html_attachment).links[:organisations]
end

test "HtmlAttachment presents lead organisation content_ids before supporting organisation content_ids" do
create(:publication, :with_html_attachment, :published)

html_attachment = HtmlAttachment.last
# if an organisation has multiple translations, pluck returns
# duplicate content_ids because it constructs a left outer join
lead_orgs = mock
lead_orgs.expects(:pluck).with(:content_id).returns(%w[abcdef])
html_attachment.attachable.expects(:lead_organisations).returns(lead_orgs).twice

supporting_orgs = mock
supporting_orgs.expects(:pluck).with(:content_id).returns(%w[bcdefg])
html_attachment.attachable.expects(:supporting_organisations).returns(supporting_orgs)

assert_equal %w[abcdef bcdefg], present(html_attachment).links[:organisations]
end

test "HtmlAttachment presents primary_publishing_organisation" do
create(:publication, :with_html_attachment, :published)

Expand Down

0 comments on commit 3f7a05f

Please sign in to comment.