mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Optionally invalidate onebox in PostAnalyzer#cook
This commit is contained in:
parent
6a9484155d
commit
ef76e18215
3 changed files with 38 additions and 5 deletions
|
@ -20,7 +20,8 @@ class PostAnalyzer
|
|||
# wait for the post processor.
|
||||
dirty = false
|
||||
result = Oneboxer.apply(cooked) do |url, elem|
|
||||
Oneboxer.render_from_cache(url)
|
||||
Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes]
|
||||
Oneboxer.onebox url
|
||||
end
|
||||
|
||||
cooked = result.to_html if result.changed?
|
||||
|
|
|
@ -2,10 +2,39 @@ require 'spec_helper'
|
|||
|
||||
describe PostAnalyzer do
|
||||
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:default_topic_id) { topic.id }
|
||||
let(:post_args) do
|
||||
{user: topic.user, topic: topic}
|
||||
let(:default_topic_id) { 12 }
|
||||
|
||||
describe '#cook' do
|
||||
let(:post_analyzer) { described_class.new nil, nil }
|
||||
|
||||
let(:args) { [raw, options] }
|
||||
let(:raw) { "Here's a tweet:\n#{url}" }
|
||||
let(:options) { {} }
|
||||
|
||||
let(:url) {
|
||||
'https://twitter.com/evil_trout/status/345954894420787200'
|
||||
}
|
||||
|
||||
before { Oneboxer.stubs(:onebox) }
|
||||
|
||||
it 'fetches the onebox for any urls in the post' do
|
||||
Oneboxer.expects(:onebox).with url
|
||||
post_analyzer.cook(*args)
|
||||
end
|
||||
|
||||
it 'does not invalidate the onebox cache' do
|
||||
Oneboxer.expects(:invalidate).with(url).never
|
||||
post_analyzer.cook(*args)
|
||||
end
|
||||
|
||||
context 'when invalidating oneboxes' do
|
||||
let(:options) {{ invalidate_oneboxes: true }}
|
||||
|
||||
it 'invalidates the oneboxes for urls in the post' do
|
||||
Oneboxer.expects(:invalidate).with url
|
||||
post_analyzer.cook(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "links" do
|
||||
|
@ -115,6 +144,7 @@ describe PostAnalyzer do
|
|||
end
|
||||
|
||||
it "finds links from markdown" do
|
||||
Oneboxer.stubs :onebox
|
||||
post_analyzer = PostAnalyzer.new(raw_post_one_link_md, default_topic_id)
|
||||
post_analyzer.link_count.should == 1
|
||||
end
|
||||
|
|
|
@ -2,6 +2,8 @@ require 'spec_helper'
|
|||
require_dependency 'post_destroyer'
|
||||
|
||||
describe Post do
|
||||
before { Oneboxer.stubs :onebox }
|
||||
|
||||
# Help us build a post with a raw body
|
||||
def post_with_body(body, user=nil)
|
||||
args = post_args.merge(raw: body)
|
||||
|
|
Loading…
Reference in a new issue