summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-14 16:55:33 +0100
committerSebastian Ziebell <sebastian.ziebell@asquera.de>2013-02-14 16:55:33 +0100
commitc305eb31aa1cf1aec24b907e0db1d7b2084400dc (patch)
tree9df3cf267fd31e617bac562d77c8df0afed7c5a0
parent6df02adc7a5cb7badf748be783f9a552cf19aeee (diff)
downloadgitlab-ce-c305eb31aa1cf1aec24b907e0db1d7b2084400dc.tar.gz
API: tests that check status codes for project branches and hooks
Status code 422 (Unprocessable Entity) returned if invalid url is given when creating or updating a project hook.
-rw-r--r--lib/api/projects.rb14
-rw-r--r--spec/requests/api/projects_spec.rb43
2 files changed, 54 insertions, 3 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 87653f04450..cf3e8257a77 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -156,9 +156,9 @@ module Gitlab
# DELETE /projects/:id/members/:user_id
delete ":id/members/:user_id" do
authorize! :admin_project, user_project
- users_project = user_project.users_projects.find_by_user_id params[:user_id]
- unless users_project.nil?
- users_project.destroy
+ team_member = user_project.users_projects.find_by_user_id(params[:user_id])
+ unless team_member.nil?
+ team_member.destroy
else
{:message => "Access revoked", :id => params[:user_id].to_i}
end
@@ -205,6 +205,9 @@ module Gitlab
if @hook.save
present @hook, with: Entities::Hook
else
+ if @hook.errors[:url].present?
+ error!("Invalid url given", 422)
+ end
not_found!
end
end
@@ -227,6 +230,9 @@ module Gitlab
if @hook.update_attributes attrs
present @hook, with: Entities::Hook
else
+ if @hook.errors[:url].present?
+ error!("Invalid url given", 422)
+ end
not_found!
end
end
@@ -281,6 +287,7 @@ module Gitlab
# PUT /projects/:id/repository/branches/:branch/protect
put ":id/repository/branches/:branch/protect" do
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
+ not_found! unless @branch
protected = user_project.protected_branches.find_by_name(@branch.name)
unless protected
@@ -299,6 +306,7 @@ module Gitlab
# PUT /projects/:id/repository/branches/:branch/unprotect
put ":id/repository/branches/:branch/unprotect" do
@branch = user_project.repo.heads.find { |item| item.name == params[:branch] }
+ not_found! unless @branch
protected = user_project.protected_branches.find_by_name(@branch.name)
if protected
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index b635307884b..96f58dde194 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -144,6 +144,17 @@ describe Gitlab::API do
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['protected'].should == true
end
+
+ it "should return a 404 error if branch not found" do
+ put api("/projects/#{project.id}/repository/branches/unknown/protect", user)
+ response.status.should == 404
+ end
+
+ it "should return success when protect branch again" do
+ put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
+ put api("/projects/#{project.id}/repository/branches/new_design/protect", user)
+ response.status.should == 200
+ end
end
describe "PUT /projects/:id/repository/branches/:branch/unprotect" do
@@ -155,6 +166,17 @@ describe Gitlab::API do
json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1'
json_response['protected'].should == false
end
+
+ it "should return success when unprotect branch" do
+ put api("/projects/#{project.id}/repository/branches/unknown/unprotect", user)
+ response.status.should == 404
+ end
+
+ it "should return success when unprotect branch again" do
+ put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
+ put api("/projects/#{project.id}/repository/branches/new_design/unprotect", user)
+ response.status.should == 200
+ end
end
describe "GET /projects/:id/members" do
@@ -182,6 +204,11 @@ describe Gitlab::API do
json_response['email'].should == user.email
json_response['access_level'].should == UsersProject::MASTER
end
+
+ it "should return a 404 error if user id not found" do
+ get api("/projects/#{project.id}/members/1234", user)
+ response.status.should == 404
+ end
end
describe "POST /projects/:id/members" do
@@ -262,6 +289,12 @@ describe Gitlab::API do
delete api("/projects/#{project.id}/members/#{user3.id}", user)
}.to_not change { UsersProject.count }.by(1)
end
+
+ it "should return 200 if team member already removed" do
+ delete api("/projects/#{project.id}/members/#{user3.id}", user)
+ delete api("/projects/#{project.id}/members/#{user3.id}", user)
+ response.status.should == 200
+ end
end
describe "DELETE /projects/:id/members/:user_id" do
@@ -313,6 +346,11 @@ describe Gitlab::API do
post api("/projects/#{project.id}/hooks", user)
response.status.should == 400
end
+
+ it "should return a 422 error if url not valid" do
+ post api("/projects/#{project.id}/hooks", user), "url" => "ftp://example.com"
+ response.status.should == 422
+ end
end
describe "PUT /projects/:id/hooks/:hook_id" do
@@ -332,6 +370,11 @@ describe Gitlab::API do
put api("/projects/#{project.id}/hooks/#{hook.id}", user)
response.status.should == 400
end
+
+ it "should return a 422 error if url is not valid" do
+ put api("/projects/#{project.id}/hooks/#{hook.id}", user), url: 'ftp://example.com'
+ response.status.should == 422
+ end
end
describe "DELETE /projects/:id/hooks" do