Part 1: Shows Relevant #help Posts in Homepage Sidebar (#12670) [deploy]
* Replace #active_help scope with #active_help class method * WIP: Add tests around #active_help class method * Refactor #active_help and update article_spec.rb tests to pass * Replaces .active_help class method with .active_help scope - Reverts change from scope to class method, back to scope - Updates to use newer AR query syntax using endless ranges - Refactors scope to be more concise
This commit is contained in:
parent
a2458d5f59
commit
27f27caff3
2 changed files with 19 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue