From 4e0533a20beba76055214c6d98e0d0ce42b7bb6c Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 10 Oct 2018 13:39:03 +0300 Subject: [PATCH] FIX: Generate Onebox for posts of type moderator_action. (#6466) --- lib/oneboxer.rb | 6 +++++- spec/components/oneboxer_spec.rb | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb index fee360a87f9..db0a4da32ca 100644 --- a/lib/oneboxer.rb +++ b/lib/oneboxer.rb @@ -26,6 +26,10 @@ module Oneboxer @force_get_hosts ||= ['http://us.battle.net'] end + def self.allowed_post_types + @allowed_post_types ||= [Post.types[:regular], Post.types[:moderator_action]] + end + def self.preview(url, options = nil) options ||= {} invalidate(url) if options[:invalidate_oneboxes] @@ -197,7 +201,7 @@ module Oneboxer topic.posts.where(post_number: post_number).first : topic.ordered_posts.first - return if !post || post.hidden || post.post_type != Post.types[:regular] + return if !post || post.hidden || !allowed_post_types.include?(post.post_type) if post_number > 1 && current_topic&.id == topic.id excerpt = post.excerpt(SiteSetting.post_onebox_maxlength) diff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rb index b3524267ed0..b9b4215c0bf 100644 --- a/spec/components/oneboxer_spec.rb +++ b/spec/components/oneboxer_spec.rb @@ -35,10 +35,11 @@ describe Oneboxer do replier = Fabricate(:user) - public_post = Fabricate(:post, raw: "This post has an emoji :+1:") - public_topic = public_post.topic - public_reply = Fabricate(:post, topic: public_topic, post_number: 2, user: replier) - public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true) + public_post = Fabricate(:post, raw: "This post has an emoji :+1:") + public_topic = public_post.topic + public_reply = Fabricate(:post, topic: public_topic, post_number: 2, user: replier) + public_hidden = Fabricate(:post, topic: public_topic, post_number: 3, hidden: true) + public_moderator_action = Fabricate(:post, topic: public_topic, post_number: 4, user: staff, post_type: Post.types[:moderator_action]) user = public_post.user public_category = public_topic.category @@ -57,6 +58,11 @@ describe Oneboxer do expect(onebox).to include(%{data-post="2"}) expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny")) + onebox = preview(public_moderator_action.url, user, public_category) + expect(onebox).to include(public_moderator_action.excerpt) + expect(onebox).to include(%{data-post="4"}) + expect(onebox).to include(PrettyText.avatar_img(staff.avatar_template, "tiny")) + onebox = preview(public_reply.url, user, public_category, public_topic) expect(onebox).not_to include(public_topic.title) expect(onebox).to include(replier.avatar_template.sub("{size}", "40"))