diff --git a/app/models/article.rb b/app/models/article.rb index ec57ef73b..745dee7a1 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -133,10 +133,9 @@ class Article < ApplicationRecord scope :cached_tagged_by_approval_with, ->(tag) { cached_tagged_with(tag).where(approved: true) } scope :active_help, lambda { - published - .cached_tagged_with("help") - .order(created_at: :desc) - .where("published_at > ? AND comments_count < ? AND score > ?", 12.hours.ago, 6, -4) + stories = published.cached_tagged_with("help").order(created_at: :desc) + + stories.where(published_at: 12.hours.ago.., comments_count: ..5, score: -3..).presence || stories } scope :limited_column_select, lambda { diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index ec37651f8..555f6972a 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -681,6 +681,22 @@ RSpec.describe Article, type: :model do end end + describe ".active_help" do + it "returns properly filtered articles under the 'help' tag" do + filtered_article = create(:article, user: user, tags: "help", + published_at: 13.hours.ago, comments_count: 5, score: -3) + articles = described_class.active_help + expect(articles).to include(filtered_article) + end + + it "returns any published articles tagged with 'help' when there are no articles that fit the criteria" do + unfiltered_article = create(:article, user: user, tags: "help", + published_at: 10.hours.ago, comments_count: 8, score: -5) + articles = described_class.active_help + expect(articles).to include(unfiltered_article) + end + end + describe ".seo_boostable" do let!(:top_article) do create(:article, organic_page_views_past_month_count: 20, score: 30, tags: "good, greatalicious", user: user)