Improve CreateContext call. Fixed test
This commit is contained in:
parent
232d61d598
commit
6f05ea4f6e
|
@ -1,10 +1,14 @@
|
|||
module Projects
|
||||
class CreateContext < BaseContext
|
||||
def initialize(user, params)
|
||||
@current_user, @params = user, params.dup
|
||||
end
|
||||
|
||||
def execute
|
||||
# get namespace id
|
||||
namespace_id = params[:project].delete(:namespace_id)
|
||||
namespace_id = params.delete(:namespace_id)
|
||||
|
||||
@project = Project.new(params[:project])
|
||||
@project = Project.new(params)
|
||||
|
||||
# Parametrize path for project
|
||||
#
|
||||
|
@ -25,7 +29,7 @@ module Projects
|
|||
end
|
||||
else
|
||||
# Set current user namespace if namespace_id is nil
|
||||
@project.namespace_id = current_user.id
|
||||
@project.namespace_id = current_user.namespace_id
|
||||
end
|
||||
|
||||
Project.transaction do
|
||||
|
|
|
@ -19,7 +19,7 @@ class ProjectsController < ProjectResourceController
|
|||
end
|
||||
|
||||
def create
|
||||
@project = Projects::CreateContext.new(nil, current_user, params).execute
|
||||
@project = Projects::CreateContext.new(current_user, params).execute
|
||||
|
||||
respond_to do |format|
|
||||
flash[:notice] = 'Project was successfully created.' if @project.saved?
|
||||
|
|
|
@ -43,7 +43,7 @@ module Gitlab
|
|||
:wall_enabled,
|
||||
:merge_requests_enabled,
|
||||
:wiki_enabled]
|
||||
@project = Projects::CreateContext.new(nil, attrs, current_user).execute
|
||||
@project = ::Projects::CreateContext.new(current_user, attrs).execute
|
||||
if @project.saved?
|
||||
present @project, with: Entities::Project
|
||||
else
|
||||
|
|
38
spec/contexts/projects_create_context_spec.rb
Normal file
38
spec/contexts/projects_create_context_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Projects::CreateContext do
|
||||
describe :create_by_user do
|
||||
before do
|
||||
@user = create :user
|
||||
@opts = {
|
||||
name: "GitLab"
|
||||
}
|
||||
end
|
||||
|
||||
context 'user namespace' do
|
||||
before do
|
||||
@project = create_project(@user, @opts)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @user.namespace }
|
||||
end
|
||||
|
||||
context 'group namespace' do
|
||||
before do
|
||||
@group = create :group, owner: @user
|
||||
@opts.merge!(namespace_id: @group.id)
|
||||
@project = create_project(@user, @opts)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @group }
|
||||
end
|
||||
end
|
||||
|
||||
def create_project(user, opts)
|
||||
Projects::CreateContext.new(user, opts).execute
|
||||
end
|
||||
end
|
|
@ -153,36 +153,6 @@ describe Project do
|
|||
end
|
||||
end
|
||||
|
||||
describe :create_by_user do
|
||||
before do
|
||||
@user = create :user
|
||||
@opts = {
|
||||
name: "GitLab"
|
||||
}
|
||||
end
|
||||
|
||||
context 'user namespace' do
|
||||
before do
|
||||
@project = Project.create_by_user(@opts, @user)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @user.namespace }
|
||||
end
|
||||
|
||||
context 'user namespace' do
|
||||
before do
|
||||
@group = create :group, owner: @user
|
||||
@opts.merge!(namespace_id: @group.id)
|
||||
@project = Project.create_by_user(@opts, @user)
|
||||
end
|
||||
|
||||
it { @project.should be_valid }
|
||||
it { @project.owner.should == @user }
|
||||
it { @project.namespace.should == @group }
|
||||
end
|
||||
end
|
||||
|
||||
describe :find_with_namespace do
|
||||
context 'with namespace' do
|
||||
|
|
Loading…
Reference in a new issue