Commit d44653da authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add some fixes after review

parent e0ec69d9
...@@ -32,6 +32,10 @@ module Ci ...@@ -32,6 +32,10 @@ module Ci
trigger_requests.last trigger_requests.last
end end
def last_used
last_trigger_request.try(:created_at)
end
def short_token def short_token
token[0...10] token[0...10]
end end
......
...@@ -367,13 +367,7 @@ module API ...@@ -367,13 +367,7 @@ module API
end end
class Trigger < Grape::Entity class Trigger < Grape::Entity
expose :token, :created_at, :updated_at, :deleted_at expose :token, :created_at, :updated_at, :deleted_at, :last_used
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
end end
end end
end end
...@@ -73,10 +73,10 @@ module API ...@@ -73,10 +73,10 @@ module API
authenticate! authenticate!
authorize_admin_project authorize_admin_project
triggers = user_project.triggers.where(token: params[:token]) trigger = user_project.triggers.find_by(token: params[:token].to_s)
return not_found!('Trigger') if triggers.empty? return not_found!('Trigger') unless trigger
present triggers.first, with: Entities::Trigger present trigger, with: Entities::Trigger
end end
# Create trigger # Create trigger
...@@ -89,8 +89,7 @@ module API ...@@ -89,8 +89,7 @@ module API
authenticate! authenticate!
authorize_admin_project authorize_admin_project
trigger = user_project.triggers.new trigger = user_project.triggers.create
trigger.save
present trigger, with: Entities::Trigger present trigger, with: Entities::Trigger
end end
...@@ -106,7 +105,7 @@ module API ...@@ -106,7 +105,7 @@ module API
authenticate! authenticate!
authorize_admin_project 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 return not_found!('Trigger') unless trigger
trigger.destroy trigger.destroy
......
...@@ -105,7 +105,7 @@ describe API::API do ...@@ -105,7 +105,7 @@ describe API::API do
end end
end end
context 'unauthentikated user' do context 'unauthenticated user' do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers") get api("/projects/#{project.id}/triggers")
...@@ -123,7 +123,7 @@ describe API::API do ...@@ -123,7 +123,7 @@ describe API::API do
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
end 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) get api("/projects/#{project.id}/triggers/abcdef012345", user)
expect(response.status).to eq(404) expect(response.status).to eq(404)
...@@ -138,7 +138,7 @@ describe API::API do ...@@ -138,7 +138,7 @@ describe API::API do
end end
end end
context 'unauthentikated user' do context 'unauthenticated user' do
it 'should not return triggers list' do it 'should not return triggers list' do
get api("/projects/#{project.id}/triggers/#{trigger.token}") get api("/projects/#{project.id}/triggers/#{trigger.token}")
...@@ -167,7 +167,7 @@ describe API::API do ...@@ -167,7 +167,7 @@ describe API::API do
end end
end end
context 'unauthentikated user' do context 'unauthenticated user' do
it 'should not create trigger' do it 'should not create trigger' do
post api("/projects/#{project.id}/triggers") post api("/projects/#{project.id}/triggers")
...@@ -185,7 +185,7 @@ describe API::API do ...@@ -185,7 +185,7 @@ describe API::API do
expect(response.status).to eq(200) expect(response.status).to eq(200)
end 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) delete api("/projects/#{project.id}/triggers/abcdef012345", user)
expect(response.status).to eq(404) expect(response.status).to eq(404)
...@@ -200,7 +200,7 @@ describe API::API do ...@@ -200,7 +200,7 @@ describe API::API do
end end
end end
context 'unauthentikated user' do context 'unauthenticated user' do
it 'should not delete trigger' do it 'should not delete trigger' do
delete api("/projects/#{project.id}/triggers/#{trigger.token}") delete api("/projects/#{project.id}/triggers/#{trigger.token}")
......
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