FIX: stop logging every 404 error when searching for gravatars

This commit is contained in:
Sam 2018-10-23 11:43:14 +11:00
parent adab7a3a48
commit b74dd7d379
2 changed files with 21 additions and 0 deletions

View File

@ -51,6 +51,10 @@ class UserAvatar < ActiveRecord::Base
end
end
end
rescue OpenURI::HTTPError => e
if e.io&.status[0].to_i != 404
raise e
end
ensure
tempfile&.close!
end

View File

@ -83,6 +83,23 @@ describe UserAvatar do
end
describe "404 should be silent, nothing to do really" do
it "does nothing when avatar is 404" do
freeze_time Time.now
stub_request(:get, "https://www.gravatar.com/avatar/#{avatar.user.email_hash}.png?d=404&s=360").
to_return(status: 404, body: "", headers: {})
expect do
avatar.update_gravatar!
end.to_not change { Upload.count }
expect(avatar.last_gravatar_download_attempt).to eq(Time.now)
end
end
end
context '.import_url_for_user' do