From 19f583c4497830bf38988068f067a0530d413caa Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 24 May 2022 11:52:13 +0100 Subject: [PATCH] FIX: Skip pulling hotlinked images for nil user bio (#16901) --- app/jobs/regular/pull_user_profile_hotlinked_images.rb | 2 +- spec/jobs/pull_user_profile_hotlinked_images_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/jobs/regular/pull_user_profile_hotlinked_images.rb b/app/jobs/regular/pull_user_profile_hotlinked_images.rb index 66280f2f7eb..22c7b21e9dc 100644 --- a/app/jobs/regular/pull_user_profile_hotlinked_images.rb +++ b/app/jobs/regular/pull_user_profile_hotlinked_images.rb @@ -7,7 +7,7 @@ module Jobs raise Discourse::InvalidParameters.new(:user_id) if @user_id.blank? user_profile = UserProfile.find_by(user_id: @user_id) - return if user_profile.blank? + return if user_profile.blank? || user_profile.bio_cooked.nil? large_image_urls = [] broken_image_urls = [] diff --git a/spec/jobs/pull_user_profile_hotlinked_images_spec.rb b/spec/jobs/pull_user_profile_hotlinked_images_spec.rb index a0605978a61..748709e35d0 100644 --- a/spec/jobs/pull_user_profile_hotlinked_images_spec.rb +++ b/spec/jobs/pull_user_profile_hotlinked_images_spec.rb @@ -21,5 +21,10 @@ describe Jobs::PullUserProfileHotlinkedImages do expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.to change { Upload.count }.by(1) expect(user.user_profile.reload.bio_cooked).to include(Upload.last.url) end + + it 'handles nil bio' do + expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.to change { Upload.count }.by(0) + expect(user.user_profile.reload.bio_cooked).to eq(nil) + end end end