diff --git a/app/assets/javascripts/discourse/lib/link-tag-hashtag.js.es6 b/app/assets/javascripts/discourse/lib/link-tag-hashtag.js.es6 index e82de3eb0aa..ddb9e714db7 100644 --- a/app/assets/javascripts/discourse/lib/link-tag-hashtag.js.es6 +++ b/app/assets/javascripts/discourse/lib/link-tag-hashtag.js.es6 @@ -28,7 +28,7 @@ export function linkSeenTagHashtags($elem) { if ($hashtags.length) { const tagValues = $hashtags.map((_, hashtag) => { - return $(hashtag).text().substr(1).replace(`${TAG_HASHTAG_POSTFIX}`, ""); + return $(hashtag).text().substr(1).replace(TAG_HASHTAG_POSTFIX, ""); }); if (tagValues.length) { diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index ad2a442ab2a..c5b9a44c5d9 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -177,8 +177,8 @@ class TagsController < ::ApplicationController def check_hashtag tag_values = params[:tag_values].each(&:downcase!) - valid_tags = TopicCustomField.where(name: DiscourseTagging::TAGS_FIELD_NAME, value: tag_values).map do |tag| - { value: tag.value, url: "#{Discourse.base_url}/tags/#{tag.value}" } + valid_tags = Tag.where(name: tag_values).map do |tag| + { value: tag.name, url: tag.full_url } end.compact render json: { valid: valid_tags } diff --git a/app/models/tag.rb b/app/models/tag.rb index 5e3d6809205..78652a1871a 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -34,6 +34,10 @@ class Tag < ActiveRecord::Base def self.include_tags? SiteSetting.tagging_enabled && SiteSetting.show_filter_by_tag end + + def full_url + "#{Discourse.base_url}/tags/#{self.name}" + end end # == Schema Information diff --git a/spec/integration/tags_spec.rb b/spec/integration/tags_spec.rb new file mode 100644 index 00000000000..61f0bf6b3d0 --- /dev/null +++ b/spec/integration/tags_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +describe "Tags" do + before do + SiteSetting.tagging_enabled = true + end + + describe "checking tag hashtags" do + let(:tag) { Fabricate(:tag, name: 'test') } + + it "should return the right response" do + get "/tags/check.json", { tag_values: [tag.name] } + + expect(response).to be_success + + tag = JSON.parse(response.body)["valid"].first + expect(tag["value"]).to eq('test') + end + end +end