Complete implementation and add specs (#16615)

This commit is contained in:
Arit Amana 2022-02-16 18:10:58 -05:00 committed by GitHub
parent e0ecb56db4
commit 29bb7b4e75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 12 deletions

View file

@ -1,8 +1,8 @@
class CommentTag < LiquidTagBase
PARTIAL = "comments/liquid".freeze
REGISTRY_REGEXP = %r{#{URL.url}/\w+/comment/(?<comment_id>\w+)}
VALID_LINK_REGEXP = %r{#{URL.url}/\w+/comment/(?<comment_id>\w+)}
VALID_ID_REGEXP = /\A(?<comment_id>\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)

View file

@ -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

View file

@ -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

View file

@ -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)