diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb
index 4030df5d592..9d5c81451c3 100644
--- a/app/models/post_analyzer.rb
+++ b/app/models/post_analyzer.rb
@@ -32,15 +32,15 @@ class PostAnalyzer
end
limit = SiteSetting.max_oneboxes_per_post
- result = Oneboxer.apply(cooked) do |url|
- next if limit <= 0
- limit -= 1
-
- @onebox_urls << url
+ result = Oneboxer.apply(cooked, extra_paths: ".inline-onebox-loading") do |url, element|
if opts[:invalidate_oneboxes]
Oneboxer.invalidate(url)
InlineOneboxer.invalidate(url)
end
+ next if element["class"] != Oneboxer::ONEBOX_CSS_CLASS
+ next if limit <= 0
+ limit -= 1
+ @onebox_urls << url
onebox = Oneboxer.cached_onebox(url)
@found_oneboxes = true if onebox.present?
onebox
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index f338b776caf..2168d832dc5 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1228,6 +1228,52 @@ describe Post do
post.reload
post.rebake!
end
+
+ it "uses inline onebox cache by default" do
+ Jobs.run_immediately!
+ stub_request(:get, "http://testonebox.com/vvf").to_return(status: 200, body: <<~HTML)
+
+ hello this is Testonebox!
+
+ HTML
+ post = create_post(raw: <<~POST).reload
+ hello inline onebox http://testonebox.com/vvf
+ POST
+ expect(post.cooked).to include("hello this is Testonebox!")
+
+ stub_request(:get, "http://testonebox.com/vvf").to_return(status: 200, body: <<~HTML)
+
+ hello this is updated Testonebox!
+
+ HTML
+ post.rebake!
+ expect(post.reload.cooked).to include("hello this is Testonebox!")
+ ensure
+ InlineOneboxer.invalidate("http://testonebox.com/vvf")
+ end
+
+ it "passing invalidate_oneboxes: true ignores inline onebox cache" do
+ Jobs.run_immediately!
+ stub_request(:get, "http://testonebox.com/vvf22").to_return(status: 200, body: <<~HTML)
+
+ hello this is Testonebox!
+
+ HTML
+ post = create_post(raw: <<~POST).reload
+ hello inline onebox http://testonebox.com/vvf22
+ POST
+ expect(post.cooked).to include("hello this is Testonebox!")
+
+ stub_request(:get, "http://testonebox.com/vvf22").to_return(status: 200, body: <<~HTML)
+
+ hello this is updated Testonebox!
+
+ HTML
+ post.rebake!(invalidate_oneboxes: true)
+ expect(post.reload.cooked).to include("hello this is updated Testonebox!")
+ ensure
+ InlineOneboxer.invalidate("http://testonebox.com/vvf22")
+ end
end
describe "#set_owner" do