Don't show low scoring articles in timeframe feeds (#20525)

This commit is contained in:
Anna Buianova 2024-01-15 17:14:32 +03:00 committed by GitHub
parent 9c7476db62
commit 08d34d5d34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View file

@ -81,6 +81,7 @@ module Stories
def stories_by_timeframe(stories:)
if Timeframe::FILTER_TIMEFRAMES.include?(params[:timeframe])
stories.where("published_at > ?", Timeframe.datetime(params[:timeframe]))
.where(score: -20..)
.order(public_reactions_count: :desc)
elsif params[:timeframe] == Timeframe::LATEST_TIMEFRAME
stories.where(score: -20..).order(published_at: :desc)

View file

@ -1,12 +1,14 @@
module Articles
module Feeds
module Timeframe
def self.call(timeframe, tag: nil, number_of_articles: Article::DEFAULT_FEED_PAGINATION_WINDOW_SIZE, page: 1)
def self.call(timeframe, tag: nil, minimum_score: -20,
number_of_articles: Article::DEFAULT_FEED_PAGINATION_WINDOW_SIZE, page: 1)
articles = ::Articles::Feeds::Tag.call(tag)
articles
.where("published_at > ?", ::Timeframe.datetime(timeframe))
.includes(:distinct_reaction_categories)
.where("score > ?", minimum_score)
.order(score: :desc)
.page(page)
.per(number_of_articles)

View file

@ -105,6 +105,14 @@ RSpec.describe "Stories::TaggedArticlesIndex" do
expect(response.body).to include(tag.name)
end
it "displays articles with score > -20 on top/week", :aggregate_failures do
article
bad_article = create(:article, tags: tag.name, score: -30)
get "/t/#{tag.name}/top/week"
expect(response.body).to include(CGI.escapeHTML(article.title))
expect(response.body).not_to include(CGI.escapeHTML(bad_article.title))
end
it "renders tag after alias change" do
tag2 = create(:tag, alias_for: tag.name)
get "/t/#{tag2.name}"

View file

@ -11,7 +11,12 @@ RSpec.describe Articles::Feeds::Timeframe, type: :service do
it "returns correct articles ordered by score", :aggregate_failures do
result = described_class.call("week")
expect(result.slice(0, 2)).to eq [hot_article, moderately_high_scoring_article]
expect(result.last).to eq low_scoring_article
expect(result).not_to include(low_scoring_article)
expect(result).not_to include(month_old_article)
end
it "returns low scoring articles if lower score is passed" do
result = described_class.call("week", minimum_score: -1001)
expect(result).to include(low_scoring_article)
end
end