Commit 8672203b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #5112 from hiroponz/drop-support-of-root-namespace

Drop support of root namespace in model
parents 9fabd703 a3ef6831
...@@ -83,6 +83,7 @@ class Project < ActiveRecord::Base ...@@ -83,6 +83,7 @@ class Project < ActiveRecord::Base
:wiki_enabled, inclusion: { in: [true, false] } :wiki_enabled, inclusion: { in: [true, false] }
validates :issues_tracker_id, length: { within: 0..255 } validates :issues_tracker_id, length: { within: 0..255 }
validates :namespace, presence: true
validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :name, scope: :namespace_id
validates_uniqueness_of :path, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id
...@@ -165,11 +166,7 @@ class Project < ActiveRecord::Base ...@@ -165,11 +166,7 @@ class Project < ActiveRecord::Base
end end
def to_param def to_param
if namespace
namespace.path + "/" + path namespace.path + "/" + path
else
path
end
end end
def web_url def web_url
......
require 'spec_helper' require 'spec_helper'
describe Issues::BulkUpdateContext do describe Issues::BulkUpdateContext do
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
let(:issue) { let(:issue) {
create(:issue, project: @project) create(:issue, project: @project)
...@@ -9,7 +11,8 @@ describe Issues::BulkUpdateContext do ...@@ -9,7 +11,8 @@ describe Issues::BulkUpdateContext do
before do before do
@user = create :user @user = create :user
opts = { opts = {
name: "GitLab" name: "GitLab",
namespace: @user.namespace
} }
@project = Projects::CreateContext.new(@user, opts).execute @project = Projects::CreateContext.new(@user, opts).execute
end end
......
require 'spec_helper' require 'spec_helper'
describe Projects::CreateContext do describe Projects::CreateContext do
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
describe :create_by_user do describe :create_by_user do
before do before do
@user = create :user @user = create :user
@opts = { @opts = {
name: "GitLab" name: "GitLab",
namespace: @user.namespace
} }
end end
......
...@@ -67,6 +67,7 @@ describe Project do ...@@ -67,6 +67,7 @@ describe Project do
it { should ensure_length_of(:description).is_within(0..2000) } it { should ensure_length_of(:description).is_within(0..2000) }
it { should validate_presence_of(:creator) } it { should validate_presence_of(:creator) }
it { should ensure_length_of(:issues_tracker_id).is_within(0..255) } it { should ensure_length_of(:issues_tracker_id).is_within(0..255) }
it { should validate_presence_of(:namespace) }
it "should not allow new projects beyond user limits" do it "should not allow new projects beyond user limits" do
project2 = build(:project) project2 = build(:project)
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
describe API::API do describe API::API do
include ApiHelpers include ApiHelpers
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:key) { create(:key, user: user) } let(:key) { create(:key, user: user) }
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
describe API::API do describe API::API do
include ApiHelpers include ApiHelpers
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
......
...@@ -2,6 +2,8 @@ require 'spec_helper' ...@@ -2,6 +2,8 @@ require 'spec_helper'
describe API::API do describe API::API do
include ApiHelpers include ApiHelpers
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
......
...@@ -21,25 +21,7 @@ describe ProjectTransferService do ...@@ -21,25 +21,7 @@ describe ProjectTransferService do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) } let(:project) { create(:project, namespace: user.namespace) }
before do it { lambda{service.transfer(project, nil)}.should raise_error(ActiveRecord::RecordInvalid) }
@result = service.transfer(project, nil)
end
it { @result.should be_true }
it { project.namespace.should == nil }
end
context 'no namespace -> namespace' do
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
@result = service.transfer(project, user.namespace)
end
it { @result.should be_true }
it { project.namespace.should == user.namespace }
end end
def service def service
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment