Flaky Spec Fix:Ensure We Find Articles With Tags and Dont Cache Count for Class Method (#9833)
This commit is contained in:
parent
10d4053210
commit
702cece697
2 changed files with 5 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
class ArticleSuggester
|
||||
def initialize(article)
|
||||
@article = article
|
||||
@total_articles_count = self.class.memoized_articles_count
|
||||
@total_articles_count = self.class.articles_count
|
||||
end
|
||||
|
||||
def articles(max: 4)
|
||||
|
|
@ -23,8 +23,8 @@ class ArticleSuggester
|
|||
end
|
||||
end
|
||||
|
||||
def self.memoized_articles_count
|
||||
@memoized_articles_count ||= Article.published.estimated_count
|
||||
def self.articles_count
|
||||
Article.published.estimated_count
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ require "rails_helper"
|
|||
|
||||
RSpec.describe ArticleSuggester, type: :labor do
|
||||
it "returns proper number of articles with post with the same tags" do
|
||||
create_list(:article, 4, featured: true, tags: ["discuss"])
|
||||
create_list(:article, 4, featured: true, tags: ["discuss"], score: 10)
|
||||
article = create(:article, featured: true, tags: ["discuss"])
|
||||
expect(described_class.new(article).articles.size).to eq(4)
|
||||
end
|
||||
|
||||
it "returns proper number of articles with post with different tags" do
|
||||
create_list(:article, 2, featured: true, tags: ["discuss"])
|
||||
create_list(:article, 2, featured: true, tags: ["discuss"], score: 10)
|
||||
create_list(:article, 2, featured: true, tags: ["javascript"])
|
||||
article = create(:article, featured: true, tags: ["discuss"])
|
||||
expect(described_class.new(article).articles.size).to eq(4)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue