From 39c339247bbfe17bf154be835b24a417c0feb4b0 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Mon, 28 Mar 2022 14:01:29 -0500 Subject: [PATCH] Avoid using robohash for factory generated article cover images (#17024) * Avoid using robohash for article cover images If their service slows down, loading the cover image times out in system tests. Use a locally served image file instead. * Specify expected image format for view object test We were relying on the internals of Faker to return a robohash.org url and checking that we included that in the cloudinary url. Rather than relying on the default behavior, explicitly pass a robohash url in the main image for this spec. --- spec/factories/articles.rb | 6 +++++- spec/view_objects/cloud_cover_url_spec.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/factories/articles.rb b/spec/factories/articles.rb index 0b76e1d7f..adb2701bb 100644 --- a/spec/factories/articles.rb +++ b/spec/factories/articles.rb @@ -23,7 +23,11 @@ FactoryBot.define do co_author_ids { [] } association :user, factory: :user, strategy: :create description { Faker::Hipster.paragraph(sentence_count: 1)[0..100] } - main_image { with_main_image ? Faker::Avatar.image : nil } + main_image do + if with_main_image + URL.url(ActionController::Base.helpers.asset_path("#{rand(1..40)}.png")) + end + end experience_level_rating { rand(4..6) } body_markdown do <<~HEREDOC diff --git a/spec/view_objects/cloud_cover_url_spec.rb b/spec/view_objects/cloud_cover_url_spec.rb index 0a67cc9fd..b821eeb11 100644 --- a/spec/view_objects/cloud_cover_url_spec.rb +++ b/spec/view_objects/cloud_cover_url_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" RSpec.describe CloudCoverUrl, type: :view_object, cloudinary: true do - let(:article) { create(:article) } + let(:article) { create(:article, main_image: "https://robohash.org/articlefactory.png") } let(:cloudinary_prefix) { "https://res.cloudinary.com/#{Cloudinary.config.cloud_name}/image/fetch/" } it "returns proper url" do