Merge pull request #1363 from AlexDenisov/api_create_project_fixes

API create project fixes
This commit is contained in:
Dmitriy Zaporozhets 2012-09-06 23:00:04 -07:00
commit 7c0a1068bf
4 changed files with 56 additions and 35 deletions

View file

@ -11,6 +11,9 @@ module Factory
def self.new(type, *args)
FactoryGirl.build(type, *args)
end
def self.attributes(type, *args)
FactoryGirl.attributes_for(type, *args)
end
end
FactoryGirl.define do

View file

@ -27,38 +27,40 @@ describe Gitlab::API do
describe "POST /projects" do
it "should create new project without code and path" do
lambda {
name = "foo"
post api("/projects", user), {
name: name
}
response.status.should == 201
json_response["name"].should == name
json_response["code"].should == name
json_response["path"].should == name
}.should change{Project.count}.by(1)
expect { post api("/projects", user), name: 'foo' }.to change {Project.count}.by(1)
end
it "should create new project" do
lambda {
name = "foo"
path = "bar"
code = "bazz"
post api("/projects", user), {
code: code,
path: path,
name: name
}
response.status.should == 201
json_response["name"].should == name
json_response["path"].should == path
json_response["code"].should == code
}.should change{Project.count}.by(1)
it "should not create new project without name" do
expect { post api("/projects", user) }.to_not change {Project.count}
end
it "should not create project without name" do
lambda {
post api("/projects", user)
response.status.should == 404
}.should_not change{Project.count}
it "should respond with 201 on success" do
post api("/projects", user), name: 'foo'
response.status.should == 201
end
it "should repsond with 404 on failure" do
post api("/projects", user)
response.status.should == 404
end
it "should assign attributes to project" do
project = Factory.attributes(:project, {
path: 'path',
code: 'code',
description: Faker::Lorem.sentence,
default_branch: 'stable',
issues_enabled: false,
wall_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false
})
post api("/projects", user), project
project.each_pair do |k,v|
json_response[k.to_s].should == v
end
end
end