From 1b95c8bff351f6718ec31ac1de1e48c57bc95d44 Mon Sep 17 00:00:00 2001 From: Nihad Abbasov Date: Wed, 25 Jul 2012 02:18:30 -0700 Subject: [PATCH] API: ability to get project by id --- lib/api/helpers.rb | 3 ++- spec/api/projects_spec.rb | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index e7b9a417..4dfe35f4 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -5,7 +5,8 @@ module Gitlab end def user_project - @project ||= current_user.projects.find_by_code(params[:id]) + @project ||= current_user.projects.find_by_id(params[:id]) || + current_user.projects.find_by_code(params[:id]) end def authenticate! diff --git a/spec/api/projects_spec.rb b/spec/api/projects_spec.rb index 9998ee50..92a25543 100644 --- a/spec/api/projects_spec.rb +++ b/spec/api/projects_spec.rb @@ -25,11 +25,17 @@ describe Gitlab::API do describe "GET /projects/:id" do it "should return a project by id" do - get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" + get "#{api_prefix}/projects/#{project.id}?private_token=#{user.private_token}" response.status.should == 200 json_response['name'].should == project.name json_response['owner']['email'].should == user.email end + + it "should return a project by code name" do + get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" + response.status.should == 200 + json_response['name'].should == project.name + end end describe "GET /projects/:id/repository/branches" do