diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-03-16 21:15:05 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-03-16 21:15:16 -0300 |
commit | 3f111741967a5dcb6e0418471d2b26ca9ab04eac (patch) | |
tree | b32a7cc72b9ffaec3739e42821265401cee8a449 /spec/requests/api/v3 | |
parent | 0fa511fdeb5e1089dbd82435cb1397b0d433b00b (diff) | |
download | gitlab-ce-3f111741967a5dcb6e0418471d2b26ca9ab04eac.tar.gz |
Use "branch_name" instead "branch" on V3 branch creation API29604-v3-fix-branch-creation
Diffstat (limited to 'spec/requests/api/v3')
-rw-r--r-- | spec/requests/api/v3/branches_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/requests/api/v3/branches_spec.rb b/spec/requests/api/v3/branches_spec.rb index e4cedf98e64..5dcd4f21f4e 100644 --- a/spec/requests/api/v3/branches_spec.rb +++ b/spec/requests/api/v3/branches_spec.rb @@ -10,6 +10,7 @@ describe API::V3::Branches, api: true do let!(:master) { create(:project_member, :master, user: user, project: project) } let!(:guest) { create(:project_member, :guest, user: user2, project: project) } let!(:branch_name) { 'feature' } + let!(:branch_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } let!(:branch_with_dot) { CreateBranchService.new(project, user).execute("with.1.2.3", "master") } describe "GET /projects/:id/repository/branches" do @@ -80,4 +81,55 @@ describe API::V3::Branches, api: true do expect(response).to have_http_status(403) end end + + describe "POST /projects/:id/repository/branches" do + it "creates a new branch" do + post v3_api("/projects/#{project.id}/repository/branches", user), + branch_name: 'feature1', + ref: branch_sha + + expect(response).to have_http_status(201) + + expect(json_response['name']).to eq('feature1') + expect(json_response['commit']['id']).to eq(branch_sha) + end + + it "denies for user without push access" do + post v3_api("/projects/#{project.id}/repository/branches", user2), + branch_name: branch_name, + ref: branch_sha + expect(response).to have_http_status(403) + end + + it 'returns 400 if branch name is invalid' do + post v3_api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new design', + ref: branch_sha + expect(response).to have_http_status(400) + expect(json_response['message']).to eq('Branch name is invalid') + end + + it 'returns 400 if branch already exists' do + post v3_api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design1', + ref: branch_sha + expect(response).to have_http_status(201) + + post v3_api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design1', + ref: branch_sha + + expect(response).to have_http_status(400) + expect(json_response['message']).to eq('Branch already exists') + end + + it 'returns 400 if ref name is invalid' do + post v3_api("/projects/#{project.id}/repository/branches", user), + branch_name: 'new_design3', + ref: 'foo' + + expect(response).to have_http_status(400) + expect(json_response['message']).to eq('Invalid reference name') + end + end end |