FIX: Remove tag plugin code from tag hashtag check.

This commit is contained in:
Guo Xiang Tan 2016-08-02 10:54:32 +08:00
parent 3f4f1ee032
commit bf683178a8
4 changed files with 27 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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