Add some fixes after review
This commit is contained in:
parent
e0ec69d919
commit
d44653da1f
4 changed files with 16 additions and 19 deletions
|
@ -32,6 +32,10 @@ module Ci
|
|||
trigger_requests.last
|
||||
end
|
||||
|
||||
def last_used
|
||||
last_trigger_request.try(:created_at)
|
||||
end
|
||||
|
||||
def short_token
|
||||
token[0...10]
|
||||
end
|
||||
|
|
|
@ -367,13 +367,7 @@ module API
|
|||
end
|
||||
|
||||
class Trigger < Grape::Entity
|
||||
expose :token, :created_at, :updated_at, :deleted_at
|
||||
expose :last_used do |repo_obj, _options|
|
||||
if repo_obj.respond_to?(:last_trigger_request)
|
||||
request = repo_obj.last_trigger_request
|
||||
request.created_at if request
|
||||
end
|
||||
end
|
||||
expose :token, :created_at, :updated_at, :deleted_at, :last_used
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,10 +73,10 @@ module API
|
|||
authenticate!
|
||||
authorize_admin_project
|
||||
|
||||
triggers = user_project.triggers.where(token: params[:token])
|
||||
return not_found!('Trigger') if triggers.empty?
|
||||
trigger = user_project.triggers.find_by(token: params[:token].to_s)
|
||||
return not_found!('Trigger') unless trigger
|
||||
|
||||
present triggers.first, with: Entities::Trigger
|
||||
present trigger, with: Entities::Trigger
|
||||
end
|
||||
|
||||
# Create trigger
|
||||
|
@ -89,8 +89,7 @@ module API
|
|||
authenticate!
|
||||
authorize_admin_project
|
||||
|
||||
trigger = user_project.triggers.new
|
||||
trigger.save
|
||||
trigger = user_project.triggers.create
|
||||
|
||||
present trigger, with: Entities::Trigger
|
||||
end
|
||||
|
@ -106,7 +105,7 @@ module API
|
|||
authenticate!
|
||||
authorize_admin_project
|
||||
|
||||
trigger = user_project.triggers.where(token: params[:token]).first
|
||||
trigger = user_project.triggers.find_by(token: params[:token].to_s)
|
||||
return not_found!('Trigger') unless trigger
|
||||
|
||||
trigger.destroy
|
||||
|
|
|
@ -105,7 +105,7 @@ describe API::API do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unauthentikated user' do
|
||||
context 'unauthenticated user' do
|
||||
it 'should not return triggers list' do
|
||||
get api("/projects/#{project.id}/triggers")
|
||||
|
||||
|
@ -123,7 +123,7 @@ describe API::API do
|
|||
expect(json_response).to be_a(Hash)
|
||||
end
|
||||
|
||||
it 'should responde with 404 Not Found if requesting non-existing trigger' do
|
||||
it 'should respond with 404 Not Found if requesting non-existing trigger' do
|
||||
get api("/projects/#{project.id}/triggers/abcdef012345", user)
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
|
@ -138,7 +138,7 @@ describe API::API do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unauthentikated user' do
|
||||
context 'unauthenticated user' do
|
||||
it 'should not return triggers list' do
|
||||
get api("/projects/#{project.id}/triggers/#{trigger.token}")
|
||||
|
||||
|
@ -167,7 +167,7 @@ describe API::API do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unauthentikated user' do
|
||||
context 'unauthenticated user' do
|
||||
it 'should not create trigger' do
|
||||
post api("/projects/#{project.id}/triggers")
|
||||
|
||||
|
@ -185,7 +185,7 @@ describe API::API do
|
|||
expect(response.status).to eq(200)
|
||||
end
|
||||
|
||||
it 'should responde with 404 Not Found if requesting non-existing trigger' do
|
||||
it 'should respond with 404 Not Found if requesting non-existing trigger' do
|
||||
delete api("/projects/#{project.id}/triggers/abcdef012345", user)
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
|
@ -200,7 +200,7 @@ describe API::API do
|
|||
end
|
||||
end
|
||||
|
||||
context 'unauthentikated user' do
|
||||
context 'unauthenticated user' do
|
||||
it 'should not delete trigger' do
|
||||
delete api("/projects/#{project.id}/triggers/#{trigger.token}")
|
||||
|
||||
|
|
Loading…
Reference in a new issue