diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-21 02:50:22 +0300 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/services/todos | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/services/todos')
-rw-r--r-- | spec/services/todos/destroy/destroyed_issuable_service_spec.rb | 34 | ||||
-rw-r--r-- | spec/services/todos/destroy/entity_leave_service_spec.rb | 27 |
2 files changed, 53 insertions, 8 deletions
diff --git a/spec/services/todos/destroy/destroyed_issuable_service_spec.rb b/spec/services/todos/destroy/destroyed_issuable_service_spec.rb new file mode 100644 index 00000000000..24f74bae7c8 --- /dev/null +++ b/spec/services/todos/destroy/destroyed_issuable_service_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Todos::Destroy::DestroyedIssuableService do + describe '#execute' do + let_it_be(:target) { create(:merge_request) } + let_it_be(:pending_todo) { create(:todo, :pending, project: target.project, target: target, user: create(:user)) } + let_it_be(:done_todo) { create(:todo, :done, project: target.project, target: target, user: create(:user)) } + + def execute + described_class.new(target.id, target.class.name).execute + end + + it 'deletes todos for specified target ID and type' do + control_count = ActiveRecord::QueryRecorder.new { execute }.count + + # Create more todos for the target + create(:todo, :pending, project: target.project, target: target, user: create(:user)) + create(:todo, :pending, project: target.project, target: target, user: create(:user)) + create(:todo, :done, project: target.project, target: target, user: create(:user)) + create(:todo, :done, project: target.project, target: target, user: create(:user)) + + expect { execute }.not_to exceed_query_limit(control_count) + expect(target.reload.todos.count).to eq(0) + end + + it 'invalidates todos cache counts of todo users', :use_clean_rails_redis_caching do + expect { execute } + .to change { pending_todo.user.todos_pending_count }.from(1).to(0) + .and change { done_todo.user.todos_done_count }.from(1).to(0) + end + end +end diff --git a/spec/services/todos/destroy/entity_leave_service_spec.rb b/spec/services/todos/destroy/entity_leave_service_spec.rb index 4126eb88b0b..03fa2482bbf 100644 --- a/spec/services/todos/destroy/entity_leave_service_spec.rb +++ b/spec/services/todos/destroy/entity_leave_service_spec.rb @@ -224,6 +224,8 @@ RSpec.describe Todos::Destroy::EntityLeaveService do end context 'with nested groups' do + let(:parent_group) { create(:group, :public) } + let(:parent_subgroup) { create(:group)} let(:subgroup) { create(:group, :private, parent: group) } let(:subgroup2) { create(:group, :private, parent: group) } let(:subproject) { create(:project, group: subgroup) } @@ -235,12 +237,17 @@ RSpec.describe Todos::Destroy::EntityLeaveService do let!(:todo_subgroup2_user) { create(:todo, user: user, group: subgroup2) } let!(:todo_subproject_user2) { create(:todo, user: user2, project: subproject) } let!(:todo_subpgroup_user2) { create(:todo, user: user2, group: subgroup) } + let!(:todo_parent_group_user) { create(:todo, user: user, group: parent_group) } + + before do + group.update!(parent: parent_group) + end context 'when the user is not a member of any groups/projects' do it 'removes todos for the user including subprojects todos' do - expect { subject }.to change { Todo.count }.from(12).to(4) + expect { subject }.to change { Todo.count }.from(13).to(5) - expect(user.todos).to be_empty + expect(user.todos).to eq([todo_parent_group_user]) expect(user2.todos) .to match_array( [todo_issue_c_user2, todo_group_user2, todo_subproject_user2, todo_subpgroup_user2] @@ -250,8 +257,6 @@ RSpec.describe Todos::Destroy::EntityLeaveService do context 'when the user is member of a parent group' do before do - parent_group = create(:group) - group.update!(parent: parent_group) parent_group.add_developer(user) end @@ -264,9 +269,12 @@ RSpec.describe Todos::Destroy::EntityLeaveService do end it 'does not remove group and subproject todos' do - expect { subject }.to change { Todo.count }.from(12).to(7) + expect { subject }.to change { Todo.count }.from(13).to(8) - expect(user.todos).to match_array([todo_group_user, todo_subgroup_user, todo_subproject_user]) + expect(user.todos) + .to match_array( + [todo_group_user, todo_subgroup_user, todo_subproject_user, todo_parent_group_user] + ) expect(user2.todos) .to match_array( [todo_issue_c_user2, todo_group_user2, todo_subproject_user2, todo_subpgroup_user2] @@ -280,9 +288,12 @@ RSpec.describe Todos::Destroy::EntityLeaveService do end it 'does not remove subproject and group todos' do - expect { subject }.to change { Todo.count }.from(12).to(7) + expect { subject }.to change { Todo.count }.from(13).to(8) - expect(user.todos).to match_array([todo_subgroup_user, todo_group_user, todo_subproject_user]) + expect(user.todos) + .to match_array( + [todo_subgroup_user, todo_group_user, todo_subproject_user, todo_parent_group_user] + ) expect(user2.todos) .to match_array( [todo_issue_c_user2, todo_group_user2, todo_subproject_user2, todo_subpgroup_user2] |