diff options
author | Alex Van't Hof <alexvh@cs.columbia.edu> | 2013-08-27 21:22:42 -0400 |
---|---|---|
committer | Alex Van't Hof <alexvh@cs.columbia.edu> | 2013-08-27 21:22:42 -0400 |
commit | 59f428dca20228984e9f50c33b12f54eb15638e5 (patch) | |
tree | 8ba21e90e3e2709ab831f1afe266620abe1d57d5 /spec | |
parent | 79f0858a18081d37669883f1b5a32d033197561d (diff) | |
download | gitlab-ce-59f428dca20228984e9f50c33b12f54eb15638e5.tar.gz |
Standardize commit diff api url, change blob api url, add get single commit
Use "/commits/:sha/diff" as opposed to "/commit/:sha", keeping in line
with existing api urls (e.g. "/projects/:id", etc.)
Fix 500 error resulting from a diff api call with an invalid commit hash
Move "/commits/:sha/blob" to "/blobs/:sha", leaving the old path for
backwards compatibility.
Add ability to get a single commit via "/commits/:sha"
Diffstat (limited to 'spec')
-rw-r--r-- | spec/requests/api/repositories_spec.rb | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/spec/requests/api/repositories_spec.rb b/spec/requests/api/repositories_spec.rb index 44892876ccb..f15abdd3581 100644 --- a/spec/requests/api/repositories_spec.rb +++ b/spec/requests/api/repositories_spec.rb @@ -112,23 +112,51 @@ describe API::API do end end - describe "GET /projects:id/repository/commit/:sha" do + describe "GET /projects:id/repository/commits/:sha" do + context "authorized user" do + it "should return a commit by sha" do + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user) + response.status.should == 200 + json_response['id'].should == project.repository.commit.id + json_response['title'].should == project.repository.commit.title + end + + it "should return a 404 error if not found" do + get api("/projects/#{project.id}/repository/commits/invalid_sha", user) + response.status.should == 404 + end + end + + context "unauthorized user" do + it "should not return the selected commit" do + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}") + response.status.should == 401 + end + end + end + + describe "GET /projects:id/repository/commits/:sha/diff" do context "authorized user" do before { project.team << [user2, :reporter] } it "should return the diff of the selected commit" do - get api("/projects/#{project.id}/repository/commit/#{project.repository.commit.id}", user) + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user) response.status.should == 200 json_response.should be_an Array json_response.length.should >= 1 json_response.first.keys.should include "diff" end + + it "should return a 404 error if invalid commit" do + get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user) + response.status.should == 404 + end end context "unauthorized user" do it "should not return the diff of the selected commit" do - get api("/projects/#{project.id}/repository/commit/#{project.repository.commit.id}") + get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff") response.status.should == 401 end end @@ -157,25 +185,33 @@ describe API::API do end end - describe "GET /projects/:id/repository/commits/:sha/blob" do + describe "GET /projects/:id/repository/blobs/:sha" do it "should get the raw file contents" do - get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) + get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user) response.status.should == 200 end it "should return 404 for invalid branch_name" do - get api("/projects/#{project.id}/repository/commits/invalid_branch_name/blob?filepath=README.md", user) + get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user) response.status.should == 404 end it "should return 404 for invalid file" do - get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.invalid", user) + get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user) response.status.should == 404 end it "should return a 400 error if filepath is missing" do - get api("/projects/#{project.id}/repository/commits/master/blob", user) + get api("/projects/#{project.id}/repository/blobs/master", user) response.status.should == 400 end end + + describe "GET /projects/:id/repository/commits/:sha/blob" do + it "should get the raw file contents" do + get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user) + response.status.should == 200 + end + end + end |