debian-mirror-gitlab/spec/services/todos/destroy/destroyed_issuable_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
2.2 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Todos::Destroy::DestroyedIssuableService, feature_category: :team_planning do
2021-04-29 21:17:54 +05:30
describe '#execute' do
2022-08-27 11:52:29 +05:30
let_it_be(:user) { create(:user) }
2021-04-29 21:17:54 +05:30
2022-08-27 11:52:29 +05:30
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) }
2021-04-29 21:17:54 +05:30
2022-08-27 11:52:29 +05:30
it 'deletes todos for specified target ID and type' do
control_count = ActiveRecord::QueryRecorder.new { subject }.count
2021-04-29 21:17:54 +05:30
2022-08-27 11:52:29 +05:30
# 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)
2021-04-29 21:17:54 +05:30
2022-08-27 11:52:29 +05:30
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
2021-04-29 21:17:54 +05:30
end
2022-08-27 11:52:29 +05:30
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
2021-04-29 21:17:54 +05:30
end
end
end