FIX: 'have_uploads' scope should include all uploads without multisite 'upload_path' prefix

FIX: ‘have_uploads’ scope should include all uploads without multisite ‘upload_path’ prefix

diff --git a/app/models/post.rb b/app/models/post.rb
index 98d7a82..f8228e5 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -113,7 +113,7 @@ class Post < ActiveRecord::Base
 
   scope :have_uploads, -> {
     where(
-      "(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND posts.cooked LIKE ?",
+      "(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND (posts.cooked LIKE ? OR posts.cooked LIKE '%/original/%' OR posts.cooked LIKE '%/optimized/%')",
       "%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%"
     )
   }
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index da3354e..21c2e65 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1341,4 +1341,18 @@ describe Post do
     end
   end
 
+  context "have_uploads" do
+    it "should find all posts with the upload" do
+      ids = []
+      ids << Fabricate(:post, cooked: "A post with upload <img src='/uploads/default/1/defghijklmno.png'>").id
+      ids << Fabricate(:post, cooked: "A post with optimized image <img src='/uploads/default/_optimized/601/961/defghijklmno.png'>").id
+      Fabricate(:post)
+      ids << Fabricate(:post, cooked: "A post with upload <img src='/uploads/default/original/1X/abc/defghijklmno.png'>").id
+      ids << Fabricate(:post, cooked: "A post with upload link <a href='https://cdn.example.com/original/1X/abc/defghijklmno.png'>").id
+      ids << Fabricate(:post, cooked: "A post with optimized image <img src='https://cdn.example.com/bucket/optimized/1X/abc/defghijklmno.png'>").id
+      Fabricate(:post, cooked: "A post with external link <a href='https://example.com/wp-content/uploads/abcdef.gif'>")
+      expect(Post.have_uploads.order(:id).pluck(:id)).to eq(ids)
+    end
+  end
+
 end

GitHub sha: 8e40c35e