Commit 73f91da8 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix project deletion and tests

parent 6d352790
...@@ -98,8 +98,7 @@ class ProjectsController < ApplicationController ...@@ -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 }
......
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
......
...@@ -65,26 +65,4 @@ describe Event do ...@@ -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
...@@ -25,13 +25,14 @@ describe SystemHook do ...@@ -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
......
...@@ -63,11 +63,8 @@ describe Projects::CreateService do ...@@ -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
...@@ -106,11 +103,9 @@ describe Projects::CreateService do ...@@ -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
...@@ -155,4 +150,3 @@ describe Projects::CreateService do ...@@ -155,4 +150,3 @@ describe Projects::CreateService do
Projects::CreateService.new(user, opts).execute Projects::CreateService.new(user, opts).execute
end end
end end
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