Commit 0d014feb authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add delete feature to variables API

parent a692ce1c
......@@ -57,6 +57,18 @@ module API
present variable, with: Entities::Variable
end
# Delete existing variable of a project
#
# Parameters:
# id (required) - The ID of a project
# variable_id (required) - The ID of a variable
# Exanoke Reqyest:
# DELETE /projects/:id/variables/:variable_id
delete ':id/variables/:variable_id' do
variable = user_project.variables.where(id: params[:variable_id].to_i).first
variable.destroy
end
end
end
end
......@@ -101,11 +101,38 @@ describe API::API, api: true do
end
context 'unauthorized user' do
it 'should not return project variable details' do
it 'should not update variable' do
put api("/projects/#{project.id}/variables/#{variable.id}")
expect(response.status).to eq(401)
end
end
end
describe 'DELETE /projects/:id/variables/:variable_id' do
context 'authorized user with proper permissions' do
it 'should delete variable' do
expect do
delete api("/projects/#{project.id}/variables/#{variable.id}", user)
end.to change{project.variables.count}.by(-1)
expect(response.status).to eq(200)
end
end
context 'authorized user with invalid permissions' do
it 'should not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.id}", user2)
expect(response.status).to eq(403)
end
end
context 'unauthorized user' do
it 'should not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.id}")
expect(response.status).to eq(401)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment