diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-18 11:38:54 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-18 11:38:54 +0100 |
commit | f749fb7fe0574d07eeb38561b9af62754e518281 (patch) | |
tree | e8647693e60b73f12cd3b9dca0efb0aec1796fcb /lib/api | |
parent | b8607576c1bb25fe2cbb575b48becdf7bd4aaa8c (diff) | |
download | gitlab-ce-f749fb7fe0574d07eeb38561b9af62754e518281.tar.gz |
Improve style, add more tests
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/helpers.rb | 13 | ||||
-rw-r--r-- | lib/api/services.rb | 6 |
2 files changed, 6 insertions, 13 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index d6526ec4fdc..2c593dbb4ea 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -85,20 +85,11 @@ module API end end - def project_service - @project_service ||= user_project.find_or_initialize_service(params[:service_slug].underscore) + def project_service(project = user_project) + @project_service ||= project.find_or_initialize_service(params[:service_slug].underscore) @project_service || not_found!("Service") end - def service_by_slug(project, slug) - underscored_service = slug.underscore - - not_found!('Service') unless Service.available_services_names.include?(underscored_service) - service_method = "#{underscored_service}_service" - - service = project.public_send(service_method) - end - def service_attributes @service_attributes ||= project_service.fields.inject([]) do |arr, hash| arr << hash[:name].to_sym diff --git a/lib/api/services.rb b/lib/api/services.rb index 163187d450d..e3c6a998631 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -67,7 +67,9 @@ module API post ':id/services/:service_slug/trigger' do project = Project.find_with_namespace(params[:id]) || Project.find_by(id: params[:id]) - service = service_by_slug(project, params[:service_slug]) + not_found! unless project + + service = project_service(project) result = service.try(:active?) && service.try(:trigger, params) @@ -75,7 +77,7 @@ module API status result[:status] || 200 present result else - not_found!('Service') + not_found! end end end |