Quick fix to pagination in /stories/feed (#19423)
* Quick fix to pagination in /stories/feed * Fix whitespace * Update app/services/articles/feeds/variant_query.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Mac Siri <mac@forem.com>
This commit is contained in:
parent
89290b1bbb
commit
4d7fcb7359
2 changed files with 22 additions and 2 deletions
|
|
@ -292,9 +292,9 @@ module Articles
|
|||
end
|
||||
|
||||
def default_offset
|
||||
return 0 if @page == 1
|
||||
return 0 if @page.zero?
|
||||
|
||||
@page.to_i - (1 * default_limit)
|
||||
(@page.to_i - 1) * default_limit
|
||||
end
|
||||
|
||||
# We want to ensure that we're not randomizing someone's feed all the time; and instead aiming
|
||||
|
|
|
|||
|
|
@ -17,5 +17,25 @@ RSpec.describe Articles::Feeds do
|
|||
before { allow(AbExperiment).to receive(:get_feed_variant_for).and_return("original") }
|
||||
|
||||
it { is_expected.to be_a(described_class::VariantQuery) }
|
||||
|
||||
it "creates proper offset for page 2" do
|
||||
feed = described_class.feed_for(controller: controller, user: user, number_of_articles: 3, page: 2, tag: nil)
|
||||
expect(feed.call.to_sql).to include("OFFSET 3")
|
||||
end
|
||||
|
||||
it "creates proper offset for page 4" do
|
||||
feed = described_class.feed_for(controller: controller, user: user, number_of_articles: 12, page: 4, tag: nil)
|
||||
expect(feed.call.to_sql).to include("OFFSET 36")
|
||||
end
|
||||
|
||||
it "creates proper offset for page 1" do
|
||||
feed = described_class.feed_for(controller: controller, user: user, number_of_articles: 3, page: 1, tag: nil)
|
||||
expect(feed.call.to_sql).not_to include("OFFSET")
|
||||
end
|
||||
|
||||
it "creates proper offset for page 0" do
|
||||
feed = described_class.feed_for(controller: controller, user: user, number_of_articles: 3, page: 0, tag: nil)
|
||||
expect(feed.call.to_sql).not_to include("OFFSET")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue