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

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

Before the recent refactor, this would fail. https://meta.discourse.org/t/154184

diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb
index 27235a1..ab947c5 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

GitHub sha: df39e372

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/pullhotlinkedimages-does-not-replace-images-again-after-post-is-edited/154184/8