diff options
Diffstat (limited to 'spec/services/todos/destroy')
-rw-r--r-- | spec/services/todos/destroy/design_service_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/todos/destroy/destroyed_issuable_service_spec.rb | 53 |
2 files changed, 38 insertions, 23 deletions
diff --git a/spec/services/todos/destroy/design_service_spec.rb b/spec/services/todos/destroy/design_service_spec.rb index 61a6718dc9d..92b25d94dc6 100644 --- a/spec/services/todos/destroy/design_service_spec.rb +++ b/spec/services/todos/destroy/design_service_spec.rb @@ -9,8 +9,8 @@ RSpec.describe Todos::Destroy::DesignService do let_it_be(:design_2) { create(:design) } let_it_be(:design_3) { create(:design) } - let_it_be(:create_action) { create(:design_action, design: design)} - let_it_be(:create_action_2) { create(:design_action, design: design_2)} + let_it_be(:create_action) { create(:design_action, design: design) } + let_it_be(:create_action_2) { create(:design_action, design: design_2) } describe '#execute' do before do @@ -23,8 +23,8 @@ RSpec.describe Todos::Destroy::DesignService do subject { described_class.new([design.id, design_2.id, design_3.id]).execute } context 'when the design has been archived' do - let_it_be(:archive_action) { create(:design_action, design: design, event: :deletion)} - let_it_be(:archive_action_2) { create(:design_action, design: design_3, event: :deletion)} + let_it_be(:archive_action) { create(:design_action, design: design, event: :deletion) } + let_it_be(:archive_action_2) { create(:design_action, design: design_3, event: :deletion) } it 'removes todos for that design' do expect { subject }.to change { Todo.count }.from(4).to(1) diff --git a/spec/services/todos/destroy/destroyed_issuable_service_spec.rb b/spec/services/todos/destroy/destroyed_issuable_service_spec.rb index 24f74bae7c8..6d6abe06d1c 100644 --- a/spec/services/todos/destroy/destroyed_issuable_service_spec.rb +++ b/spec/services/todos/destroy/destroyed_issuable_service_spec.rb @@ -4,31 +4,46 @@ 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)) } + let_it_be(:user) { create(:user) } - def execute - described_class.new(target.id, target.class.name).execute - end + subject { described_class.new(target.id, target.class.name).execute } + + context 'when target is merge request' do + let_it_be(:target) { create(:merge_request) } + let_it_be(:pending_todo) { create(:todo, :pending, project: target.project, target: target, user: user) } + let_it_be(:done_todo) { create(:todo, :done, project: target.project, target: target, user: user) } - it 'deletes todos for specified target ID and type' do - control_count = ActiveRecord::QueryRecorder.new { execute }.count + it 'deletes todos for specified target ID and type' do + control_count = ActiveRecord::QueryRecorder.new { subject }.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)) + # Create more todos for the target + create(:todo, :pending, project: target.project, target: target, user: user) + create(:todo, :pending, project: target.project, target: target, user: user) + create(:todo, :done, project: target.project, target: target, user: user) + create(:todo, :done, project: target.project, target: target, user: user) - expect { execute }.not_to exceed_query_limit(control_count) - expect(target.reload.todos.count).to eq(0) + expect { subject }.not_to exceed_query_limit(control_count) + end + + it 'invalidates todos cache counts of todo users', :use_clean_rails_redis_caching do + expect { subject } + .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 - 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) + context 'when target is an work item' do + let_it_be(:target) { create(:work_item) } + let_it_be(:todo1) { create(:todo, :pending, project: target.project, target: target, user: user) } + let_it_be(:todo2) { create(:todo, :done, project: target.project, target: target, user: user) } + # rubocop: disable Cop/AvoidBecomes + let_it_be(:todo3) { create(:todo, :pending, project: target.project, target: target.becomes(Issue), user: user) } + let_it_be(:todo4) { create(:todo, :done, project: target.project, target: target.becomes(Issue), user: user) } + # rubocop: enable Cop/AvoidBecomes + + it 'deletes todos' do + expect { subject }.to change(Todo, :count).by(-4) + end end end end |