Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add spec for removing and re-adding hotlinked images

David Taylordf39e372d707
diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb
index 27235a1903f..ab947c5dc9b 100644
--- a/spec/jobs/pull_hotlinked_images_spec.rb
+++ b/spec/jobs/pull_hotlinked_images_spec.rb
@@ -74,6 +74,25 @@ describe Jobs::PullHotlinkedImages do
expect(post.post_uploads.count).to eq(0)
end
+ it 'replaces images again after edit' do
+ post = Fabricate(:post, raw: "<img src='#{image_url}'>")
+
+ expect do
+ post.rebake!
+ end.to change { Upload.count }.by(1)
+
+ expect(post.reload.raw).to eq("![](#{Upload.last.short_url})")
+
+ # Post raw is updated back to the old value (e.g. by wordpress integration)
+ post.update(raw: "<img src='#{image_url}'>")
+
+ expect do
+ post.rebake!
+ end.to change { Upload.count }.by(0) # We alread have the upload
+
+ expect(post.reload.raw).to eq("![](#{Upload.last.short_url})")
+ end
+
it 'replaces encoded image urls' do
post = Fabricate(:post, raw: "<img src='#{encoded_image_url}'>")
expect do