diff options
| author | Nick Thomas <nick@gitlab.com> | 2017-06-01 17:30:01 +0100 |
|---|---|---|
| committer | Nick Thomas <nick@gitlab.com> | 2017-06-02 02:06:56 +0100 |
| commit | 7db09c63cc4532acea2d736f667b36c96b22007d (patch) | |
| tree | 432004de3b079aa5c9f9c6603c86be065df189e5 /spec | |
| parent | aff097e8f528ab5b00842df7c76d3435b1e59c96 (diff) | |
| download | gitlab-ce-7db09c63cc4532acea2d736f667b36c96b22007d.tar.gz | |
Fix hard-deleting users when they have authored issues
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/user_spec.rb | 2 | ||||
| -rw-r--r-- | spec/services/users/destroy_service_spec.rb | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fe9df3360ff..1c3541da44f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -22,7 +22,7 @@ describe User, models: true do it { is_expected.to have_many(:deploy_keys).dependent(:destroy) } it { is_expected.to have_many(:events).dependent(:destroy) } it { is_expected.to have_many(:recent_events).class_name('Event') } - it { is_expected.to have_many(:issues).dependent(:restrict_with_exception) } + it { is_expected.to have_many(:issues).dependent(:destroy) } it { is_expected.to have_many(:notes).dependent(:destroy) } it { is_expected.to have_many(:merge_requests).dependent(:destroy) } it { is_expected.to have_many(:identities).dependent(:destroy) } diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index de37a61e388..5409f67c091 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -147,16 +147,22 @@ describe Users::DestroyService, services: true do end context "migrating associated records" do + let!(:issue) { create(:issue, author: user) } + it 'delegates to the `MigrateToGhostUser` service to move associated records to the ghost user' do - expect_any_instance_of(Users::MigrateToGhostUserService).to receive(:execute).once + expect_any_instance_of(Users::MigrateToGhostUserService).to receive(:execute).once.and_call_original service.execute(user) + + expect(issue.reload.author).to be_ghost end it 'does not run `MigrateToGhostUser` if hard_delete option is given' do expect_any_instance_of(Users::MigrateToGhostUserService).not_to receive(:execute) service.execute(user, hard_delete: true) + + expect(Issue.exists?(issue.id)).to be_falsy end end end |
