diff options
author | dixpac <dino.onex@gmail.com> | 2016-08-13 15:45:31 +0300 |
---|---|---|
committer | dixpac <dino.onex@gmail.com> | 2017-02-08 11:16:43 +0300 |
commit | 0dacf3c169a85e6f3a1c70f3f5e377d47f770d19 (patch) | |
tree | 9a7ceb14b6a7aa96636a4024df06fa37c782a3ee /spec/services/users | |
parent | a965edb89d3c260394ffc987832a469e7740415d (diff) |
Fix inconsistent naming for services that delete things
* Changed name of delete_user_service and worker to destroy
* Move and change delete_group_service to Groups::DestroyService
* Rename Notes::DeleteService to Notes::DestroyService
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/destroy_spec.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/spec/services/users/destroy_spec.rb b/spec/services/users/destroy_spec.rb new file mode 100644 index 00000000000..46e58393218 --- /dev/null +++ b/spec/services/users/destroy_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe Users::DestroyService, services: true do + describe "Deletes a user and all their personal projects" do + let!(:user) { create(:user) } + let!(:current_user) { create(:user) } + let!(:namespace) { create(:namespace, owner: user) } + let!(:project) { create(:project, namespace: namespace) } + let(:service) { described_class.new(current_user) } + + context 'no options are given' do + it 'deletes the user' do + user_data = service.execute(user) + + expect { user_data['email'].to eq(user.email) } + expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) + expect { Namespace.with_deleted.find(user.namespace.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'will delete the project in the near future' do + expect_any_instance_of(Projects::DestroyService).to receive(:async_execute).once + + service.execute(user) + end + end + + context "solo owned groups present" do + let(:solo_owned) { create(:group) } + let(:member) { create(:group_member) } + let(:user) { member.user } + + before do + solo_owned.group_members = [member] + service.execute(user) + end + + it 'does not delete the user' do + expect(User.find(user.id)).to eq user + end + end + + context "deletions with solo owned groups" do + let(:solo_owned) { create(:group) } + let(:member) { create(:group_member) } + let(:user) { member.user } + + before do + solo_owned.group_members = [member] + service.execute(user, delete_solo_owned_groups: true) + end + + it 'deletes solo owned groups' do + expect { Project.find(solo_owned.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'deletes the user' do + expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + end + end +end |