Skip to content
Snippets Groups Projects
Commit 73f91da8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Fix project deletion and tests

parent 6d352790
Branches
Tags
No related merge requests found
Loading
@@ -98,8 +98,7 @@ class ProjectsController < ApplicationController
Loading
@@ -98,8 +98,7 @@ class ProjectsController < ApplicationController
def destroy def destroy
return access_denied! unless can?(current_user, :remove_project, project) return access_denied! unless can?(current_user, :remove_project, project)
   
project.team.truncate ::Projects::DestroyService.new(@project, current_user, {}).execute
project.destroy
   
respond_to do |format| respond_to do |format|
format.html { redirect_to root_path } format.html { redirect_to root_path }
Loading
Loading
module Projects module Projects
class UpdateService < BaseService class DestroyService < BaseService
def execute(role = :default) def execute
return false unless can?(current_user, :remove_project, project) return false unless can?(current_user, :remove_project, project)
   
project.team.truncate
project.repository.expire_cache unless project.empty_repo? project.repository.expire_cache unless project.empty_repo?
   
if project.destroy if project.destroy
Loading
Loading
Loading
@@ -65,26 +65,4 @@ describe Event do
Loading
@@ -65,26 +65,4 @@ describe Event do
it { @event.branch_name.should == "master" } it { @event.branch_name.should == "master" }
it { @event.author.should == @user } it { @event.author.should == @user }
end end
describe 'Team events' do
let(:user_project) { double.as_null_object }
let(:observer) { UsersProjectObserver.instance }
before {
Event.should_receive :create
observer.stub(notification: double.as_null_object)
}
describe "Joined project team" do
it "should create event" do
observer.after_create user_project
end
end
describe "Left project team" do
it "should create event" do
observer.after_destroy user_project
end
end
end
end end
Loading
@@ -25,13 +25,14 @@ describe SystemHook do
Loading
@@ -25,13 +25,14 @@ describe SystemHook do
end end
   
it "project_create hook" do it "project_create hook" do
project = create(:project) Projects::CreateService.new(create(:user), name: 'empty').execute
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
end end
   
it "project_destroy hook" do it "project_destroy hook" do
project = create(:project) user = create(:user)
project.destroy project = create(:empty_project, namespace: user.namespace)
Projects::DestroyService.new(project, user, {}).execute
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
end end
   
Loading
Loading
Loading
@@ -63,11 +63,8 @@ describe Projects::CreateService do
Loading
@@ -63,11 +63,8 @@ describe Projects::CreateService do
@settings.stub(:merge_requests) { true } @settings.stub(:merge_requests) { true }
@settings.stub(:wiki) { true } @settings.stub(:wiki) { true }
@settings.stub(:snippets) { true } @settings.stub(:snippets) { true }
stub_const("Settings", Class.new) Gitlab.config.gitlab.stub(restricted_visibility_levels: [])
@restrictions = double("restrictions") Gitlab.config.gitlab.stub(:default_projects_features).and_return(@settings)
@restrictions.stub(:restricted_visibility_levels) { [] }
Settings.stub_chain(:gitlab).and_return(@restrictions)
Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings)
end end
   
context 'should be public when setting is public' do context 'should be public when setting is public' do
Loading
@@ -106,11 +103,9 @@ describe Projects::CreateService do
Loading
@@ -106,11 +103,9 @@ describe Projects::CreateService do
@settings.stub(:wiki) { true } @settings.stub(:wiki) { true }
@settings.stub(:snippets) { true } @settings.stub(:snippets) { true }
@settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE }
stub_const("Settings", Class.new) @restrictions = [ Gitlab::VisibilityLevel::PUBLIC ]
@restrictions = double("restrictions") Gitlab.config.gitlab.stub(restricted_visibility_levels: @restrictions)
@restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } Gitlab.config.gitlab.stub(:default_projects_features).and_return(@settings)
Settings.stub_chain(:gitlab).and_return(@restrictions)
Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings)
end end
   
context 'should be private when option is public' do context 'should be private when option is public' do
Loading
@@ -155,4 +150,3 @@ describe Projects::CreateService do
Loading
@@ -155,4 +150,3 @@ describe Projects::CreateService do
Projects::CreateService.new(user, opts).execute Projects::CreateService.new(user, opts).execute
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment