FIX: extract links in post processor
when oneboxes are not cached or are refreshed they can introduce new links, these links must be extracted otherwise you can not follow them
This commit is contained in:
parent
cb6d1632ba
commit
22b2f5285c
|
@ -29,9 +29,16 @@ class CookedPostProcessor
|
|||
optimize_urls
|
||||
pull_hotlinked_images(bypass_bump)
|
||||
grant_badges
|
||||
extract_links
|
||||
end
|
||||
end
|
||||
|
||||
# onebox may have added some links, so extract them now
|
||||
def extract_links
|
||||
TopicLink.extract_from(@post)
|
||||
QuotedPost.extract_from(@post)
|
||||
end
|
||||
|
||||
def has_emoji?
|
||||
(@doc.css("img.emoji") - @doc.css(".quote img")).size > 0
|
||||
end
|
||||
|
|
|
@ -478,6 +478,15 @@ describe CookedPostProcessor do
|
|||
|
||||
end
|
||||
|
||||
context "extracts links" do
|
||||
let(:post) { Fabricate(:post, raw: "sam has a blog at https://samsaffron.com") }
|
||||
it "always re-extracts links on post process" do
|
||||
TopicLink.destroy_all
|
||||
CookedPostProcessor.new(post).post_process
|
||||
expect(TopicLink.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "grant badges" do
|
||||
context "emoji inside a quote" do
|
||||
let(:post) { Fabricate(:post, raw: "time to eat some sweet [quote]:candy:[/quote] mmmm") }
|
||||
|
|
|
@ -150,8 +150,9 @@ describe PostCreator do
|
|||
end
|
||||
|
||||
it 'extracts links from the post' do
|
||||
TopicLink.expects(:extract_from).with(instance_of(Post))
|
||||
create_post(raw: "this is a link to the best site at https://google.com")
|
||||
creator.create
|
||||
expect(TopicLink.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'queues up post processing job when saved' do
|
||||
|
|
|
@ -387,8 +387,12 @@ describe PostsController do
|
|||
end
|
||||
|
||||
it "extracts links from the new body" do
|
||||
TopicLink.expects(:extract_from).with(post)
|
||||
xhr :put, :update, update_params
|
||||
param = update_params
|
||||
param[:post][:raw] = 'I just visited this https://google.com so many cool links'
|
||||
|
||||
xhr :put, :update, param
|
||||
expect(response).to be_success
|
||||
expect(TopicLink.count).to eq(1)
|
||||
end
|
||||
|
||||
it "doesn't allow updating of deleted posts" do
|
||||
|
|
Loading…
Reference in New Issue