Commit e4821b05 authored by Shubham Kumar's avatar Shubham Kumar Committed by Mayra Cabrera

Resolves rubocop offense Rails/WhereNot

Fixes auto correct rubocop offenses
parent 8d8fc7dd
...@@ -640,11 +640,6 @@ Rails/WhereEquals: ...@@ -640,11 +640,6 @@ Rails/WhereEquals:
Rails/WhereExists: Rails/WhereExists:
Enabled: false Enabled: false
# Offense count: 21
# Cop supports --auto-correct.
Rails/WhereNot:
Enabled: false
# Offense count: 8 # Offense count: 8
# Cop supports --auto-correct. # Cop supports --auto-correct.
Security/YAMLLoad: Security/YAMLLoad:
......
...@@ -131,7 +131,7 @@ module Ci ...@@ -131,7 +131,7 @@ module Ci
def by_yaml_errors(items) def by_yaml_errors(items)
case Gitlab::Utils.to_boolean(params[:yaml_errors]) case Gitlab::Utils.to_boolean(params[:yaml_errors])
when true when true
items.where("yaml_errors IS NOT NULL") items.where.not(yaml_errors: nil)
when false when false
items.where("yaml_errors IS NULL") items.where("yaml_errors IS NULL")
else else
......
...@@ -93,8 +93,7 @@ module Ci ...@@ -93,8 +93,7 @@ module Ci
validates :ref, presence: true validates :ref, presence: true
scope :not_interruptible, -> do scope :not_interruptible, -> do
joins(:metadata).where('ci_builds_metadata.id NOT IN (?)', joins(:metadata).where.not('ci_builds_metadata.id' => Ci::BuildMetadata.scoped_build.with_interruptible.select(:id))
Ci::BuildMetadata.scoped_build.with_interruptible.select(:id))
end end
scope :unstarted, -> { where(runner_id: nil) } scope :unstarted, -> { where(runner_id: nil) }
......
...@@ -44,7 +44,7 @@ module Ci ...@@ -44,7 +44,7 @@ module Ci
next if position.present? next if position.present?
self.position = statuses.select(:stage_idx) self.position = statuses.select(:stage_idx)
.where('stage_idx IS NOT NULL') .where.not(stage_idx: nil)
.group(:stage_idx) .group(:stage_idx)
.order('COUNT(*) DESC') .order('COUNT(*) DESC')
.first&.stage_idx.to_i .first&.stage_idx.to_i
......
...@@ -16,7 +16,7 @@ module Clusters ...@@ -16,7 +16,7 @@ module Clusters
model model
.unscoped .unscoped
.where('clusters.id IS NOT NULL') .where.not('clusters.id' => nil)
.with .with
.recursive(cte.to_arel) .recursive(cte.to_arel)
.from(cte_alias) .from(cte_alias)
......
...@@ -86,7 +86,7 @@ class Environment < ApplicationRecord ...@@ -86,7 +86,7 @@ class Environment < ApplicationRecord
end end
scope :for_project, -> (project) { where(project_id: project) } scope :for_project, -> (project) { where(project_id: project) }
scope :for_tier, -> (tier) { where(tier: tier).where('tier IS NOT NULL') } scope :for_tier, -> (tier) { where(tier: tier).where.not(tier: nil) }
scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) } scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
scope :unfoldered, -> { where(environment_type: nil) } scope :unfoldered, -> { where(environment_type: nil) }
scope :with_rank, -> do scope :with_rank, -> do
......
...@@ -519,7 +519,7 @@ class Project < ApplicationRecord ...@@ -519,7 +519,7 @@ class Project < ApplicationRecord
scope :with_packages, -> { joins(:packages) } scope :with_packages, -> { joins(:packages) }
scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) } scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) }
scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :personal, ->(user) { where(namespace_id: user.namespace_id) }
scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) } scope :joined, ->(user) { where.not(namespace_id: user.namespace_id) }
scope :starred_by, ->(user) { joins(:users_star_projects).where('users_star_projects.user_id': user.id) } scope :starred_by, ->(user) { joins(:users_star_projects).where('users_star_projects.user_id': user.id) }
scope :visible_to_user, ->(user) { where(id: user.authorized_projects.select(:id).reorder(nil)) } scope :visible_to_user, ->(user) { where(id: user.authorized_projects.select(:id).reorder(nil)) }
scope :visible_to_user_and_access_level, ->(user, access_level) { where(id: user.authorized_projects.where('project_authorizations.access_level >= ?', access_level).select(:id).reorder(nil)) } scope :visible_to_user_and_access_level, ->(user, access_level) { where(id: user.authorized_projects.where('project_authorizations.access_level >= ?', access_level).select(:id).reorder(nil)) }
......
...@@ -1041,7 +1041,7 @@ class User < ApplicationRecord ...@@ -1041,7 +1041,7 @@ class User < ApplicationRecord
[ [
Project.where(namespace: namespace), Project.where(namespace: namespace),
Project.joins(:project_authorizations) Project.joins(:project_authorizations)
.where("projects.namespace_id <> ?", namespace.id) .where.not('projects.namespace_id' => namespace.id)
.where(project_authorizations: { user_id: id, access_level: Gitlab::Access::OWNER }) .where(project_authorizations: { user_id: id, access_level: Gitlab::Access::OWNER })
], ],
remove_duplicates: false remove_duplicates: false
......
...@@ -13,7 +13,7 @@ module Todos ...@@ -13,7 +13,7 @@ module Todos
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def without_authorized(items) def without_authorized(items)
items.where('todos.user_id NOT IN (?)', authorized_users) items.where.not('todos.user_id' => authorized_users)
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -36,7 +36,7 @@ module Todos ...@@ -36,7 +36,7 @@ module Todos
items = Todo.where(project_id: project_id) items = Todo.where(project_id: project_id)
items = items.where(user_id: user_id) if user_id items = items.where(user_id: user_id) if user_id
items.where('user_id NOT IN (?)', authorized_users) items.where.not(user_id: authorized_users)
.where(target_type: target_types) .where(target_type: target_types)
.delete_all .delete_all
end end
......
---
title: Resolves rubocop offenses Rails/WhereNot
merge_request: 58062
author: Shubham Kumar (@imskr)
type: fixed
...@@ -17,7 +17,7 @@ class BackfillDeploymentClustersFromDeployments < ActiveRecord::Migration[6.0] ...@@ -17,7 +17,7 @@ class BackfillDeploymentClustersFromDeployments < ActiveRecord::Migration[6.0]
class Deployment < ActiveRecord::Base class Deployment < ActiveRecord::Base
include EachBatch include EachBatch
default_scope { where('cluster_id IS NOT NULL') } # rubocop:disable Cop/DefaultScope default_scope { where.not(cluster_id: nil) } # rubocop:disable Cop/DefaultScope
self.table_name = 'deployments' self.table_name = 'deployments'
end end
......
...@@ -18,11 +18,11 @@ class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0] ...@@ -18,11 +18,11 @@ class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
VulnerabilitiesFeedback.where('issue_id IS NOT NULL').each_batch do |relation| VulnerabilitiesFeedback.where.not(issue_id: nil).each_batch do |relation|
timestamp = Time.now timestamp = Time.now
issue_links = relation issue_links = relation
.joins("JOIN vulnerability_occurrences vo ON vo.project_id = vulnerability_feedback.project_id AND vo.report_type = vulnerability_feedback.category AND encode(vo.project_fingerprint, 'hex') = vulnerability_feedback.project_fingerprint") .joins("JOIN vulnerability_occurrences vo ON vo.project_id = vulnerability_feedback.project_id AND vo.report_type = vulnerability_feedback.category AND encode(vo.project_fingerprint, 'hex') = vulnerability_feedback.project_fingerprint")
.where('vo.vulnerability_id IS NOT NULL') .where.not('vo.vulnerability_id' => nil)
.pluck(:vulnerability_id, :issue_id) .pluck(:vulnerability_id, :issue_id)
.map do |v_id, i_id| .map do |v_id, i_id|
{ {
......
...@@ -18,7 +18,7 @@ class Elastic::ReindexingTask < ApplicationRecord ...@@ -18,7 +18,7 @@ class Elastic::ReindexingTask < ApplicationRecord
original_index_deleted: 12 original_index_deleted: 12
} }
scope :old_indices_scheduled_for_deletion, -> { where(state: :success).where('delete_original_index_at IS NOT NULL') } scope :old_indices_scheduled_for_deletion, -> { where(state: :success).where.not(delete_original_index_at: nil) }
scope :old_indices_to_be_deleted, -> { old_indices_scheduled_for_deletion.where('delete_original_index_at < NOW()') } scope :old_indices_to_be_deleted, -> { old_indices_scheduled_for_deletion.where('delete_original_index_at < NOW()') }
before_save :set_in_progress_flag before_save :set_in_progress_flag
......
...@@ -610,7 +610,7 @@ module EE ...@@ -610,7 +610,7 @@ module EE
::ApprovalMergeRequestRule ::ApprovalMergeRequestRule
.code_owner .code_owner
.joins(:merge_request) .joins(:merge_request)
.where("section != ?", ::Gitlab::CodeOwners::Entry::DEFAULT_SECTION) .where.not(section: ::Gitlab::CodeOwners::Entry::DEFAULT_SECTION)
.where(time_period), .where(time_period),
'merge_requests.target_project_id', 'merge_requests.target_project_id',
start: project_minimum_id, start: project_minimum_id,
......
...@@ -35,7 +35,7 @@ RSpec.describe NullifyFeatureFlagPlaintextTokens do ...@@ -35,7 +35,7 @@ RSpec.describe NullifyFeatureFlagPlaintextTokens do
} }
migration.after -> { migration.after -> {
expect(feature_flags_clients.where('token IS NOT NULL').count).to eq(0) expect(feature_flags_clients.where.not(token: nil).count).to eq(0)
feature_flag1.reload feature_flag1.reload
expect(feature_flag1.token).to be_nil expect(feature_flag1.token).to be_nil
......
...@@ -49,7 +49,7 @@ RSpec.describe DescriptionVersion do ...@@ -49,7 +49,7 @@ RSpec.describe DescriptionVersion do
def deleted_count def deleted_count
DescriptionVersion DescriptionVersion
.where('issue_id = ? or epic_id = ? or merge_request_id = ?', issue.id, epic.id, merge_request.id) .where('issue_id = ? or epic_id = ? or merge_request_id = ?', issue.id, epic.id, merge_request.id)
.where('deleted_at IS NOT NULL') .where.not(deleted_at: nil)
.count .count
end end
......
...@@ -11,7 +11,7 @@ module Gitlab ...@@ -11,7 +11,7 @@ module Gitlab
MergeRequest MergeRequest
.where(merge_request_assignees_not_exists_clause) .where(merge_request_assignees_not_exists_clause)
.where(id: from_id..to_id) .where(id: from_id..to_id)
.where('assignee_id IS NOT NULL') .where.not(assignee_id: nil)
.select(:id, :assignee_id) .select(:id, :assignee_id)
.to_sql .to_sql
......
...@@ -27,7 +27,7 @@ module Gitlab ...@@ -27,7 +27,7 @@ module Gitlab
joins(:user) joins(:user)
.merge(UserModel.active) .merge(UserModel.active)
.where(id: (start_id..stop_id)) .where(id: (start_id..stop_id))
.where('emails.confirmed_at IS NOT NULL') .where.not('emails.confirmed_at' => nil)
.where('emails.confirmed_at = users.confirmed_at') .where('emails.confirmed_at = users.confirmed_at')
.where('emails.email <> users.email') .where('emails.email <> users.email')
.where('NOT EXISTS (SELECT 1 FROM user_synced_attributes_metadata WHERE user_id=users.id AND email_synced IS true)') .where('NOT EXISTS (SELECT 1 FROM user_synced_attributes_metadata WHERE user_id=users.id AND email_synced IS true)')
......
...@@ -76,7 +76,7 @@ module Gitlab ...@@ -76,7 +76,7 @@ module Gitlab
def project_uploads_except_avatar(avatar_path) def project_uploads_except_avatar(avatar_path)
return @project.uploads unless avatar_path return @project.uploads unless avatar_path
@project.uploads.where("path != ?", avatar_path) @project.uploads.where.not(path: avatar_path)
end end
def download_and_copy(upload) def download_and_copy(upload)
......
...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::CodeStageStart do ...@@ -15,7 +15,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::StageEvents::CodeStageStart do
other_merge_request = create(:merge_request, source_project: project, source_branch: 'a', target_branch: 'master') other_merge_request = create(:merge_request, source_project: project, source_branch: 'a', target_branch: 'master')
records = subject.apply_query_customization(MergeRequest.all).where('merge_requests_closing_issues.issue_id IS NOT NULL') records = subject.apply_query_customization(MergeRequest.all).where.not('merge_requests_closing_issues.issue_id' => nil)
expect(records).to eq([merge_request]) expect(records).to eq([merge_request])
expect(records).not_to include(other_merge_request) expect(records).not_to include(other_merge_request)
end end
......
...@@ -25,7 +25,7 @@ RSpec.describe CleanUpNoteableIdForNotesOnCommits do ...@@ -25,7 +25,7 @@ RSpec.describe CleanUpNoteableIdForNotesOnCommits do
end end
def dirty_notes_on_commits def dirty_notes_on_commits
notes.where(noteable_type: 'Commit').where('noteable_id IS NOT NULL') notes.where(noteable_type: 'Commit').where.not(noteable_id: nil)
end end
def other_notes def other_notes
......
...@@ -15,6 +15,6 @@ RSpec.describe MigrateBotTypeToUserType, :migration do ...@@ -15,6 +15,6 @@ RSpec.describe MigrateBotTypeToUserType, :migration do
migrate! migrate!
expect(users.where('user_type IS NOT NULL').map(&:user_type)).to match_array([1, 2, 3]) expect(users.where.not(user_type: nil).map(&:user_type)).to match_array([1, 2, 3])
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment