update response error when deleting tags (#5213)

This commit is contained in:
Eleanor Demis 2017-09-30 07:31:32 -07:00 committed by Régis Hanol
parent 4eeb6014f4
commit ac04f5e0cc
2 changed files with 30 additions and 1 deletions

View File

@ -100,8 +100,11 @@ class TagsController < ::ApplicationController
def destroy
guardian.ensure_can_admin_tags!
tag_name = params[:tag_id]
tag = Tag.find_by_name(tag_name)
raise Discourse::NotFound if tag.nil?
TopicCustomField.transaction do
Tag.find_by_name(tag_name).destroy
tag.destroy
StaffActionLogger.new(current_user).log_custom('deleted_tag', subject: tag_name)
end
render json: success_json

View File

@ -190,4 +190,30 @@ describe TagsController do
end
end
end
describe 'destroy' do
context 'tagging enabled' do
before do
log_in(:admin)
SiteSetting.tagging_enabled = true
end
context 'with an existent tag name' do
it 'deletes the tag' do
tag = Fabricate(:tag)
delete :destroy, params: { tag_id: tag.name }, format: :json
expect(response).to be_success
end
end
context 'with a nonexistent tag name' do
it 'returns a tag not found message' do
delete :destroy, params: { tag_id: 'idontexist' }, format: :json
expect(response).not_to be_success
json = ::JSON.parse(response.body)
expect(json['error_type']).to eq('not_found')
end
end
end
end
end