From 29bb7b4e75952491732f9355070fecd6927aed62 Mon Sep 17 00:00:00 2001 From: Arit Amana <32520970+msarit@users.noreply.github.com> Date: Wed, 16 Feb 2022 18:10:58 -0500 Subject: [PATCH] Complete implementation and add specs (#16615) --- app/liquid_tags/comment_tag.rb | 6 ++---- app/liquid_tags/forem_tag.rb | 1 + spec/liquid_tags/forem_tag_spec.rb | 9 +++++++++ spec/liquid_tags/unified_embed/registry_spec.rb | 8 -------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/liquid_tags/comment_tag.rb b/app/liquid_tags/comment_tag.rb index f9d91bfa5..d8d9cab86 100644 --- a/app/liquid_tags/comment_tag.rb +++ b/app/liquid_tags/comment_tag.rb @@ -1,8 +1,8 @@ class CommentTag < LiquidTagBase PARTIAL = "comments/liquid".freeze - REGISTRY_REGEXP = %r{#{URL.url}/\w+/comment/(?\w+)} + VALID_LINK_REGEXP = %r{#{URL.url}/\w+/comment/(?\w+)} VALID_ID_REGEXP = /\A(?\w+)\Z/ - REGEXP_OPTIONS = [REGISTRY_REGEXP, VALID_ID_REGEXP].freeze + REGEXP_OPTIONS = [VALID_LINK_REGEXP, VALID_ID_REGEXP].freeze def initialize(_tag_name, id_code, _parse_context) super @@ -35,5 +35,3 @@ end Liquid::Template.register_tag("comment", CommentTag) # kept for compatibility with existing comments embeds on DEV Liquid::Template.register_tag("devcomment", CommentTag) - -UnifiedEmbed.register(CommentTag, regexp: CommentTag::REGISTRY_REGEXP) diff --git a/app/liquid_tags/forem_tag.rb b/app/liquid_tags/forem_tag.rb index 9353609a4..44f2bb0e7 100644 --- a/app/liquid_tags/forem_tag.rb +++ b/app/liquid_tags/forem_tag.rb @@ -20,6 +20,7 @@ module ForemTag def self.determine_klass(link) return ListingTag if link.start_with?("#{URL.url}/listings/") return TagTag if link.start_with?("#{URL.url}/t/") + return CommentTag if link.include?("/comment/") process_other_link_types(link) end diff --git a/spec/liquid_tags/forem_tag_spec.rb b/spec/liquid_tags/forem_tag_spec.rb index 6ee39a6ff..7eb408649 100644 --- a/spec/liquid_tags/forem_tag_spec.rb +++ b/spec/liquid_tags/forem_tag_spec.rb @@ -4,6 +4,9 @@ RSpec.describe ForemTag do subject(:forem_tag) { described_class } let(:article) { create(:article) } + let(:comment) do + create(:comment, commentable: article, user: user, body_markdown: "TheComment") + end let(:listing) { create(:listing) } let(:organization) { create(:organization) } let(:parse_context) { { source: article, user: user } } @@ -23,6 +26,12 @@ RSpec.describe ForemTag do end describe "determine_klass" do + it "returns CommentTag if link contains /comment/ (connotes comment url)" do + comment_url = URL.url + comment.path + + expect(described_class.determine_klass(comment_url)).to eq(CommentTag) + end + it "returns LinkTag if link is general Forem link" do link_url = URL.url + article.path diff --git a/spec/liquid_tags/unified_embed/registry_spec.rb b/spec/liquid_tags/unified_embed/registry_spec.rb index 7cbfe167c..e57a62ef9 100644 --- a/spec/liquid_tags/unified_embed/registry_spec.rb +++ b/spec/liquid_tags/unified_embed/registry_spec.rb @@ -4,9 +4,6 @@ RSpec.describe UnifiedEmbed::Registry do subject(:unified_embed) { described_class } let(:article) { create(:article) } - let(:comment) do - create(:comment, commentable: article, user: user, body_markdown: "TheComment") - end let(:listing) { create(:listing) } let(:organization) { create(:organization) } let(:podcast) { create(:podcast) } @@ -127,11 +124,6 @@ RSpec.describe UnifiedEmbed::Registry do .to eq(CodepenTag) end - it "returns CommentTag for a Forem comment url" do - expect(described_class.find_liquid_tag_for(link: "#{URL.url}/#{user.username}/comment/#{comment.id_code}")) - .to eq(CommentTag) - end - it "returns DotnetFiddleTag for a dotnetfiddle url" do expect(described_class.find_liquid_tag_for(link: "https://dotnetfiddle.net/PmoDip")) .to eq(DotnetFiddleTag)