Fix project deletion and tests
This commit is contained in:
		
							parent
							
								
									6d352790c4
								
							
						
					
					
						commit
						73f91da8b1
					
				|  | @ -98,8 +98,7 @@ class ProjectsController < ApplicationController | |||
|   def destroy | ||||
|     return access_denied! unless can?(current_user, :remove_project, project) | ||||
| 
 | ||||
|     project.team.truncate | ||||
|     project.destroy | ||||
|     ::Projects::DestroyService.new(@project, current_user, {}).execute | ||||
| 
 | ||||
|     respond_to do |format| | ||||
|       format.html { redirect_to root_path } | ||||
|  |  | |||
|  | @ -1,8 +1,9 @@ | |||
| module Projects | ||||
|   class UpdateService < BaseService | ||||
|     def execute(role = :default) | ||||
|   class DestroyService < BaseService | ||||
|     def execute | ||||
|       return false unless can?(current_user, :remove_project, project) | ||||
| 
 | ||||
|       project.team.truncate | ||||
|       project.repository.expire_cache unless project.empty_repo? | ||||
| 
 | ||||
|       if project.destroy | ||||
|  |  | |||
|  | @ -65,26 +65,4 @@ describe Event do | |||
|     it { @event.branch_name.should == "master" } | ||||
|     it { @event.author.should == @user } | ||||
|   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 | ||||
|  |  | |||
|  | @ -25,13 +25,14 @@ describe SystemHook do | |||
|     end | ||||
| 
 | ||||
|     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 | ||||
|     end | ||||
| 
 | ||||
|     it "project_destroy hook" do | ||||
|       project = create(:project) | ||||
|       project.destroy | ||||
|       user = create(:user) | ||||
|       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 | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -63,11 +63,8 @@ describe Projects::CreateService do | |||
|         @settings.stub(:merge_requests) { true } | ||||
|         @settings.stub(:wiki) { true } | ||||
|         @settings.stub(:snippets) { true } | ||||
|         stub_const("Settings", Class.new) | ||||
|         @restrictions = double("restrictions") | ||||
|         @restrictions.stub(:restricted_visibility_levels) { [] } | ||||
|         Settings.stub_chain(:gitlab).and_return(@restrictions) | ||||
|         Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | ||||
|         Gitlab.config.gitlab.stub(restricted_visibility_levels: []) | ||||
|         Gitlab.config.gitlab.stub(:default_projects_features).and_return(@settings) | ||||
|       end | ||||
| 
 | ||||
|       context 'should be public when setting is public' do | ||||
|  | @ -106,11 +103,9 @@ describe Projects::CreateService do | |||
|         @settings.stub(:wiki) { true } | ||||
|         @settings.stub(:snippets) { true } | ||||
|         @settings.stub(:visibility_level) { Gitlab::VisibilityLevel::PRIVATE } | ||||
|         stub_const("Settings", Class.new) | ||||
|         @restrictions = double("restrictions") | ||||
|         @restrictions.stub(:restricted_visibility_levels) { [ Gitlab::VisibilityLevel::PUBLIC ] } | ||||
|         Settings.stub_chain(:gitlab).and_return(@restrictions) | ||||
|         Settings.stub_chain(:gitlab, :default_projects_features).and_return(@settings) | ||||
|         @restrictions = [ Gitlab::VisibilityLevel::PUBLIC ] | ||||
|         Gitlab.config.gitlab.stub(restricted_visibility_levels: @restrictions) | ||||
|         Gitlab.config.gitlab.stub(:default_projects_features).and_return(@settings) | ||||
|       end | ||||
| 
 | ||||
|       context 'should be private when option is public' do | ||||
|  | @ -155,4 +150,3 @@ describe Projects::CreateService do | |||
|     Projects::CreateService.new(user, opts).execute | ||||
|   end | ||||
| end | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue