diff --git a/spec/black_box/black_box_spec.rb b/spec/black_box/black_box_spec.rb index 7ac07ac27..2a5660581 100644 --- a/spec/black_box/black_box_spec.rb +++ b/spec/black_box/black_box_spec.rb @@ -4,7 +4,7 @@ RSpec.describe BlackBox do let!(:function_caller) { double } describe "#article_hotness_score" do - let!(:article) { create(:article, published_at: Time.current) } + let!(:article) { build_stubbed(:article, published_at: Time.current) } it "calls function caller" do allow(function_caller).to receive(:call).and_return(5) @@ -18,7 +18,7 @@ RSpec.describe BlackBox do end it "returns the correct value" do - article.update_column(:score, 99) + article = build_stubbed(:article, score: 99, published_at: Time.current) allow(function_caller).to receive(:call).and_return(5) # recent bonuses (28 + 31 + 80 + 395 + 330 + 330 = 1194) # + score (99) @@ -28,8 +28,7 @@ RSpec.describe BlackBox do end it "returns the lower correct value if article tagged with watercooler" do - article.update_column(:score, 99) - article.update_column(:cached_tag_list, "hello, discuss, watercooler") + article = build_stubbed(:article, score: 99, cached_tag_list: "hello, discuss, watercooler", published_at: Time.current) allow(function_caller).to receive(:call).and_return(5) # recent bonuses (28 + 31 + 80 + 395 + 330 + 330 = 1194) # + score (99) @@ -40,16 +39,11 @@ RSpec.describe BlackBox do end describe "#comment_quality_score" do - let(:comment) { create(:comment, commentable: create(:article), body_markdown: "```#{'hello, world! ' * 20}```") } - - before do - reaction = create(:reaction, reactable: comment) - reaction.update_column(:points, 20) - reaction2 = create(:reaction, reactable: comment) - reaction2.update_column(:points, 2) - end - it "returns the correct score" do + comment = build_stubbed(:comment, body_markdown: "```#{'hello, world! ' * 20}```") + reactions = double + allow(comment).to receive(:reactions).and_return(reactions) + allow(reactions).to receive(:sum).with(:points).and_return(22) # rep_points + descendants_points + bonus_points - spaminess_rating # rep_points - 22 # descendants_points - 0 @@ -61,8 +55,8 @@ RSpec.describe BlackBox do end describe "#calculate_spaminess" do - let(:user) { build(:user) } - let(:comment) { build(:comment, user: user) } + let(:user) { build_stubbed(:user) } + let(:comment) { build_stubbed(:comment, user: user) } before do allow(function_caller).to receive(:call).and_return(1) diff --git a/spec/factories/articles.rb b/spec/factories/articles.rb index da55333d3..d86fff712 100644 --- a/spec/factories/articles.rb +++ b/spec/factories/articles.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :article do transient do - title { Faker::Book.title + rand(100).to_s } + title { Faker::Book.title } published { true } date { "01/01/2015" } tags { Faker::Hipster.words(number: 4).join(", ") } diff --git a/spec/factories/classified_listings.rb b/spec/factories/classified_listings.rb index ca2dbeeb7..6c9cc2017 100644 --- a/spec/factories/classified_listings.rb +++ b/spec/factories/classified_listings.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :classified_listing do user - title { Faker::Book.title + rand(100).to_s } + title { Faker::Book.title } body_markdown { Faker::Hipster.paragraph(sentence_count: 2) } category { "education" } published { true } diff --git a/spec/factories/pages.rb b/spec/factories/pages.rb index 08fdf88a6..d0c2471a7 100644 --- a/spec/factories/pages.rb +++ b/spec/factories/pages.rb @@ -1,9 +1,9 @@ FactoryBot.define do factory :page do - title { Faker::Book.title + rand(100).to_s } - body_markdown { Faker::Book.title + rand(100).to_s } - slug { "word-#{rand(10_000)}" } - description { Faker::Book.title + rand(100).to_s } - template { "contained" } + title { Faker::Book.title } + body_markdown { Faker::Lorem.sentence } + slug { Faker::Internet.slug } + description { Faker::Lorem.sentence } + template { "contained" } end end diff --git a/spec/liquid_tags/link_tag_spec.rb b/spec/liquid_tags/link_tag_spec.rb index e89fe7599..928a43e26 100644 --- a/spec/liquid_tags/link_tag_spec.rb +++ b/spec/liquid_tags/link_tag_spec.rb @@ -32,7 +32,7 @@ RSpec.describe LinkTag, type: :liquid_template do