diff --git a/app/models/project.rb b/app/models/project.rb index 6c4f3075e1c0cff2473feb852ee224c1316044e1..f4d915179e82705a4cbdefb630fb0b8fd2b4cfd9 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -83,6 +83,7 @@ class Project < ActiveRecord::Base :wiki_enabled, inclusion: { in: [true, false] } validates :issues_tracker_id, length: { within: 0..255 } + validates :namespace, presence: true validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id @@ -165,11 +166,7 @@ class Project < ActiveRecord::Base end def to_param - if namespace - namespace.path + "/" + path - else - path - end + namespace.path + "/" + path end def web_url diff --git a/spec/contexts/issues/bulk_update_context_spec.rb b/spec/contexts/issues/bulk_update_context_spec.rb index 0966ee35745fe7c754e3fa835889109ce02ced1f..058e43ba0905accdbdfc24b69cc6d200ff53a53a 100644 --- a/spec/contexts/issues/bulk_update_context_spec.rb +++ b/spec/contexts/issues/bulk_update_context_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Issues::BulkUpdateContext do + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } let(:issue) { create(:issue, project: @project) @@ -9,7 +11,8 @@ describe Issues::BulkUpdateContext do before do @user = create :user opts = { - name: "GitLab" + name: "GitLab", + namespace: @user.namespace } @project = Projects::CreateContext.new(@user, opts).execute end diff --git a/spec/contexts/projects_create_context_spec.rb b/spec/contexts/projects_create_context_spec.rb index be492585b27421c310c9a51380effcebdab5124b..7b5fa530a8a09825e30de4761abf3b4cb0711bd0 100644 --- a/spec/contexts/projects_create_context_spec.rb +++ b/spec/contexts/projects_create_context_spec.rb @@ -1,11 +1,15 @@ require 'spec_helper' 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 before do @user = create :user @opts = { - name: "GitLab" + name: "GitLab", + namespace: @user.namespace } end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 3bac142f4e2e06a3e12b2e811d93362f42a37049..c3d2bf5d4a6683e88f788748e5e9bcbe20f5fafd 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -67,6 +67,7 @@ describe Project do it { should ensure_length_of(:description).is_within(0..2000) } it { should validate_presence_of(:creator) } 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 project2 = build(:project) diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 028617aa08e64dadac589a577716bbbe7d67c74f..e8870f4d5d8c83401e78d224f67f2a2cd0a78cd9 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe API::API do include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } let(:user) { create(:user) } let(:key) { create(:key, user: user) } diff --git a/spec/requests/api/issues_spec.rb b/spec/requests/api/issues_spec.rb index d5f75367e4ad905967c780b8e4ae1b876033005d..a97d6a282a9bf55195ef6920146280b395f513a1 100644 --- a/spec/requests/api/issues_spec.rb +++ b/spec/requests/api/issues_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe API::API do include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } diff --git a/spec/requests/api/notes_spec.rb b/spec/requests/api/notes_spec.rb index 48a2d111f8cab72ab0b3f88be3bdaea2f0cb6d01..ba18b123039c97912ef97eb2b3d8417bd4cab497 100644 --- a/spec/requests/api/notes_spec.rb +++ b/spec/requests/api/notes_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe API::API do include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } let(:user) { create(:user) } let!(:project) { create(:project, namespace: user.namespace ) } diff --git a/spec/services/project_transfer_service_spec.rb b/spec/services/project_transfer_service_spec.rb index bc26403b7f4607c703baf6195138885c156007d4..109b429967eb612778e11cac6d576e4a55cf44b7 100644 --- a/spec/services/project_transfer_service_spec.rb +++ b/spec/services/project_transfer_service_spec.rb @@ -21,25 +21,7 @@ describe ProjectTransferService do let(:user) { create(:user) } let(:project) { create(:project, namespace: user.namespace) } - before do - @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 } + it { lambda{service.transfer(project, nil)}.should raise_error(ActiveRecord::RecordInvalid) } end def service