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:
Rails/WhereExists:
Enabled: false
# Offense count: 21
# Cop supports --auto-correct.
Rails/WhereNot:
Enabled: false
# Offense count: 8
# Cop supports --auto-correct.
Security/YAMLLoad:
......
......@@ -131,7 +131,7 @@ module Ci
def by_yaml_errors(items)
case Gitlab::Utils.to_boolean(params[:yaml_errors])
when true
items.where("yaml_errors IS NOT NULL")
items.where.not(yaml_errors: nil)
when false
items.where("yaml_errors IS NULL")
else
......
......@@ -93,8 +93,7 @@ module Ci
validates :ref, presence: true
scope :not_interruptible, -> do
joins(:metadata).where('ci_builds_metadata.id NOT IN (?)',
Ci::BuildMetadata.scoped_build.with_interruptible.select(:id))
joins(:metadata).where.not('ci_builds_metadata.id' => Ci::BuildMetadata.scoped_build.with_interruptible.select(:id))
end
scope :unstarted, -> { where(runner_id: nil) }
......
......@@ -44,7 +44,7 @@ module Ci
next if position.present?
self.position = statuses.select(:stage_idx)
.where('stage_idx IS NOT NULL')
.where.not(stage_idx: nil)
.group(:stage_idx)
.order('COUNT(*) DESC')
.first&.stage_idx.to_i
......
......@@ -16,7 +16,7 @@ module Clusters
model
.unscoped
.where('clusters.id IS NOT NULL')
.where.not('clusters.id' => nil)
.with
.recursive(cte.to_arel)
.from(cte_alias)
......
......@@ -86,7 +86,7 @@ class Environment < ApplicationRecord
end
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 :unfoldered, -> { where(environment_type: nil) }
scope :with_rank, -> do
......
......@@ -519,7 +519,7 @@ class Project < ApplicationRecord
scope :with_packages, -> { joins(:packages) }
scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) }
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 :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)) }
......
......@@ -1041,7 +1041,7 @@ class User < ApplicationRecord
[
Project.where(namespace: namespace),
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 })
],
remove_duplicates: false
......
......@@ -13,7 +13,7 @@ module Todos
# rubocop: disable CodeReuse/ActiveRecord
def without_authorized(items)
items.where('todos.user_id NOT IN (?)', authorized_users)
items.where.not('todos.user_id' => authorized_users)
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -36,7 +36,7 @@ module Todos
items = Todo.where(project_id: project_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)
.delete_all
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]
class Deployment < ActiveRecord::Base
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'
end
......
......@@ -18,11 +18,11 @@ class CreateMissingVulnerabilitiesIssueLinks < ActiveRecord::Migration[6.0]
disable_ddl_transaction!
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
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")
.where('vo.vulnerability_id IS NOT NULL')
.where.not('vo.vulnerability_id' => nil)
.pluck(:vulnerability_id, :issue_id)
.map do |v_id, i_id|
{
......
......@@ -18,7 +18,7 @@ class Elastic::ReindexingTask < ApplicationRecord
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()') }
before_save :set_in_progress_flag
......
......@@ -610,7 +610,7 @@ module EE
::ApprovalMergeRequestRule
.code_owner
.joins(:merge_request)
.where("section != ?", ::Gitlab::CodeOwners::Entry::DEFAULT_SECTION)
.where.not(section: ::Gitlab::CodeOwners::Entry::DEFAULT_SECTION)
.where(time_period),
'merge_requests.target_project_id',
start: project_minimum_id,
......
......@@ -35,7 +35,7 @@ RSpec.describe NullifyFeatureFlagPlaintextTokens do
}
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
expect(feature_flag1.token).to be_nil
......
......@@ -49,7 +49,7 @@ RSpec.describe DescriptionVersion do
def deleted_count
DescriptionVersion
.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
end
......
......@@ -11,7 +11,7 @@ module Gitlab
MergeRequest
.where(merge_request_assignees_not_exists_clause)
.where(id: from_id..to_id)
.where('assignee_id IS NOT NULL')
.where.not(assignee_id: nil)
.select(:id, :assignee_id)
.to_sql
......
......@@ -27,7 +27,7 @@ module Gitlab
joins(:user)
.merge(UserModel.active)
.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.email <> users.email')
.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
def project_uploads_except_avatar(avatar_path)
return @project.uploads unless avatar_path
@project.uploads.where("path != ?", avatar_path)
@project.uploads.where.not(path: avatar_path)
end
def download_and_copy(upload)
......
......@@ -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')
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).not_to include(other_merge_request)
end
......
......@@ -25,7 +25,7 @@ RSpec.describe CleanUpNoteableIdForNotesOnCommits do
end
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
def other_notes
......
......@@ -15,6 +15,6 @@ RSpec.describe MigrateBotTypeToUserType, :migration do
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
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