mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 17:53:44 +08:00
update response error when deleting tags (#5213)
This commit is contained in:
parent
4eeb6014f4
commit
ac04f5e0cc
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user