Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2014-07-27 18:40:00 +0400
committerRobert Schilling <rschilling@student.tugraz.at>2014-09-03 15:08:35 +0400
commit551145bc98e257280b615e305d531a44d7aa4131 (patch)
tree20a853ca41d610247f955a9c8824ba50b18d3220 /spec/requests/api/branches_spec.rb
parent7a0e1c7238033b33b7296701bfded56d4ad7f250 (diff)
Validate branch-names and references in WebUI, API
Add specs for GitRefValidator
Diffstat (limited to 'spec/requests/api/branches_spec.rb')
-rw-r--r--spec/requests/api/branches_spec.rb45
1 files changed, 39 insertions, 6 deletions
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index f3d7ca2ed21..e7f91c5e46e 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -94,22 +94,50 @@ describe API::API, api: true do
describe "POST /projects/:id/repository/branches" do
it "should create a new branch" do
post api("/projects/#{project.id}/repository/branches", user),
- branch_name: branch_name,
- ref: branch_sha
+ branch_name: 'feature1',
+ ref: branch_sha
response.status.should == 201
- json_response['name'].should == branch_name
+ json_response['name'].should == 'feature1'
json_response['commit']['id'].should == branch_sha
end
it "should deny for user without push access" do
post api("/projects/#{project.id}/repository/branches", user2),
- branch_name: branch_name,
- ref: branch_sha
-
+ branch_name: branch_name,
+ ref: branch_sha
response.status.should == 403
end
+
+ it 'should return 400 if branch name is invalid' do
+ post api("/projects/#{project.id}/repository/branches", user),
+ branch_name: 'new design',
+ ref: branch_sha
+ response.status.should == 400
+ json_response['message'].should == 'Branch name invalid'
+ end
+
+ it 'should return 400 if branch already exists' do
+ post api("/projects/#{project.id}/repository/branches", user),
+ branch_name: 'new_design1',
+ ref: branch_sha
+ response.status.should == 201
+
+ post api("/projects/#{project.id}/repository/branches", user),
+ branch_name: 'new_design1',
+ ref: branch_sha
+ response.status.should == 400
+ json_response['message'].should == 'Branch already exists'
+ end
+
+ it 'should return 400 if ref name is invalid' do
+ post api("/projects/#{project.id}/repository/branches", user),
+ branch_name: 'new_design3',
+ ref: 'foo'
+ response.status.should == 400
+ json_response['message'].should == 'Invalid reference name'
+ end
end
describe "DELETE /projects/:id/repository/branches/:branch" do
@@ -120,6 +148,11 @@ describe API::API, api: true do
response.status.should == 200
end
+ it 'should return 404 if branch not exists' do
+ delete api("/projects/#{project.id}/repository/branches/foobar", user)
+ response.status.should == 404
+ end
+
it "should remove protected branch" do
project.protected_branches.create(name: branch_name)
delete api("/projects/#{project.id}/repository/branches/#{branch_name}", user)