Skip to content

Commit

Permalink
Temporarily restrict number of results retured prior to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed Aug 22, 2024
1 parent c5909a3 commit 99963c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/presenters/filtered_editions_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class FilteredEditionsPresenter
ITEMS_PER_PAGE = 20

def initialize(states_filter: [], assigned_to_filter: nil, format_filter: nil, title_filter: nil)
@states_filter = states_filter || []
@assigned_to_filter = assigned_to_filter
Expand All @@ -16,7 +18,11 @@ def editions
result = editions_by_format
result = apply_states_filter(result)
result = apply_assigned_to_filter(result)
apply_title_filter(result)
result = apply_title_filter(result)
result = result.where.not(_type: "PopularLinksEdition")
# Sets a temporary limit of one page and twenty items
# Pagination to follow
result.page(1).per(ITEMS_PER_PAGE)
end

private
Expand Down
13 changes: 11 additions & 2 deletions test/unit/presenters/filtered_editions_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FilteredEditionsPresenterTest < ActiveSupport::TestCase
guide = FactoryBot.create(:guide_edition)
FactoryBot.create(:completed_transaction_edition)

filtered_editions = FilteredEditionsPresenter.new(format_filter: "guide").editions
filtered_editions = FilteredEditionsPresenter.new(format_filter: "guide").editions.to_a

assert_equal([guide], filtered_editions)
end
Expand All @@ -78,7 +78,16 @@ class FilteredEditionsPresenterTest < ActiveSupport::TestCase
guide_fawkes = FactoryBot.create(:guide_edition, title: "Guide Fawkes")
FactoryBot.create(:guide_edition, title: "Hitchhiker's Guide")

filtered_editions = FilteredEditionsPresenter.new(title_filter: "Fawkes").editions
filtered_editions = FilteredEditionsPresenter.new(title_filter: "Fawkes").editions.to_a

assert_equal([guide_fawkes], filtered_editions)
end

should "not return popular links" do
guide_fawkes = FactoryBot.create(:guide_edition)
FactoryBot.create(:popular_links)

filtered_editions = FilteredEditionsPresenter.new.editions.to_a

assert_equal([guide_fawkes], filtered_editions)
end
Expand Down

0 comments on commit 99963c2

Please sign in to comment.