diff --git a/app/controllers/projects/pages_controller.rb b/app/controllers/projects/pages_controller.rb index cae6e2c40b861600db3f1d0b5f3f95a6e3ce9f5d..ff49911d892548c6cf5a5489494aabd67b80089b 100644 --- a/app/controllers/projects/pages_controller.rb +++ b/app/controllers/projects/pages_controller.rb @@ -11,7 +11,7 @@ def show def destroy project.remove_pages - project.pages_domains.destroy_all + project.pages_domains.destroy_all # rubocop: disable DestroyAll respond_to do |format| format.html do diff --git a/app/models/concerns/awardable.rb b/app/models/concerns/awardable.rb index dd07f389fa5f6ffd9bbf38689195b89bd533106c..49981db0d80bef62c4fa44a41253b401ee350b98 100644 --- a/app/models/concerns/awardable.rb +++ b/app/models/concerns/awardable.rb @@ -101,7 +101,7 @@ def create_award_emoji(name, current_user) end def remove_award_emoji(name, current_user) - award_emoji.where(name: name, user: current_user).destroy_all + award_emoji.where(name: name, user: current_user).destroy_all # rubocop: disable DestroyAll end def toggle_award_emoji(emoji_name, current_user) diff --git a/app/models/concerns/fast_destroy_all.rb b/app/models/concerns/fast_destroy_all.rb index 65ed46ea202eb34a4501dec05bcd46f96bb93911..c342d01243ea32df5824dfb20b49ee08c09dbd7c 100644 --- a/app/models/concerns/fast_destroy_all.rb +++ b/app/models/concerns/fast_destroy_all.rb @@ -34,7 +34,7 @@ module FastDestroyAll included do before_destroy do - raise ForbiddenActionError, '`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`' + raise ForbiddenActionError, '`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`' end end diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb index f8c2d1035f77d9ce6849f9276fd03aae39603f5e..358fa1b8168e0e2691eaa0c63069b3c2a38aaf69 100644 --- a/app/models/lfs_object.rb +++ b/app/models/lfs_object.rb @@ -30,11 +30,13 @@ def local_store? [nil, LfsObjectUploader::Store::LOCAL].include?(self.file_store) end + # rubocop: disable DestroyAll def self.destroy_unreferenced joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id") .where(lfs_objects_projects: { id: nil }) .destroy_all end + # rubocop: enable DestroyAll def self.calculate_oid(path) Digest::SHA256.file(path).hexdigest diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb index 705487f82a0c5f5cecfa369c5ceb882afa5fef42..00531c3b4c503be64d0b785fc049847a7a2f8072 100644 --- a/app/models/members/project_member.rb +++ b/app/models/members/project_member.rb @@ -97,8 +97,8 @@ def notifiable_options def delete_member_branch_protection if user.present? && project.present? - project.protected_branches.merge_access_by_user(user).destroy_all - project.protected_branches.push_access_by_user(user).destroy_all + project.protected_branches.merge_access_by_user(user).destroy_all # rubocop: disable DestroyAll + project.protected_branches.push_access_by_user(user).destroy_all # rubocop: disable DestroyAll end end diff --git a/app/models/project_group_link.rb b/app/models/project_group_link.rb index 2b5f4082aec9e3d565adb95c7a079de6e972076a..c60480c75f93012cd156003455cf0a1ef5050626 100644 --- a/app/models/project_group_link.rb +++ b/app/models/project_group_link.rb @@ -51,8 +51,8 @@ def different_group def delete_branch_protection if group.present? && project.present? - project.protected_branches.merge_access_by_group(group).destroy_all - project.protected_branches.push_access_by_group(group).destroy_all + project.protected_branches.merge_access_by_group(group).destroy_all # rubocop: disable DestroyAll + project.protected_branches.push_access_by_group(group).destroy_all # rubocop: disable DestroyAll end end diff --git a/app/models/user.rb b/app/models/user.rb index 38f98f26bf88a0646a908a8c3f864e4bfbea8f7f..d2823016308a7922c5af9bdba04f8dad63597412 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -534,7 +534,7 @@ def disable_two_factor! otp_grace_period_started_at: nil, otp_backup_codes: nil ) - self.u2f_registrations.destroy_all + self.u2f_registrations.destroy_all # rubocop: disable DestroyAll end end diff --git a/app/services/labels/promote_service.rb b/app/services/labels/promote_service.rb index c0463052821905d42b58fb3d5beebbc2200211b8..623a5f0950e3e18f7b7992d8ae5246b72aaebf04 100644 --- a/app/services/labels/promote_service.rb +++ b/app/services/labels/promote_service.rb @@ -65,7 +65,7 @@ def update_priorities(new_label, label_ids) end def update_project_labels(label_ids) - Label.where(id: label_ids).destroy_all + Label.where(id: label_ids).destroy_all # rubocop: disable DestroyAll end def clone_label_to_group_label(label) diff --git a/app/services/milestones/promote_service.rb b/app/services/milestones/promote_service.rb index f2e2a8a04d02ea7e131879eafa2352015a1b9dfc..75475f263d7ad91515fa00766169829dd7ff6e73 100644 --- a/app/services/milestones/promote_service.rb +++ b/app/services/milestones/promote_service.rb @@ -75,7 +75,7 @@ def group end def destroy_old_milestones(milestone) - Milestone.where(id: milestone_ids_for_merge(milestone)).destroy_all + Milestone.where(id: milestone_ids_for_merge(milestone)).destroy_all # rubocop: disable DestroyAll end def group_project_ids diff --git a/app/services/projects/move_deploy_keys_projects_service.rb b/app/services/projects/move_deploy_keys_projects_service.rb index 40a22837eafa35f42af31ec10a62287544d51b90..9f3f44f30eac3c5d9a53f1022f08fa235df207f3 100644 --- a/app/services/projects/move_deploy_keys_projects_service.rb +++ b/app/services/projects/move_deploy_keys_projects_service.rb @@ -27,7 +27,7 @@ def non_existent_deploy_keys_projects end def remove_remaining_deploy_keys_projects - source_project.deploy_keys_projects.destroy_all + source_project.deploy_keys_projects.destroy_all # rubocop: disable DestroyAll end end end diff --git a/app/services/projects/move_lfs_objects_projects_service.rb b/app/services/projects/move_lfs_objects_projects_service.rb index a509951959482e5802b3dbf16a40ffab5dee7ee3..f78546a1e9c283d70427e03e4f9db379d9642e2d 100644 --- a/app/services/projects/move_lfs_objects_projects_service.rb +++ b/app/services/projects/move_lfs_objects_projects_service.rb @@ -21,7 +21,7 @@ def move_lfs_objects_projects end def remove_remaining_lfs_objects_project - source_project.lfs_objects_projects.destroy_all + source_project.lfs_objects_projects.destroy_all # rubocop: disable DestroyAll end def non_existent_lfs_objects_projects diff --git a/app/services/projects/move_notification_settings_service.rb b/app/services/projects/move_notification_settings_service.rb index 746605d56f19b64f4af40895b5989bc3533af97a..109a00dd6d9d719cecf6badd972f56b79ac992a2 100644 --- a/app/services/projects/move_notification_settings_service.rb +++ b/app/services/projects/move_notification_settings_service.rb @@ -22,7 +22,7 @@ def move_notification_settings # Remove remaining notification settings from source_project def remove_remaining_notification_settings - source_project.notification_settings.destroy_all + source_project.notification_settings.destroy_all # rubocop: disable DestroyAll end # Get users of current notification_settings diff --git a/app/services/projects/move_project_group_links_service.rb b/app/services/projects/move_project_group_links_service.rb index d9038030f7e87135aafb618355eed0a9d1a3020c..1efafdce36d8e383eaa3479a67c0b47f9ae42f2e 100644 --- a/app/services/projects/move_project_group_links_service.rb +++ b/app/services/projects/move_project_group_links_service.rb @@ -26,7 +26,7 @@ def move_group_links # Remove remaining project group links from source_project def remove_remaining_project_group_links - source_project.reload.project_group_links.destroy_all + source_project.reload.project_group_links.destroy_all # rubocop: disable DestroyAll end def group_links_in_target_project diff --git a/app/services/projects/move_project_members_service.rb b/app/services/projects/move_project_members_service.rb index bb0c0d10242729248a7d4b2e45dd0f3140566fe7..ec983582d94b34af20e364aee3cb81fd93ee47d9 100644 --- a/app/services/projects/move_project_members_service.rb +++ b/app/services/projects/move_project_members_service.rb @@ -25,7 +25,7 @@ def move_project_members def remove_remaining_members # Remove remaining members and authorizations from source_project - source_project.project_members.destroy_all + source_project.project_members.destroy_all # rubocop: disable DestroyAll end def project_members_in_target_project diff --git a/app/services/protected_branches/legacy_api_update_service.rb b/app/services/protected_branches/legacy_api_update_service.rb index 42c0712bd6da8634ab97295771c190de0b9f5c1f..4cb78c4aeb1ead95588e34965971df9f605ec991 100644 --- a/app/services/protected_branches/legacy_api_update_service.rb +++ b/app/services/protected_branches/legacy_api_update_service.rb @@ -38,11 +38,11 @@ def execute(protected_branch) def delete_redundant_access_levels unless @developers_can_merge.nil? - @protected_branch.merge_access_levels.destroy_all + @protected_branch.merge_access_levels.destroy_all # rubocop: disable DestroyAll # rubocop: disable DestroyAll end unless @developers_can_push.nil? - @protected_branch.push_access_levels.destroy_all + @protected_branch.push_access_levels.destroy_all # rubocop: disable DestroyAll # rubocop: disable DestroyAll end end @@ -52,18 +52,18 @@ def delete_redundant_access_levels def delete_redundant_ee_access_levels case @developers_can_merge when true - @protected_branch.merge_access_levels.developer.destroy_all + @protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll when false - @protected_branch.merge_access_levels.developer.destroy_all - @protected_branch.merge_access_levels.maintainer.destroy_all + @protected_branch.merge_access_levels.developer.destroy_all # rubocop: disable DestroyAll + @protected_branch.merge_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll end case @developers_can_push when true - @protected_branch.push_access_levels.developer.destroy_all + @protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll when false - @protected_branch.push_access_levels.developer.destroy_all - @protected_branch.push_access_levels.maintainer.destroy_all + @protected_branch.push_access_levels.developer.destroy_all # rubocop: disable DestroyAll + @protected_branch.push_access_levels.maintainer.destroy_all # rubocop: disable DestroyAll end end end diff --git a/app/workers/remove_expired_group_links_worker.rb b/app/workers/remove_expired_group_links_worker.rb index 6b8b972a440c738ac302066e3fe718b8c022ecaf..25128caf72fa6d18356f5ae48cd56b28a844e28b 100644 --- a/app/workers/remove_expired_group_links_worker.rb +++ b/app/workers/remove_expired_group_links_worker.rb @@ -5,6 +5,6 @@ class RemoveExpiredGroupLinksWorker include CronjobQueue def perform - ProjectGroupLink.expired.destroy_all + ProjectGroupLink.expired.destroy_all # rubocop: disable DestroyAll end end diff --git a/app/workers/remove_old_web_hook_logs_worker.rb b/app/workers/remove_old_web_hook_logs_worker.rb index 17140ac44500dfb40857cf160375a13b097c5d4f..0f486f8991d68e5848c3bd8013632851620a3312 100644 --- a/app/workers/remove_old_web_hook_logs_worker.rb +++ b/app/workers/remove_old_web_hook_logs_worker.rb @@ -6,7 +6,9 @@ class RemoveOldWebHookLogsWorker WEB_HOOK_LOG_LIFETIME = 2.days + # rubocop: disable DestroyAll def perform WebHookLog.destroy_all(['created_at < ?', Time.now - WEB_HOOK_LOG_LIFETIME]) end + # rubocop: enable DestroyAll end diff --git a/db/migrate/20160712171823_remove_award_emojis_with_no_user.rb b/db/migrate/20160712171823_remove_award_emojis_with_no_user.rb index 668c22bb51c7a33192b0f640aedd778aaad43be2..8ebf1a5234dc0591160cd139c765fc61ad4f3b40 100644 --- a/db/migrate/20160712171823_remove_award_emojis_with_no_user.rb +++ b/db/migrate/20160712171823_remove_award_emojis_with_no_user.rb @@ -16,6 +16,6 @@ class RemoveAwardEmojisWithNoUser < ActiveRecord::Migration # disable_ddl_transaction! def up - AwardEmoji.joins('LEFT JOIN users ON users.id = user_id').where('users.id IS NULL').destroy_all + AwardEmoji.joins('LEFT JOIN users ON users.id = user_id').where('users.id IS NULL').destroy_all # rubocop: disable DestroyAll end end diff --git a/ee/app/controllers/groups/ldap_group_links_controller.rb b/ee/app/controllers/groups/ldap_group_links_controller.rb index e6eb2d68f2515e5b87c07a6b51082c41d182d48a..835f6fac6c10a52ced656b381354a4cc4563bd01 100644 --- a/ee/app/controllers/groups/ldap_group_links_controller.rb +++ b/ee/app/controllers/groups/ldap_group_links_controller.rb @@ -26,7 +26,7 @@ def create end def destroy - @group.ldap_group_links.where(id: params[:id]).destroy_all + @group.ldap_group_links.where(id: params[:id]).destroy_all # rubocop: disable DestroyAll redirect_back_or_default(default: { action: 'index' }, options: { notice: 'LDAP link removed' }) end diff --git a/ee/app/services/concerns/cleanup_approvers.rb b/ee/app/services/concerns/cleanup_approvers.rb index 927d5a99768cc5208a7a6dfee78a0220d669378c..f60829c1a0111e0065979370fe34dc6ba3636cb7 100644 --- a/ee/app/services/concerns/cleanup_approvers.rb +++ b/ee/app/services/concerns/cleanup_approvers.rb @@ -7,8 +7,8 @@ module CleanupApprovers private def cleanup_approvers(target, reload: false) - target.approvers.where.not(user_id: params[:approver_ids]).destroy_all - target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all + target.approvers.where.not(user_id: params[:approver_ids]).destroy_all # rubocop: disable DestroyAll + target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all # rubocop: disable DestroyAll # If the target already has `approvers` and/or `approver_groups` loaded then we need to # force a reload in order to not return stale information after the destroys above diff --git a/ee/app/services/merge_requests/remove_approval_service.rb b/ee/app/services/merge_requests/remove_approval_service.rb index d23e6c108eadc694b91991b6fe7d8aceef1eda74..3df58dafae0d6552ba2327a979b7cf0333b11e59 100644 --- a/ee/app/services/merge_requests/remove_approval_service.rb +++ b/ee/app/services/merge_requests/remove_approval_service.rb @@ -8,7 +8,7 @@ def execute(merge_request) currently_approved = merge_request.approved? - if approval.destroy_all + if approval.destroy_all # rubocop: disable DestroyAll merge_request.reset_approval_cache! create_note(merge_request) diff --git a/ee/spec/controllers/projects/settings/integrations_controller_spec.rb b/ee/spec/controllers/projects/settings/integrations_controller_spec.rb index 4e6ac81a2a7cba2310891de4c1a4ebf608207fc3..09badab698326abdcee05824c0ea985a7f9b538b 100644 --- a/ee/spec/controllers/projects/settings/integrations_controller_spec.rb +++ b/ee/spec/controllers/projects/settings/integrations_controller_spec.rb @@ -48,7 +48,7 @@ context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it_behaves_like 'endpoint with some disabled services' diff --git a/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb b/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb index a39fe0dc6a673a308386f33cf158367076f64a65..33c84d8ee31e68ae04806377a57dd22ed8629802 100644 --- a/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb +++ b/ee/spec/features/admin/licenses/admin_uploads_license_spec.rb @@ -11,7 +11,7 @@ set(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) } before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll visit(admin_license_path(trial_key: license.data)) end diff --git a/ee/spec/lib/gitlab/database/load_balancing_spec.rb b/ee/spec/lib/gitlab/database/load_balancing_spec.rb index 3178d6067a1fa9f3218ad0e77c3477c528ca55db..e70916c18eef5c91f4399f96ee926e14e7ed2a26 100644 --- a/ee/spec/lib/gitlab/database/load_balancing_spec.rb +++ b/ee/spec/lib/gitlab/database/load_balancing_spec.rb @@ -156,7 +156,7 @@ context 'without a license' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it 'is disabled' do diff --git a/ee/spec/models/burndown_spec.rb b/ee/spec/models/burndown_spec.rb index ebda38352c7d29677b725a20700314cc1776e496..935c07058328f7b17ed9ae6011b06be3dfeb18a0 100644 --- a/ee/spec/models/burndown_spec.rb +++ b/ee/spec/models/burndown_spec.rb @@ -53,7 +53,7 @@ context "when all closed issues does not have closed events" do before do - Event.where(target: milestone.issues, action: Event::CLOSED).destroy_all + Event.where(target: milestone.issues, action: Event::CLOSED).destroy_all # rubocop: disable DestroyAll end it "considers closed_at as milestone start date" do @@ -73,7 +73,7 @@ context "when one or more closed issues does not have a closed event" do before do - Event.where(target: milestone.issues.closed.first, action: Event::CLOSED).destroy_all + Event.where(target: milestone.issues.closed.first, action: Event::CLOSED).destroy_all # rubocop: disable DestroyAll end it "sets attribute accurate to false" do diff --git a/ee/spec/models/license_spec.rb b/ee/spec/models/license_spec.rb index 194a9c9015e3c843ba810468ba6b09ee5262d588..c48ba2d5314b7c28ca484d8e4d2156fdee4f5169 100644 --- a/ee/spec/models/license_spec.rb +++ b/ee/spec/models/license_spec.rb @@ -560,7 +560,7 @@ let(:license) { create(:license, trial: true, expired: true) } before(:all) do - described_class.destroy_all + described_class.destroy_all # rubocop: disable DestroyAll end ::License::EES_FEATURES.each do |feature| diff --git a/ee/spec/models/project_services/jenkins_deprecated_service_spec.rb b/ee/spec/models/project_services/jenkins_deprecated_service_spec.rb index 3c6f1085bca6afcfcdf2b8bce6bb0ecb202b8c82..bb003aab761a94cfe9374446a785671d4b731e44 100644 --- a/ee/spec/models/project_services/jenkins_deprecated_service_spec.rb +++ b/ee/spec/models/project_services/jenkins_deprecated_service_spec.rb @@ -134,7 +134,7 @@ def status_body_for_icon(state) context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it_behaves_like 'a disabled jenkins deprecated service' diff --git a/ee/spec/models/project_services/jenkins_service_spec.rb b/ee/spec/models/project_services/jenkins_service_spec.rb index df5777e2cc5d629c5f00243bc12e491e38c07cdd..98b75648919e7db841fa180c5dd58117857fbbcb 100644 --- a/ee/spec/models/project_services/jenkins_service_spec.rb +++ b/ee/spec/models/project_services/jenkins_service_spec.rb @@ -164,7 +164,7 @@ context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it_behaves_like 'project with disabled Jenkins service' diff --git a/ee/spec/models/project_spec.rb b/ee/spec/models/project_spec.rb index ada88a6bf7c3845320e9a2b656a30b4eca937fd2..111a0ffc45b67240c6b11089ae6bebc0bc598c25 100644 --- a/ee/spec/models/project_spec.rb +++ b/ee/spec/models/project_spec.rb @@ -774,7 +774,7 @@ context 'without a License' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it 'is disabled' do @@ -1123,7 +1123,7 @@ context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it_behaves_like 'project with disabled services' diff --git a/ee/spec/spec_helper.rb b/ee/spec/spec_helper.rb index b30defdaf9a388ef7d11add920cb489fb0a0fe4e..2d5d371cc7185745e034cf71805eed1117f91aba 100644 --- a/ee/spec/spec_helper.rb +++ b/ee/spec/spec_helper.rb @@ -7,7 +7,7 @@ config.include EE::LicenseHelpers config.before(:all) do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll TestLicense.init end diff --git a/ee/spec/workers/historical_data_worker_spec.rb b/ee/spec/workers/historical_data_worker_spec.rb index 4a17a50bc45865f38e2df07022fbae9e8e8595d3..239380e527a4116da8c6539760162fc3c0ddd1ff 100644 --- a/ee/spec/workers/historical_data_worker_spec.rb +++ b/ee/spec/workers/historical_data_worker_spec.rb @@ -30,7 +30,7 @@ context 'when there is not a license key' do it 'does not track historical data' do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll expect(HistoricalData).not_to receive(:track!) diff --git a/ee/spec/workers/ldap_all_groups_sync_worker_spec.rb b/ee/spec/workers/ldap_all_groups_sync_worker_spec.rb index d307105408a30ae157f8a106ec4562e38070bd4b..56386a8f3fa7f1f3d178d8d6fbeb66668981fa13 100644 --- a/ee/spec/workers/ldap_all_groups_sync_worker_spec.rb +++ b/ee/spec/workers/ldap_all_groups_sync_worker_spec.rb @@ -19,7 +19,7 @@ context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it 'does not sync all groups' do diff --git a/ee/spec/workers/ldap_group_sync_worker_spec.rb b/ee/spec/workers/ldap_group_sync_worker_spec.rb index 0b98b90a5b7a11762cd8d82483c14647b084def1..1eb224af2accc6695d5d2f6d4889083635619ff1 100644 --- a/ee/spec/workers/ldap_group_sync_worker_spec.rb +++ b/ee/spec/workers/ldap_group_sync_worker_spec.rb @@ -35,7 +35,7 @@ def expect_fake_proxy(provider) context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it 'does not sync groups' do diff --git a/ee/spec/workers/ldap_sync_worker_spec.rb b/ee/spec/workers/ldap_sync_worker_spec.rb index cbe34fe3148d6dd992514e4075e251aef6439ef2..ae9af69de45685db882a021970e6ffc9498c11c7 100644 --- a/ee/spec/workers/ldap_sync_worker_spec.rb +++ b/ee/spec/workers/ldap_sync_worker_spec.rb @@ -21,7 +21,7 @@ context 'without a license key' do before do - License.destroy_all + License.destroy_all # rubocop: disable DestroyAll end it 'does not sync LDAP users' do diff --git a/lib/gitlab/import_export/members_mapper.rb b/lib/gitlab/import_export/members_mapper.rb index ac827cbe1ca892c97428c5860274cf0328827350..bcbaf00e11b978a86d624c2ea5ae94bbfcbc9c73 100644 --- a/lib/gitlab/import_export/members_mapper.rb +++ b/lib/gitlab/import_export/members_mapper.rb @@ -45,7 +45,7 @@ def missing_keys_tracking_hash end def ensure_default_member! - @project.project_members.destroy_all + @project.project_members.destroy_all # rubocop: disable DestroyAll ProjectMember.create!(user: @user, access_level: ProjectMember::MAINTAINER, source_id: @project.id, importing: true) end diff --git a/rubocop/cop/destroy_all.rb b/rubocop/cop/destroy_all.rb new file mode 100644 index 0000000000000000000000000000000000000000..38b6cb40f91fc1e7f68e67cf670089e5721ab2ef --- /dev/null +++ b/rubocop/cop/destroy_all.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + # Cop that blacklists the use of `destroy_all`. + class DestroyAll < RuboCop::Cop::Cop + MSG = 'Use `delete_all` instead of `destroy_all`. ' \ + '`destroy_all` will load the rows into memory, then execute a ' \ + '`DELETE` for every individual row.' + + def_node_matcher :destroy_all?, <<~PATTERN + (send {send ivar lvar const} :destroy_all ...) + PATTERN + + def on_send(node) + return unless destroy_all?(node) + + add_offense(node, location: :expression) + end + end + end +end diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb index a427208cdabcc6363d01eb3e584e8c5db5c89cc2..88c9bbf24f498aff2d621d9078ba1b3104ad057b 100644 --- a/rubocop/rubocop.rb +++ b/rubocop/rubocop.rb @@ -27,3 +27,4 @@ require_relative 'cop/rspec/env_assignment' require_relative 'cop/rspec/factories_in_migration_specs' require_relative 'cop/sidekiq_options_queue' +require_relative 'cop/destroy_all' diff --git a/spec/controllers/omniauth_callbacks_controller_spec.rb b/spec/controllers/omniauth_callbacks_controller_spec.rb index b23f183fec8c607dc542c743cb8e85d2b3abc620..d377d69457f03c212551afe1a68efdd7df1c93d0 100644 --- a/spec/controllers/omniauth_callbacks_controller_spec.rb +++ b/spec/controllers/omniauth_callbacks_controller_spec.rb @@ -95,7 +95,7 @@ end it 'allows linking the disabled provider' do - user.identities.destroy_all + user.identities.destroy_all # rubocop: disable DestroyAll sign_in(user) expect { post provider }.to change { user.reload.identities.count }.by(1) diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index fc1619acec6aabae5b79aeb448246607bc94c2ae..20a6beb3df8b443b9f91cffc1d3839cce09c6139 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -14,7 +14,7 @@ describe 'GET #edit' do it 'initializes a new release' do tag_id = release.tag - project.releases.destroy_all + project.releases.destroy_all # rubocop: disable DestroyAll get :edit, namespace_id: project.namespace, project_id: project, tag_id: tag_id diff --git a/spec/lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys_spec.rb b/spec/lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys_spec.rb index 26d48cc820137e4656ef57cbda40712ef327e865..f92acf6168235a7442bd6f20149590c5ad036034 100644 --- a/spec/lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys_spec.rb +++ b/spec/lib/gitlab/background_migration/create_gpg_key_subkeys_from_gpg_keys_spec.rb @@ -5,7 +5,7 @@ let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) } before do - GpgKeySubkey.destroy_all + GpgKeySubkey.destroy_all # rubocop: disable DestroyAll end it 'generate the subkeys' do diff --git a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb index 96bef1075990d1a2b7abc71ef295f4a4a764761e..c4427910518d734d3e905beb281d2eab615e010e 100644 --- a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb +++ b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb @@ -6,7 +6,7 @@ create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs # Delete all subkeys so they can be recreated - GpgKeySubkey.destroy_all + GpgKeySubkey.destroy_all # rubocop: disable DestroyAll end it 'correctly schedules background migrations' do diff --git a/spec/models/fork_network_member_spec.rb b/spec/models/fork_network_member_spec.rb index 25bf596fddcb14ae0d48d6e34938ad0218835ac5..60d04562e6c99fa86bec74973a4c1292ca70823e 100644 --- a/spec/models/fork_network_member_spec.rb +++ b/spec/models/fork_network_member_spec.rb @@ -11,7 +11,7 @@ let(:fork_network) { fork_network_member.fork_network } it 'removes the fork network if it was the last member' do - fork_network.fork_network_members.destroy_all + fork_network.fork_network_members.destroy_all # rubocop: disable DestroyAll expect(ForkNetwork.count).to eq(0) end diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index 01129df11076ad8a682ccaf0e47cb9464d6e2b55..edd1cb455af1aa282bb982866cc2605011e8c218 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -73,7 +73,7 @@ it "project_destroy hook" do project.add_maintainer(user) - project.project_members.destroy_all + project.project_members.destroy_all # rubocop: disable DestroyAll expect(WebMock).to have_requested(:post, system_hook.url).with( body: /user_remove_from_team/, @@ -110,7 +110,7 @@ it 'group member destroy hook' do group.add_maintainer(user) - group.group_members.destroy_all + group.group_members.destroy_all # rubocop: disable DestroyAll expect(WebMock).to have_requested(:post, system_hook.url).with( body: /user_remove_from_group/, diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 2115f3f9349a38696bc0c58c71c5771026237103..50e1ac3c9b957faa6fd85527992199dadce746b3 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -2000,7 +2000,7 @@ def reloaded_merge_request context 'with no discussions' do before do - merge_request.notes.destroy_all + merge_request.notes.destroy_all # rubocop: disable DestroyAll end it 'returns true' do diff --git a/spec/models/project_group_link_spec.rb b/spec/models/project_group_link_spec.rb index 1fccf92627ad3d284eba27d958e8535fc1dee69a..5bea21427d4e6d79714d6d8bb3a386bb8e500e62 100644 --- a/spec/models/project_group_link_spec.rb +++ b/spec/models/project_group_link_spec.rb @@ -41,7 +41,7 @@ project.project_group_links.create(group: group) group_users.each { |user| expect(user.authorized_projects).to include(project) } - project.project_group_links.destroy_all + project.project_group_links.destroy_all # rubocop: disable DestroyAll group_users.each { |user| expect(user.authorized_projects).not_to include(project) } end end diff --git a/spec/policies/group_policy_spec.rb b/spec/policies/group_policy_spec.rb index 8bbf50a66418f54c904d0a3ff95674d8fd113e11..3872c58f80aadc32dfeda04c10cbf1be2cf07acc 100644 --- a/spec/policies/group_policy_spec.rb +++ b/spec/policies/group_policy_spec.rb @@ -206,7 +206,7 @@ def expect_disallowed(*permissions) nested_group.add_guest(developer) nested_group.add_guest(maintainer) - group.owners.destroy_all + group.owners.destroy_all # rubocop: disable DestroyAll group.add_guest(owner) nested_group.add_owner(owner) diff --git a/spec/rubocop/cop/destroy_all_spec.rb b/spec/rubocop/cop/destroy_all_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..b0bc40552b3314911c18f606a2a0ff547fa650ca --- /dev/null +++ b/spec/rubocop/cop/destroy_all_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' +require_relative '../../../rubocop/cop/destroy_all' + +describe RuboCop::Cop::DestroyAll do + include CopHelper + + subject(:cop) { described_class.new } + + it 'flags the use of destroy_all with a send receiver' do + inspect_source('foo.destroy_all # rubocop: disable DestroyAll') + + expect(cop.offenses.size).to eq(1) + end + + it 'flags the use of destroy_all with a constant receiver' do + inspect_source('User.destroy_all # rubocop: disable DestroyAll') + + expect(cop.offenses.size).to eq(1) + end + + it 'flags the use of destroy_all when passing arguments' do + inspect_source('User.destroy_all([])') + + expect(cop.offenses.size).to eq(1) + end + + it 'flags the use of destroy_all with a local variable receiver' do + inspect_source(<<~RUBY) + users = User.all + users.destroy_all # rubocop: disable DestroyAll + RUBY + + expect(cop.offenses.size).to eq(1) + end + + it 'does not flag the use of delete_all' do + inspect_source('foo.delete_all') + + expect(cop.offenses).to be_empty + end +end diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 06fb61baf33f29b862e61dedfe8c7c7060db61fe..74bcc15f9123484cb8a599422f35dfa9f2b85c2a 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -134,9 +134,11 @@ let!(:pipeline_3) { create(:ci_pipeline, project: project, ref: "other_branch", project_id: project.id) } before do + # rubocop: disable DestroyAll project.merge_requests .where(source_branch: opts[:source_branch], target_branch: opts[:target_branch]) .destroy_all + # rubocop: enable DestroyAll end it 'sets head pipeline' do diff --git a/spec/services/merge_requests/delete_non_latest_diffs_service_spec.rb b/spec/services/merge_requests/delete_non_latest_diffs_service_spec.rb index 1c63284794027c8cb828127e7d13ef55e749a3cd..6268c149fc623d443100971e9b4a83e1738776b1 100644 --- a/spec/services/merge_requests/delete_non_latest_diffs_service_spec.rb +++ b/spec/services/merge_requests/delete_non_latest_diffs_service_spec.rb @@ -46,10 +46,12 @@ end it 'schedules no removal if there is no non-latest diffs' do + # rubocop: disable DestroyAll merge_request .merge_request_diffs .where.not(id: merge_request.latest_merge_request_diff_id) .destroy_all + # rubocop: enable DestroyAll expect(DeleteDiffFilesWorker).not_to receive(:bulk_perform_in) diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index 0b8782499c6b35e46cb0b1acf4360e974321f9ee..9d9d19e311e74ff8222603bbab23985ccb0094f4 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -448,7 +448,7 @@ def update_merge_request(opts) update_merge_request(approver_ids: [existing_approver, removed_approver].map(&:id).join(',')) end - Todo.where(action: Todo::APPROVAL_REQUIRED).destroy_all + Todo.where(action: Todo::APPROVAL_REQUIRED).destroy_all # rubocop: disable DestroyAll ActionMailer::Base.deliveries.clear end diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb index e039b325e0a1cdbc99be031de20a63b2954afbf1..bedcc65f1df59c3e017a77a03100be56d96f68cc 100644 --- a/spec/services/todo_service_spec.rb +++ b/spec/services/todo_service_spec.rb @@ -280,7 +280,7 @@ end it 'does not create a todo if unassigned' do - issue.assignees.destroy_all + issue.assignees.destroy_all # rubocop: disable DestroyAll should_not_create_any_todo { service.reassigned_issue(issue, author) } end diff --git a/spec/support/shared_examples/fast_destroy_all.rb b/spec/support/shared_examples/fast_destroy_all.rb index 5448ddcfe335d3d4ac83f16156e9ce3a736ef9a3..a8079b6d86416614021d3c2416acdde1d4f58664 100644 --- a/spec/support/shared_examples/fast_destroy_all.rb +++ b/spec/support/shared_examples/fast_destroy_all.rb @@ -4,8 +4,8 @@ expect(external_data_counter).to be > 0 expect(subjects.count).to be > 0 - expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`') - expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbbiden. Please use `fast_destroy_all`') + expect { subjects.first.destroy }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') + expect { subjects.destroy_all }.to raise_error('`destroy` and `destroy_all` are forbidden. Please use `fast_destroy_all`') # rubocop: disable DestroyAll expect(subjects.count).to be > 0 expect(external_data_counter).to be > 0 diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index 22fc64c15365ebeab174161169f691ca159a8ec2..f11875cffd1264b703f9b454b1b8ed421f827994 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -6,7 +6,7 @@ it 'skips when the project has no push events' do project = create(:project, :repository, :wiki_disabled) - project.events.destroy_all + project.events.destroy_all # rubocop: disable DestroyAll break_project(project) expect(worker).not_to receive(:git_fsck)