Commit fbd559d44f1fc7e37f88844a9260bf7a5e1ba822
1 parent
378dc55d
Exists in
master
and in
4 other branches
add API version
Showing
5 changed files
with
37 additions
and
34 deletions
Show diff stats
lib/api.rb
spec/api/projects_spec.rb
... | ... | @@ -8,75 +8,69 @@ describe Gitlab::API do |
8 | 8 | |
9 | 9 | describe "GET /projects" do |
10 | 10 | it "should return authentication error" do |
11 | - get "/api/projects" | |
11 | + get "#{api_prefix}/projects" | |
12 | 12 | response.status.should == 401 |
13 | 13 | end |
14 | 14 | |
15 | 15 | describe "authenticated GET /projects" do |
16 | 16 | it "should return an array of projects" do |
17 | - get "/api/projects?private_token=#{user.private_token}" | |
17 | + get "#{api_prefix}/projects?private_token=#{user.private_token}" | |
18 | 18 | response.status.should == 200 |
19 | - json = JSON.parse(response.body) | |
20 | - json.should be_an Array | |
21 | - json.first['name'].should == project.name | |
22 | - json.first['owner']['email'].should == user.email | |
19 | + json_response.should be_an Array | |
20 | + json_response.first['name'].should == project.name | |
21 | + json_response.first['owner']['email'].should == user.email | |
23 | 22 | end |
24 | 23 | end |
25 | 24 | end |
26 | 25 | |
27 | 26 | describe "GET /projects/:id" do |
28 | 27 | it "should return a project by id" do |
29 | - get "/api/projects/#{project.code}?private_token=#{user.private_token}" | |
28 | + get "#{api_prefix}/projects/#{project.code}?private_token=#{user.private_token}" | |
30 | 29 | response.status.should == 200 |
31 | - json = JSON.parse(response.body) | |
32 | - json['name'].should == project.name | |
33 | - json['owner']['email'].should == user.email | |
30 | + json_response['name'].should == project.name | |
31 | + json_response['owner']['email'].should == user.email | |
34 | 32 | end |
35 | 33 | end |
36 | 34 | |
37 | 35 | describe "GET /projects/:id/repository/branches" do |
38 | 36 | it "should return an array of project branches" do |
39 | - get "/api/projects/#{project.code}/repository/branches?private_token=#{user.private_token}" | |
37 | + get "#{api_prefix}/projects/#{project.code}/repository/branches?private_token=#{user.private_token}" | |
40 | 38 | response.status.should == 200 |
41 | - json = JSON.parse(response.body) | |
42 | - json.should be_an Array | |
43 | - json.first['name'].should == project.repo.heads.sort_by(&:name).first.name | |
39 | + json_response.should be_an Array | |
40 | + json_response.first['name'].should == project.repo.heads.sort_by(&:name).first.name | |
44 | 41 | end |
45 | 42 | end |
46 | 43 | |
47 | 44 | describe "GET /projects/:id/repository/tags" do |
48 | 45 | it "should return an array of project tags" do |
49 | - get "/api/projects/#{project.code}/repository/tags?private_token=#{user.private_token}" | |
46 | + get "#{api_prefix}/projects/#{project.code}/repository/tags?private_token=#{user.private_token}" | |
50 | 47 | response.status.should == 200 |
51 | - json = JSON.parse(response.body) | |
52 | - json.should be_an Array | |
53 | - json.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name | |
48 | + json_response.should be_an Array | |
49 | + json_response.first['name'].should == project.repo.tags.sort_by(&:name).reverse.first.name | |
54 | 50 | end |
55 | 51 | end |
56 | 52 | |
57 | 53 | describe "GET /projects/:id/snippets/:snippet_id" do |
58 | 54 | it "should return a project snippet" do |
59 | - get "/api/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}" | |
55 | + get "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}" | |
60 | 56 | response.status.should == 200 |
61 | - json = JSON.parse(response.body) | |
62 | - json['title'].should == snippet.title | |
57 | + json_response['title'].should == snippet.title | |
63 | 58 | end |
64 | 59 | end |
65 | 60 | |
66 | 61 | describe "POST /projects/:id/snippets" do |
67 | 62 | it "should create a new project snippet" do |
68 | - post "/api/projects/#{project.code}/snippets?private_token=#{user.private_token}", | |
63 | + post "#{api_prefix}/projects/#{project.code}/snippets?private_token=#{user.private_token}", | |
69 | 64 | :title => 'api test', :file_name => 'sample.rb', :code => 'test' |
70 | 65 | response.status.should == 201 |
71 | - json = JSON.parse(response.body) | |
72 | - json['title'].should == 'api test' | |
66 | + json_response['title'].should == 'api test' | |
73 | 67 | end |
74 | 68 | end |
75 | 69 | |
76 | 70 | describe "DELETE /projects/:id/snippets/:snippet_id" do |
77 | 71 | it "should create a new project snippet" do |
78 | 72 | expect { |
79 | - delete "/api/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}" | |
73 | + delete "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}" | |
80 | 74 | }.should change { Snippet.count }.by(-1) |
81 | 75 | end |
82 | 76 | end | ... | ... |
spec/api/users_spec.rb
... | ... | @@ -5,34 +5,33 @@ describe Gitlab::API do |
5 | 5 | |
6 | 6 | describe "GET /users" do |
7 | 7 | it "should return authentication error" do |
8 | - get "/api/users" | |
8 | + get "#{api_prefix}/users" | |
9 | 9 | response.status.should == 401 |
10 | 10 | end |
11 | 11 | |
12 | 12 | describe "authenticated GET /users" do |
13 | 13 | it "should return an array of users" do |
14 | - get "/api/users?private_token=#{user.private_token}" | |
14 | + get "#{api_prefix}/users?private_token=#{user.private_token}" | |
15 | 15 | response.status.should == 200 |
16 | - json = JSON.parse(response.body) | |
17 | - json.should be_an Array | |
18 | - json.first['email'].should == user.email | |
16 | + json_response.should be_an Array | |
17 | + json_response.first['email'].should == user.email | |
19 | 18 | end |
20 | 19 | end |
21 | 20 | end |
22 | 21 | |
23 | 22 | describe "GET /users/:id" do |
24 | 23 | it "should return a user by id" do |
25 | - get "/api/users/#{user.id}?private_token=#{user.private_token}" | |
24 | + get "#{api_prefix}/users/#{user.id}?private_token=#{user.private_token}" | |
26 | 25 | response.status.should == 200 |
27 | - JSON.parse(response.body)['email'].should == user.email | |
26 | + json_response['email'].should == user.email | |
28 | 27 | end |
29 | 28 | end |
30 | 29 | |
31 | 30 | describe "GET /user" do |
32 | 31 | it "should return current user" do |
33 | - get "/api/user?private_token=#{user.private_token}" | |
32 | + get "#{api_prefix}/user?private_token=#{user.private_token}" | |
34 | 33 | response.status.should == 200 |
35 | - JSON.parse(response.body)['email'].should == user.email | |
34 | + json_response['email'].should == user.email | |
36 | 35 | end |
37 | 36 | end |
38 | 37 | end | ... | ... |
spec/support/security.rb