Fixes #3842 - Removing tags from tickets return HTTP 201

This commit is contained in:
Mantas 2021-11-08 16:55:01 +02:00 committed by Mantas Masalskis
parent 1d2549b41f
commit 92cd364ec2
2 changed files with 33 additions and 5 deletions

View file

@ -53,7 +53,7 @@ class TagsController < ApplicationController
item: params[:item], item: params[:item],
) )
if success if success
render json: success, status: :created render json: success
else else
render json: success.errors, status: :unprocessable_entity render json: success.errors, status: :unprocessable_entity
end end

View file

@ -4,15 +4,43 @@ require 'rails_helper'
RSpec.describe Tag, type: :request do RSpec.describe Tag, type: :request do
describe 'request handling' do describe 'request handling', authenticated_as: :agent do
let(:agent) { create(:agent) } let(:agent) { create(:agent) }
context 'tag search' do context 'tag adding' do
before do it 'returns created' do
authenticated_as(agent) post '/api/v1/tags/add', params: { object: 'Foo', item: 'bar', o_id: 1 }
expect(response).to have_http_status(:created)
end end
it 'deletes tag' do
post '/api/v1/tags/add', params: { object: 'Foo', item: 'bar', o_id: 1 }
expect(described_class.tag_list({ object: 'Foo', item: 'bar', o_id: 1 })).to be_present
end
end
context 'tag removal', authenticated_as: :agent do
before do
described_class.tag_add(object: 'Foo', item: 'bar', o_id: 1, created_by_id: 1)
end
it 'returns ok' do
delete '/api/v1/tags/remove', params: { object: 'Foo', item: 'bar', o_id: 1 }
expect(response).to have_http_status(:ok)
end
it 'deletes tag' do
delete '/api/v1/tags/remove', params: { object: 'Foo', item: 'bar', o_id: 1 }
expect(described_class.tag_list({ object: 'Foo', item: 'bar', o_id: 1 })).to be_empty
end
end
context 'tag search' do
let!(:tags) do let!(:tags) do
[ [
Tag::Item.lookup_by_name_and_create('foobar'), Tag::Item.lookup_by_name_and_create('foobar'),