Commit 1b95c8bff351f6718ec31ac1de1e48c57bc95d44
1 parent
92d98f5a
Exists in
master
and in
4 other branches
API: ability to get project by id
Showing
2 changed files
with
9 additions
and
2 deletions
Show diff stats
lib/api/helpers.rb
@@ -5,7 +5,8 @@ module Gitlab | @@ -5,7 +5,8 @@ module Gitlab | ||
5 | end | 5 | end |
6 | 6 | ||
7 | def user_project | 7 | def user_project |
8 | - @project ||= current_user.projects.find_by_code(params[:id]) | 8 | + @project ||= current_user.projects.find_by_id(params[:id]) || |
9 | + current_user.projects.find_by_code(params[:id]) | ||
9 | end | 10 | end |
10 | 11 | ||
11 | def authenticate! | 12 | def authenticate! |
spec/api/projects_spec.rb
@@ -25,11 +25,17 @@ describe Gitlab::API do | @@ -25,11 +25,17 @@ describe Gitlab::API do | ||
25 | 25 | ||
26 | describe "GET /projects/:id" do | 26 | describe "GET /projects/:id" do |
27 | it "should return a project by id" do | 27 | it "should return a project by id" do |
28 | - get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" | 28 | + get "#{api_prefix}/projects/#{project.id}?private_token=#{user.private_token}" |
29 | response.status.should == 200 | 29 | response.status.should == 200 |
30 | json_response['name'].should == project.name | 30 | json_response['name'].should == project.name |
31 | json_response['owner']['email'].should == user.email | 31 | json_response['owner']['email'].should == user.email |
32 | end | 32 | end |
33 | + | ||
34 | + it "should return a project by code name" do | ||
35 | + get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" | ||
36 | + response.status.should == 200 | ||
37 | + json_response['name'].should == project.name | ||
38 | + end | ||
33 | end | 39 | end |
34 | 40 | ||
35 | describe "GET /projects/:id/repository/branches" do | 41 | describe "GET /projects/:id/repository/branches" do |