Commit 34c1c8a3 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Minor fixes in the Env API endpoints

parent 1b72256f
...@@ -2,7 +2,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -2,7 +2,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
layout 'project' layout 'project'
before_action :authorize_read_environment! before_action :authorize_read_environment!
before_action :authorize_create_environment!, only: [:new, :create] before_action :authorize_create_environment!, only: [:new, :create]
before_action :authorize_update_environment!, only: [:edit, :destroy] before_action :authorize_update_environment!, only: [:edit, :update, :destroy]
before_action :environment, only: [:show, :edit, :update, :destroy] before_action :environment, only: [:show, :edit, :update, :destroy]
def index def index
......
...@@ -11,6 +11,10 @@ module API ...@@ -11,6 +11,10 @@ module API
detail 'This feature was introduced in GitLab 8.11.' detail 'This feature was introduced in GitLab 8.11.'
success Entities::Environment success Entities::Environment
end end
params do
optional :page, type: Integer, desc: 'Page number of the current request'
optional :per_page, type: Integer, desc: 'Number of items per page'
end
get ':id/environments' do get ':id/environments' do
authorize! :read_environment, user_project authorize! :read_environment, user_project
...@@ -51,7 +55,7 @@ module API ...@@ -51,7 +55,7 @@ module API
authorize! :update_environment, user_project authorize! :update_environment, user_project
environment = user_project.environments.find(params[:environment_id]) environment = user_project.environments.find(params[:environment_id])
update_params = declared(params, include_missing: false).extract!(:name, :external_url).to_h update_params = declared(params, include_missing: false).extract!(:name, :external_url).to_h
if environment.update(update_params) if environment.update(update_params)
present environment, with: Entities::Environment present environment, with: Entities::Environment
......
...@@ -14,6 +14,10 @@ describe API::API, api: true do ...@@ -14,6 +14,10 @@ describe API::API, api: true do
describe 'GET /projects/:id/environments' do describe 'GET /projects/:id/environments' do
context 'as member of the project' do context 'as member of the project' do
it_behaves_like 'a paginated resources' do
let(:request) { get api("/projects/#{project.id}/environments", user) }
end
it 'returns project environments' do it 'returns project environments' do
get api("/projects/#{project.id}/environments", user) get api("/projects/#{project.id}/environments", user)
...@@ -59,9 +63,13 @@ describe API::API, api: true do ...@@ -59,9 +63,13 @@ describe API::API, api: true do
context 'a non member' do context 'a non member' do
it 'rejects the request' do it 'rejects the request' do
post api("/projects/#{project.id}/environments", non_member) post api("/projects/#{project.id}/environments", non_member), name: 'gitlab.com'
expect(response).to have_http_status(400) expect(response).to have_http_status(404)
end
it 'returns a 400 when the required params are missing' do
post api("/projects/12345/environments", non_member), external_url: 'http://env.git.com'
end end
end end
end end
...@@ -109,5 +117,13 @@ describe API::API, api: true do ...@@ -109,5 +117,13 @@ describe API::API, api: true do
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('404 Not found')
end end
end end
context 'a non member' do
it 'rejects the request' do
delete api("/projects/#{project.id}/environments/#{environment.id}", non_member)
expect(response).to have_http_status(404)
end
end
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