FIX: 'have_uploads' scope should include all uploads without multisite 'upload_path' prefix
This commit is contained in:
parent
70fef8e0c3
commit
8e40c35eb8
|
@ -113,7 +113,7 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
scope :have_uploads, -> {
|
scope :have_uploads, -> {
|
||||||
where(
|
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}/%"
|
"%/uploads/#{RailsMultisite::ConnectionManagement.current_db}/%"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1341,4 +1341,18 @@ describe Post do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue