FIX: Remove post/topic image_url on post edits
- resets image_url when image is removed from first post on edit - excludes onebox icons from being featured as topic/post images
This commit is contained in:
parent
f029e2eaf6
commit
0fd39cc511
|
@ -216,7 +216,9 @@ class CookedPostProcessor
|
||||||
# minus emojis
|
# minus emojis
|
||||||
@doc.css("img.emoji") -
|
@doc.css("img.emoji") -
|
||||||
# minus images inside quotes
|
# minus images inside quotes
|
||||||
@doc.css(".quote img")
|
@doc.css(".quote img") -
|
||||||
|
# minus onebox site icons
|
||||||
|
@doc.css("img.site-icon")
|
||||||
end
|
end
|
||||||
|
|
||||||
def oneboxed_images
|
def oneboxed_images
|
||||||
|
@ -488,7 +490,11 @@ class CookedPostProcessor
|
||||||
|
|
||||||
def update_post_image
|
def update_post_image
|
||||||
img = extract_images_for_post.first
|
img = extract_images_for_post.first
|
||||||
return if img.blank?
|
if img.blank?
|
||||||
|
@post.update_column(:image_url, nil) if @post.image_url
|
||||||
|
@post.topic.update_column(:image_url, nil) if @post.topic.image_url
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if img["src"].present?
|
if img["src"].present?
|
||||||
@post.update_column(:image_url, img["src"][0...255]) # post
|
@post.update_column(:image_url, img["src"][0...255]) # post
|
||||||
|
|
|
@ -774,6 +774,21 @@ describe CookedPostProcessor do
|
||||||
post.topic.reload
|
post.topic.reload
|
||||||
expect(post.topic.image_url).to be_present
|
expect(post.topic.image_url).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "removes image if post is edited and no longer has an image" do
|
||||||
|
FastImage.stubs(:size)
|
||||||
|
|
||||||
|
cpp.post_process
|
||||||
|
post.topic.reload
|
||||||
|
expect(post.topic.image_url).to be_present
|
||||||
|
expect(post.image_url).to be_present
|
||||||
|
|
||||||
|
post.update!(raw: "This post no longer has an image.")
|
||||||
|
CookedPostProcessor.new(post).post_process
|
||||||
|
post.topic.reload
|
||||||
|
expect(post.topic.image_url).not_to be_present
|
||||||
|
expect(post.image_url).not_to be_present
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "post image" do
|
context "post image" do
|
||||||
|
|
Loading…
Reference in New Issue