Skip to content

Commit

Permalink
Merge pull request #9562 from alphagov/up-featured-limit-for-topical-…
Browse files Browse the repository at this point in the history
…events

Up limit to 6 for featured documents for Topical Event Pages
  • Loading branch information
ChrisBAshton authored Oct 28, 2024
2 parents db797c1 + 43f9817 commit 951a2d1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/models/topical_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TopicalEvent < ApplicationRecord
has_many :publications, through: :topical_event_memberships
has_many :speeches, through: :topical_event_memberships

MAX_FEATURED_DOCUMENTS = 6
has_many :features, inverse_of: :topical_event, dependent: :destroy
has_many :offsite_links, as: :parent
has_many :social_media_accounts, as: :socialable, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/publishing_api/topical_event_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def ordered_featured_documents
item
.topical_event_featurings
.includes(:image, edition: :document)
.limit(FeaturedLink::DEFAULT_SET_SIZE)
.limit(TopicalEvent::MAX_FEATURED_DOCUMENTS)
.select { |feature| feature.image.all_asset_variants_uploaded? }
.map do |feature|
{
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/topical_event_featurings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
label: "Currently featured",
content: render(Admin::CurrentlyFeaturedTabComponent.new(
featurings: @topical_event_featurings,
maximum_featured_documents: 5,
maximum_featured_documents: TopicalEvent::MAX_FEATURED_DOCUMENTS,
)),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ class PublishingApi::TopicalEventPresenterTest < ActiveSupport::TestCase

test "it limits the number of featured items" do
topical_event = create(:topical_event, start_date: Time.zone.today)
create_list(:topical_event_featuring, FeaturedLink::DEFAULT_SET_SIZE + 1, topical_event:)
create_list(:topical_event_featuring, TopicalEvent::MAX_FEATURED_DOCUMENTS + 1, topical_event:)

presenter = PublishingApi::TopicalEventPresenter.new(topical_event)

assert_equal FeaturedLink::DEFAULT_SET_SIZE, presenter.content.dig(:details, :ordered_featured_documents).length
assert_equal TopicalEvent::MAX_FEATURED_DOCUMENTS, presenter.content.dig(:details, :ordered_featured_documents).length
end

test "it ignores featured items if image variants are missing" do
Expand Down

0 comments on commit 951a2d1

Please sign in to comment.