Merge branch 'master' into fixes/api, code clean up and tests fixed
Conflicts: doc/api/projects.md spec/requests/api/projects_spec.rb
This commit is contained in:
commit
3374027e3a
49 changed files with 820 additions and 163 deletions
|
@ -100,4 +100,27 @@ describe Gitlab::API do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /groups/:id/projects/:project_id" do
|
||||
let(:project) { create(:project) }
|
||||
before(:each) do
|
||||
project.stub!(:transfer).and_return(true)
|
||||
Project.stub(:find).and_return(project)
|
||||
end
|
||||
|
||||
|
||||
context "when authenticated as user" do
|
||||
it "should not transfer project to group" do
|
||||
post api("/groups/#{group1.id}/projects/#{project.id}", user2)
|
||||
response.status.should == 403
|
||||
end
|
||||
end
|
||||
|
||||
context "when authenticated as admin" do
|
||||
it "should transfer project to group" do
|
||||
project.should_receive(:transfer)
|
||||
post api("/groups/#{group1.id}/projects/#{project.id}", admin)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,13 +105,6 @@ describe Gitlab::API do
|
|||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
|
||||
context "when notable is invalid" do
|
||||
it "should return a 404 error" do
|
||||
get api("/projects/#{project.id}/unknown/#{snippet.id}/notes", user)
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /projects/:id/noteable/:noteable_id/notes/:note_id" do
|
||||
|
@ -180,12 +173,5 @@ describe Gitlab::API do
|
|||
response.status.should == 401
|
||||
end
|
||||
end
|
||||
|
||||
context "when noteable is invalid" do
|
||||
it "should return a 404 error" do
|
||||
post api("/projects/#{project.id}/invalid/#{snippet.id}/notes", user)
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,14 @@ describe Gitlab::API do
|
|||
let(:user) { create(:user) }
|
||||
let(:user2) { create(:user) }
|
||||
let(:user3) { create(:user) }
|
||||
let(:admin) { create(:admin) }
|
||||
let!(:project) { create(:project, namespace: user.namespace ) }
|
||||
let!(:hook) { create(:project_hook, project: project, url: "http://example.com") }
|
||||
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
|
||||
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
|
||||
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
|
||||
let(:key) { create(:key, project: project) }
|
||||
|
||||
before { project.team << [user, :reporter] }
|
||||
|
||||
describe "GET /projects" do
|
||||
|
@ -103,6 +106,46 @@ describe Gitlab::API do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /projects/user/:id" do
|
||||
before { admin }
|
||||
|
||||
it "should create new project without path" do
|
||||
expect { post api("/projects/user/#{user.id}", admin), name: 'foo' }.to change {Project.count}.by(1)
|
||||
end
|
||||
|
||||
it "should not create new project without name" do
|
||||
expect { post api("/projects/user/#{user.id}", admin) }.to_not change {Project.count}
|
||||
end
|
||||
|
||||
it "should respond with 201 on success" do
|
||||
post api("/projects/user/#{user.id}", admin), name: 'foo'
|
||||
response.status.should == 201
|
||||
end
|
||||
|
||||
it "should respond with 404 on failure" do
|
||||
post api("/projects/user/#{user.id}", admin)
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "should assign attributes to project" do
|
||||
project = attributes_for(:project, {
|
||||
description: Faker::Lorem.sentence,
|
||||
default_branch: 'stable',
|
||||
issues_enabled: false,
|
||||
wall_enabled: false,
|
||||
merge_requests_enabled: false,
|
||||
wiki_enabled: false
|
||||
})
|
||||
|
||||
post api("/projects/user/#{user.id}", admin), project
|
||||
|
||||
project.each_pair do |k,v|
|
||||
next if k == :path
|
||||
json_response[k.to_s].should == v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /projects/:id" do
|
||||
it "should return a project by id" do
|
||||
get api("/projects/#{project.id}", user)
|
||||
|
@ -591,4 +634,59 @@ describe Gitlab::API do
|
|||
response.status.should == 400
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /projects/:id/keys" do
|
||||
it "should return array of ssh keys" do
|
||||
project.deploy_keys << key
|
||||
project.save
|
||||
get api("/projects/#{project.id}/keys", user)
|
||||
response.status.should == 200
|
||||
json_response.should be_an Array
|
||||
json_response.first['title'].should == key.title
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /projects/:id/keys/:key_id" do
|
||||
it "should return a single key" do
|
||||
project.deploy_keys << key
|
||||
project.save
|
||||
get api("/projects/#{project.id}/keys/#{key.id}", user)
|
||||
response.status.should == 200
|
||||
json_response['title'].should == key.title
|
||||
end
|
||||
|
||||
it "should return 404 Not Found with invalid ID" do
|
||||
get api("/projects/#{project.id}/keys/404", user)
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /projects/:id/keys" do
|
||||
it "should not create an invalid ssh key" do
|
||||
post api("/projects/#{project.id}/keys", user), { title: "invalid key" }
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "should create new ssh key" do
|
||||
key_attrs = attributes_for :key
|
||||
expect {
|
||||
post api("/projects/#{project.id}/keys", user), key_attrs
|
||||
}.to change{ project.deploy_keys.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /projects/:id/keys/:key_id" do
|
||||
it "should delete existing key" do
|
||||
project.deploy_keys << key
|
||||
project.save
|
||||
expect {
|
||||
delete api("/projects/#{project.id}/keys/#{key.id}", user)
|
||||
}.to change{ project.deploy_keys.count }.by(-1)
|
||||
end
|
||||
|
||||
it "should return 404 Not Found with invalid ID" do
|
||||
delete api("/projects/#{project.id}/keys/404", user)
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
69
spec/requests/api/system_hooks_spec.rb
Normal file
69
spec/requests/api/system_hooks_spec.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::API do
|
||||
include ApiHelpers
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:admin) { create(:admin) }
|
||||
let!(:hook) { create(:system_hook, url: "http://example.com") }
|
||||
|
||||
before { stub_request(:post, hook.url) }
|
||||
|
||||
describe "GET /hooks" do
|
||||
context "when not an admin" do
|
||||
it "should return forbidden error" do
|
||||
get api("/hooks", user)
|
||||
response.status.should == 403
|
||||
end
|
||||
end
|
||||
|
||||
context "when authenticated as admin" do
|
||||
it "should return an array of hooks" do
|
||||
get api("/hooks", admin)
|
||||
response.status.should == 200
|
||||
json_response.should be_an Array
|
||||
json_response.first['url'].should == hook.url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /hooks" do
|
||||
it "should create new hook" do
|
||||
expect {
|
||||
post api("/hooks", admin), url: 'http://example.com'
|
||||
}.to change { SystemHook.count }.by(1)
|
||||
end
|
||||
|
||||
it "should respond with 404 on failure" do
|
||||
post api("/hooks", admin)
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "should not create new hook without url" do
|
||||
expect {
|
||||
post api("/hooks", admin)
|
||||
}.to_not change { SystemHook.count }
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /hooks/:id" do
|
||||
it "should return hook by id" do
|
||||
get api("/hooks/#{hook.id}", admin)
|
||||
response.status.should == 200
|
||||
json_response['event_name'].should == 'project_create'
|
||||
end
|
||||
|
||||
it "should return 404 on failure" do
|
||||
get api("/hooks/404", admin)
|
||||
response.status.should == 404
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /hooks/:id" do
|
||||
it "should delete a hook" do
|
||||
expect {
|
||||
delete api("/hooks/#{hook.id}", admin)
|
||||
}.to change { SystemHook.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -167,6 +167,22 @@ describe Gitlab::API do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:id/keys" do
|
||||
before { admin }
|
||||
|
||||
it "should not create invalid ssh key" do
|
||||
post api("/users/#{user.id}/keys", admin), { title: "invalid key" }
|
||||
response.status.should == 404
|
||||
end
|
||||
|
||||
it "should create ssh key" do
|
||||
key_attrs = attributes_for :key
|
||||
expect {
|
||||
post api("/users/#{user.id}/keys", admin), key_attrs
|
||||
}.to change{ user.keys.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /users/:id" do
|
||||
before { admin }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue