mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Move hotlinked image information into a dedicated table (#16585)
This will make future changes to the 'pull hotlinked images' system easier. This commit should not introduce any functional change. For now, the old post_custom_field data is kept in the database. This will be dropped in a future commit.
This commit is contained in:
@@ -1080,8 +1080,7 @@ describe CookedPostProcessor do
|
||||
post = Fabricate(:post, raw: url)
|
||||
upload.update!(url: "https://test.s3.amazonaws.com/something.png")
|
||||
|
||||
post.custom_fields[Post::DOWNLOADED_IMAGES] = { "//image.com/avatar.png": upload.id }
|
||||
post.save_custom_fields
|
||||
PostHotlinkedMedia.create!(url: "//image.com/avatar.png", post: post, status: 'downloaded', upload: upload)
|
||||
|
||||
cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)
|
||||
stub_image_size(width: 100, height: 200)
|
||||
@@ -1113,8 +1112,7 @@ describe CookedPostProcessor do
|
||||
post = Fabricate(:post, raw: url)
|
||||
upload.update!(url: "https://test.s3.amazonaws.com/something.png")
|
||||
|
||||
post.custom_fields[Post::DOWNLOADED_IMAGES] = { "//image.com/avatar.png": upload.id }
|
||||
post.save_custom_fields
|
||||
PostHotlinkedMedia.create!(url: "//image.com/avatar.png", post: post, status: 'downloaded', upload: upload)
|
||||
|
||||
cooked_url = "https://localhost/secure-media-uploads/test.png"
|
||||
UrlHelper.expects(:cook_url).with(upload.url, secure: true).returns(cooked_url)
|
||||
@@ -1137,8 +1135,7 @@ describe CookedPostProcessor do
|
||||
|
||||
post = Fabricate(:post, raw: url)
|
||||
|
||||
post.custom_fields[Post::LARGE_IMAGES] = ["//image.com/avatar.png"]
|
||||
post.save_custom_fields
|
||||
PostHotlinkedMedia.create!(url: "//image.com/avatar.png", post: post, status: 'too_large')
|
||||
|
||||
cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)
|
||||
cpp.post_process
|
||||
@@ -1146,6 +1143,23 @@ describe CookedPostProcessor do
|
||||
expect(cpp.doc.to_s).to match(/<div class="large-image-placeholder">/)
|
||||
expect(cpp.doc.to_s).to include(I18n.t("upload.placeholders.too_large_humanized", max_size: "4 MB"))
|
||||
end
|
||||
|
||||
it "replaces broken image placeholder" do
|
||||
url = 'https://image.com/my-avatar'
|
||||
image_url = 'https://image.com/avatar.png'
|
||||
|
||||
Oneboxer.stubs(:onebox).with(url, anything).returns("<img class='onebox' src='#{image_url}' />")
|
||||
|
||||
post = Fabricate(:post, raw: url)
|
||||
|
||||
PostHotlinkedMedia.create!(url: "//image.com/avatar.png", post: post, status: 'download_failed')
|
||||
|
||||
cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)
|
||||
cpp.post_process
|
||||
|
||||
expect(cpp.doc.to_s).to have_tag("span.broken-image")
|
||||
expect(cpp.doc.to_s).to include(I18n.t("post.image_placeholder.broken"))
|
||||
end
|
||||
end
|
||||
|
||||
context "#post_process_oneboxes removes nofollow if add_rel_nofollow_to_user_content is disabled" do
|
||||
|
||||
Reference in New Issue
Block a user