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

This commit is contained in:
Vinoth Kannan 2019-04-15 01:54:55 +05:30
parent 70fef8e0c3
commit 8e40c35eb8
2 changed files with 15 additions and 1 deletions

View File

@ -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}/%"
)
}

View File

@ -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