FIX: Post does not save if it contains a tag link

This commit is contained in:
Sam 2016-05-02 11:36:09 +10:00
parent ad2a3ec5bc
commit d25dc126f7
2 changed files with 13 additions and 1 deletions

View File

@ -3,6 +3,7 @@ require 'nokogiri'
require_dependency 'url_helper'
require_dependency 'excerpt_parser'
require_dependency 'post'
require_dependency 'discourse_tagging'
module PrettyText
@ -74,7 +75,7 @@ module PrettyText
if !is_tag && category = Category.query_from_hashtag_slug(text)
[category.url_with_id, text]
elsif is_tag && tag = TopicCustomField.find_by(name: TAGS_FIELD_NAME, value: text.gsub!("#{tag_postfix}", ''))
elsif is_tag && tag = TopicCustomField.find_by(name: DiscourseTagging::TAGS_FIELD_NAME, value: text.gsub!("#{tag_postfix}", ''))
["#{Discourse.base_url}/tags/#{tag.value}", text]
else
nil

View File

@ -421,4 +421,15 @@ HTML
end
end
describe "tag and category links" do
it "produces tag links" do
# TODO where is our tags table?
TopicCustomField.create!(topic_id: 1, name: DiscourseTagging::TAGS_FIELD_NAME, value: "known")
# TODO does it make sense to generate hashtags for tags that are missing in action?
expect(PrettyText.cook(" #unknown::tag #known::tag")).to match_html("<p> <span class=\"hashtag\">#unknown::tag</span> <a class=\"hashtag\" href=\"http://test.localhost/tags/known\">#<span>known</span></a></p>")
end
end
end