From 621f7e0a658c35e40178d7c0ac1bff526621504d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 14 Mar 2016 14:48:30 -0400 Subject: [PATCH] FIX: Replace emoji in local oneboxes --- lib/onebox/engine/discourse_local_onebox.rb | 2 +- lib/onebox/templates/discourse_topic_onebox.hbs | 2 +- .../onebox/engine/discourse_local_onebox_spec.rb | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/onebox/engine/discourse_local_onebox.rb b/lib/onebox/engine/discourse_local_onebox.rb index 6708c98d8..9ac748e27 100644 --- a/lib/onebox/engine/discourse_local_onebox.rb +++ b/lib/onebox/engine/discourse_local_onebox.rb @@ -93,7 +93,7 @@ module Onebox quote = post.excerpt(SiteSetting.post_onebox_maxlength) args = { original_url: url, - title: topic.title, + title: PrettyText.unescape_emoji(topic.title), avatar: PrettyText.avatar_img(topic.user.avatar_template, 'tiny'), posts_count: topic.posts_count, last_post: FreedomPatches::Rails4.time_ago_in_words(topic.last_posted_at, false, scope: :'datetime.distance_in_words_verbose'), diff --git a/lib/onebox/templates/discourse_topic_onebox.hbs b/lib/onebox/templates/discourse_topic_onebox.hbs index a070f974f..b9ca0aff5 100644 --- a/lib/onebox/templates/discourse_topic_onebox.hbs +++ b/lib/onebox/templates/discourse_topic_onebox.hbs @@ -2,7 +2,7 @@
{{{avatar}}} - {{title}} {{{category_html}}} + {{{title}}} {{{category_html}}}
{{{quote}}}
diff --git a/spec/components/onebox/engine/discourse_local_onebox_spec.rb b/spec/components/onebox/engine/discourse_local_onebox_spec.rb index 627eaba4b..3646e9729 100644 --- a/spec/components/onebox/engine/discourse_local_onebox_spec.rb +++ b/spec/components/onebox/engine/discourse_local_onebox_spec.rb @@ -60,11 +60,16 @@ describe Onebox::Engine::DiscourseLocalOnebox do end it "returns a link if not allowed to see the post" do - url = "#{topic.url}" + url = topic.url Guardian.any_instance.stubs(:can_see?).returns(false) expect(Onebox.preview(url).to_s).to eq("#{url}") end + it "replaces emoji in the title" do + topic.update_column(:title, "Who wants to eat a :hamburger:") + expect(Onebox.preview(topic.url).to_s).to match(/hamburger.png/) + end + it "returns some onebox goodness if post exists and can be seen" do SiteSetting.external_system_avatars_enabled = false url = "#{topic.url}" @@ -94,7 +99,7 @@ describe Onebox::Engine::DiscourseLocalOnebox do expect(html).to eq("") end end - + context "When deployed to a subfolder" do let(:base_url) { "http://test.localhost/subfolder" } let(:base_uri) { "/subfolder" }