tests: fix broken tests.

This commit is contained in:
evazion
2022-08-23 18:31:24 -05:00
parent 09dfab1f0d
commit e3af738371
16 changed files with 100 additions and 152 deletions

View File

@@ -66,6 +66,10 @@ module Source
elsif api_response[:file_url].present?
api_response[:file_url][/\.(jpg|jpeg|png|gif)\z/i, 1]
# on yande.re, the file extension doesn't matter, any random string will work. This means we can't guess the true file extension.
elsif domain == "yande.re"
"png"
# the api_response wasn't available because it's a deleted post.
elsif post_md5.present?
%w[jpg png gif].find { |ext| http_exists?("https://#{domain}/image/#{post_md5}.#{ext}") }

View File

@@ -246,6 +246,8 @@ class MediaAsset < ApplicationRecord
# This can't be called inside a transaction because the transaction will
# fail if there's a RecordNotUnique error when the asset already exists.
def upload!(media_file, &block)
media_file = MediaFile.open(media_file) unless media_file.is_a?(MediaFile)
raise Error, "File is corrupt" if media_file.is_corrupt?
media_asset = create!(file: media_file, status: :processing)