Commit d509f0e1 authored by Shubham Kumar's avatar Shubham Kumar Committed by Heinrich Lee Yu

Resolves rubocop offense Rails/WhereEquals

Fixes auto correct rubocop offenses
parent e77edc54
......@@ -626,11 +626,6 @@ Rails/SkipsModelValidations:
Rails/SquishedSQLHeredocs:
Enabled: false
# Offense count: 44
# Cop supports --auto-correct.
Rails/WhereEquals:
Enabled: false
# Offense count: 44
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
......
......@@ -133,7 +133,7 @@ module Ci
when true
items.where.not(yaml_errors: nil)
when false
items.where("yaml_errors IS NULL")
items.where(yaml_errors: nil)
else
items
end
......
......@@ -28,7 +28,7 @@ module Milestoneable
scope :without_release, -> do
joins("LEFT OUTER JOIN milestone_releases ON #{table_name}.milestone_id = milestone_releases.milestone_id")
.where('milestone_releases.release_id IS NULL')
.where(milestone_releases: { release_id: nil })
end
scope :joins_milestone_releases, -> do
......
......@@ -12,7 +12,7 @@ class DeploymentMergeRequest < ApplicationRecord
end
def self.by_deployment_id(id)
where('deployments.id = ?', id)
where(deployments: { id: id })
end
def self.deployed_to(name)
......@@ -20,7 +20,7 @@ class DeploymentMergeRequest < ApplicationRecord
# (project_id, name), instead of using the index on
# (name varchar_pattern_ops). This results in better performance on
# GitLab.com.
where('environments.name = ?', name)
where(environments: { name: name })
.where('environments.project_id = merge_requests.target_project_id')
end
......
......@@ -109,13 +109,13 @@ class Group < Namespace
scope :for_authorized_group_members, -> (user_ids) do
joins(:group_members)
.where("members.user_id IN (?)", user_ids)
.where(members: { user_id: user_ids })
.where("access_level >= ?", Gitlab::Access::GUEST)
end
scope :for_authorized_project_members, -> (user_ids) do
joins(projects: :project_authorizations)
.where("project_authorizations.user_id IN (?)", user_ids)
.where(project_authorizations: { user_id: user_ids })
end
class << self
......@@ -153,7 +153,7 @@ class Group < Namespace
def select_for_project_authorization
if current_scope.joins_values.include?(:shared_projects)
joins('INNER JOIN namespaces project_namespace ON project_namespace.id = projects.namespace_id')
.where('project_namespace.share_with_group_lock = ?', false)
.where(project_namespace: { share_with_group_lock: false })
.select("projects.id AS project_id, LEAST(project_group_links.group_access, members.access_level) AS access_level")
else
super
......
......@@ -8,7 +8,7 @@ class IssueAssignee < ApplicationRecord
validates :assignee, uniqueness: { scope: :issue_id }
scope :in_projects, ->(project_ids) { joins(:issue).where("issues.project_id in (?)", project_ids) }
scope :in_projects, ->(project_ids) { joins(:issue).where(issues: { project_id: project_ids }) }
scope :on_issues, ->(issue_ids) { where(issue_id: issue_ids) }
scope :for_assignee, ->(user) { where(assignee: user) }
end
......
......@@ -16,7 +16,7 @@ class ProjectMember < Member
scope :in_project, ->(project) { where(source_id: project.id) }
scope :in_namespaces, ->(groups) do
joins('INNER JOIN projects ON projects.id = members.source_id')
.where('projects.namespace_id in (?)', groups.select(:id))
.where(projects: { namespace_id: groups.select(:id) })
end
scope :without_project_bots, -> do
......
......@@ -6,5 +6,5 @@ class MergeRequestAssignee < ApplicationRecord
validates :assignee, uniqueness: { scope: :merge_request_id }
scope :in_projects, ->(project_ids) { joins(:merge_request).where("merge_requests.target_project_id in (?)", project_ids) }
scope :in_projects, ->(project_ids) { joins(:merge_request).where(merge_requests: { target_project_id: project_ids }) }
end
......@@ -94,7 +94,7 @@ class Milestone < ApplicationRecord
end
def participants
User.joins(assigned_issues: :milestone).where("milestones.id = ?", id).distinct
User.joins(assigned_issues: :milestone).where(milestones: { id: id }).distinct
end
def self.sort_by_attribute(method)
......
......@@ -89,7 +89,7 @@ class Namespace < ApplicationRecord
before_destroy(prepend: true) { prepare_for_destroy }
after_destroy :rm_dir
scope :for_user, -> { where('type IS NULL') }
scope :for_user, -> { where(type: nil) }
scope :sort_by_type, -> { order(Gitlab::Database.nulls_first_order(:type)) }
scope :include_route, -> { includes(:route) }
scope :by_parent, -> (parent) { where(parent_id: parent) }
......
......@@ -27,7 +27,7 @@ module Network
@project
.notes
.where('noteable_type = ?', 'Commit')
.where(noteable_type: 'Commit')
.group('notes.commit_id')
.select('notes.commit_id, count(notes.id) as note_count')
.each do |item|
......
......@@ -97,7 +97,7 @@ module Operations
issues = ::Issue
.select('issues.*, operations_feature_flags_issues.id AS link_id')
.joins(:feature_flag_issues)
.where('operations_feature_flags_issues.feature_flag_id = ?', id)
.where(operations_feature_flags_issues: { feature_flag_id: id })
.order('operations_feature_flags_issues.id ASC')
.includes(preload)
......
......@@ -118,7 +118,7 @@ class Snippet < ApplicationRecord
def self.only_include_projects_visible_to(current_user = nil)
levels = Gitlab::VisibilityLevel.levels_for_user(current_user)
joins(:project).where('projects.visibility_level IN (?)', levels)
joins(:project).where(projects: { visibility_level: levels })
end
def self.only_include_projects_with_snippets_enabled(include_private: false)
......
......@@ -129,7 +129,7 @@ module Boards
# rubocop: disable CodeReuse/ActiveRecord
def label_links(label_ids)
LabelLink
.where('label_links.target_type = ?', item_model)
.where(label_links: { target_type: item_model })
.where(item_model.arel_table[:id].eq(LabelLink.arel_table[:target_id]).to_sql)
.where(label_id: label_ids)
end
......
......@@ -37,7 +37,7 @@ module Todos
def todos
Todo.joins_issue_and_assignees
.where(target: issues)
.where('issues.confidential = ?', true)
.where(issues: { confidential: true })
.where('todos.user_id != issues.author_id')
.where('todos.user_id != issue_assignees.user_id')
end
......
---
title: Resolves rubocop offenses Rails/WhereEquals
merge_request: 58067
author: Shubham Kumar (@imskr)
type: fixed
......@@ -82,12 +82,12 @@ class CleanupProjectsWithMissingNamespace < ActiveRecord::Migration[6.0]
# There should only be one Group for User Ghost starting with LOST_AND_FOUND_GROUP
Group
.joins('INNER JOIN members ON namespaces.id = members.source_id')
.where('namespaces.type = ?', 'Group')
.where('members.type = ?', 'GroupMember')
.where('members.source_type = ?', 'Namespace')
.where('members.user_id = ?', self.id)
.where('members.requested_at IS NULL')
.where('members.access_level = ?', ACCESS_LEVEL_OWNER)
.where(namespaces: { type: 'Group' })
.where(members: { type: 'GroupMember' })
.where(members: { source_type: 'Namespace' })
.where(members: { user_id: self.id })
.where(members: { requested_at: nil })
.where(members: { access_level: ACCESS_LEVEL_OWNER })
.find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%"))
end
......
......@@ -25,11 +25,11 @@ class UpdateRoutesForLostAndFoundGroupAndOrphanedProjects < ActiveRecord::Migrat
# There should only be one Group owned by the Ghost user starting with 'lost-and-found'
Group
.joins('INNER JOIN members ON namespaces.id = members.source_id')
.where('namespaces.type = ?', 'Group')
.where('members.type = ?', 'GroupMember')
.where('members.source_type = ?', 'Namespace')
.where('members.user_id = ?', self.id)
.where('members.access_level = ?', ACCESS_LEVEL_OWNER)
.where(namespaces: { type: 'Group' })
.where(members: { type: 'GroupMember' })
.where(members: { source_type: 'Namespace' })
.where(members: { user_id: self.id })
.where(members: { access_level: ACCESS_LEVEL_OWNER })
.find_by(Group.arel_table[:name].matches("#{LOST_AND_FOUND_GROUP}%"))
end
......
......@@ -36,7 +36,7 @@ class GenerateMissingRoutesForBots < ActiveRecord::Migration[6.0]
belongs_to :owner, class_name: 'GenerateMissingRoutesForBots::User'
scope :for_user, -> { where('type IS NULL') }
scope :for_user, -> { where(type: nil) }
scope :for_bots, -> { for_user.joins(:owner).merge(GenerateMissingRoutesForBots::User.bots) }
scope :without_routes, -> do
......
......@@ -71,7 +71,7 @@ class CleanupGroupImportStatesWithNullUserId < ActiveRecord::Migration[6.0]
end
end
GroupImportState.where('user_id IS NULL').delete_all
GroupImportState.where(user_id: nil).delete_all
end
def down
......
......@@ -21,7 +21,7 @@ class EnsureU2fRegistrationsMigrated < ActiveRecord::Migration[6.0]
# Do a manual update in case we lost BG jobs. The expected record count should be 0 or very low.
U2fRegistration
.joins("LEFT JOIN webauthn_registrations ON webauthn_registrations.u2f_registration_id = u2f_registrations.id")
.where("webauthn_registrations.u2f_registration_id IS NULL")
.where(webauthn_registrations: { u2f_registration_id: nil })
.each_batch(of: BATCH_SIZE) do |batch, index|
batch.each do |record|
Gitlab::BackgroundMigration::MigrateU2fWebauthn.new.perform(record.id, record.id)
......
......@@ -15,7 +15,7 @@ class CleanupGitlabSubscriptionsWithNullNamespaceId < ActiveRecord::Migration[6.
# This will be fast on GitLab.com, because:
# - gitlab_subscriptions.count=5021850
# - namespace_id is indexed, so the query is pretty fast. Try on database-lab, this uses 5.931 ms
GitlabSubscription.where('namespace_id IS NULL').delete_all
GitlabSubscription.where(namespace_id: nil).delete_all
end
def down
......
......@@ -15,7 +15,7 @@ class CleanupClusterTokensWithNullName < ActiveRecord::Migration[6.0]
def up
AgentToken.each_batch(of: BATCH_SIZE) do |relation|
relation.where('name IS NULL').update_all("name = 'agent-token-' || id")
relation.where(name: nil).update_all("name = 'agent-token-' || id")
end
end
......
......@@ -17,7 +17,7 @@ class BackfillEventsIdForBigintConversion < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'events', column_name: 'id')
.where('job_arguments = ?', %w[id id_convert_to_bigint].to_json)
.where(job_arguments: %w[id id_convert_to_bigint].to_json)
.delete_all
end
......
......@@ -18,7 +18,7 @@ class BackfillPushEventPayloadEventIdForBigintConversion < ActiveRecord::Migrati
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'push_event_payloads', column_name: 'event_id')
.where('job_arguments = ?', %w[event_id event_id_convert_to_bigint].to_json)
.where(job_arguments: %w[event_id event_id_convert_to_bigint].to_json)
.delete_all
end
......
......@@ -18,7 +18,7 @@ class BackfillCiBuildNeedsForBigintConversion < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_build_needs', column_name: 'build_id')
.where('job_arguments = ?', %w[build_id build_id_convert_to_bigint].to_json)
.where(job_arguments: %w[build_id build_id_convert_to_bigint].to_json)
.delete_all
end
......
......@@ -17,7 +17,7 @@ class BackfillConversionOfCiJobArtifacts < ActiveRecord::Migration[6.0]
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_job_artifacts', column_name: 'id')
.where('job_arguments = ?', [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]].to_json)
.where(job_arguments: [%w[id job_id], %w[id_convert_to_bigint job_id_convert_to_bigint]].to_json)
.delete_all
end
......
......@@ -16,7 +16,7 @@ class BackfillCiSourcesPipelinesSourceJobIdForBigintConversion < ActiveRecord::M
Gitlab::Database::BackgroundMigration::BatchedMigration
.where(job_class_name: 'CopyColumnUsingBackgroundMigrationJob')
.where(table_name: 'ci_sources_pipelines', column_name: 'id')
.where('job_arguments = ?', [%w[source_job_id], %w[source_job_id_convert_to_bigint]].to_json)
.where(job_arguments: [%w[source_job_id], %w[source_job_id_convert_to_bigint]].to_json)
.delete_all
end
......
......@@ -35,7 +35,7 @@ module EE
return self.all unless ::Gitlab::Geo.current_node.selective_sync?
self.joins(:package)
.where('packages_packages.project_id IN (?)', ::Gitlab::Geo.current_node.projects.select(:id))
.where(packages_packages: { project_id: ::Gitlab::Geo.current_node.projects.select(:id) })
end
end
......
......@@ -286,7 +286,7 @@ module EE
def with_slack_application_disabled
joins('LEFT JOIN services ON services.project_id = projects.id AND services.type = \'GitlabSlackApplicationService\' AND services.active IS true')
.where('services.id IS NULL')
.where(services: { id: nil })
end
override :with_web_entity_associations
......
......@@ -32,7 +32,7 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
def label_links(label_ids)
if has_valid_milestone?
super.where("issues.milestone_id = ?", board.milestone_id)
super.where(issues: { milestone_id: board.milestone_id })
else
super
end
......
......@@ -479,7 +479,7 @@ module EE
::Security::Scan.scan_types.each do |name, scan_type|
relation = ::Ci::Build.joins(:security_scans)
.where(status: 'success', retried: [nil, false])
.where('security_scans.scan_type = ?', scan_type)
.where(security_scans: { scan_type: scan_type })
.where(time_period)
pipelines_with_secure_jobs["#{name}_pipeline".to_sym] = distinct_count(relation, :commit_id, start: start, finish: finish, batch: false)
end
......
......@@ -182,7 +182,7 @@ namespace :gitlab do
relation = Project.all
unless ENV['UPDATE_INDEX']
relation = relation.includes(:index_status).where('index_statuses.id IS NULL').references(:index_statuses)
relation = relation.includes(:index_status).where(index_statuses: { id: nil }).references(:index_statuses)
end
if ::Gitlab::CurrentSettings.elasticsearch_limit_indexing?
......
......@@ -19,7 +19,7 @@ module Banzai
def readable_project_ids_for(user)
@project_ids_by_user ||= {}
@project_ids_by_user[user] ||=
Project.public_or_visible_to_user(user).where("projects.id IN (?)", @projects_for_nodes.values.map(&:id)).pluck(:id)
Project.public_or_visible_to_user(user).where(projects: { id: @projects_for_nodes.values.map(&:id) }).pluck(:id)
end
def can_read_reference?(user, ref_project, node)
......
......@@ -9,7 +9,7 @@ module Gitlab
scope :for_migration_class, -> (class_name) { where(class_name: normalize_class_name(class_name)) }
scope :for_migration_execution, -> (class_name, arguments) do
for_migration_class(class_name).where('arguments = ?', arguments.to_json)
for_migration_class(class_name).where('arguments = ?', arguments.to_json) # rubocop:disable Rails/WhereEquals
end
scope :for_partitioning_migration, -> (class_name, table_name) do
......
......@@ -95,12 +95,12 @@ RSpec.describe CleanupProjectsWithMissingNamespace, :migration, schema: SchemaVe
expect(
described_class::Group
.joins('INNER JOIN members ON namespaces.id = members.source_id')
.where('namespaces.type = ?', 'Group')
.where('members.type = ?', 'GroupMember')
.where('members.source_type = ?', 'Namespace')
.where('members.user_id = ?', ghost_user.id)
.where('members.requested_at IS NULL')
.where('members.access_level = ?', described_class::ACCESS_LEVEL_OWNER)
.where(namespaces: { type: 'Group' })
.where(members: { type: 'GroupMember' })
.where(members: { source_type: 'Namespace' })
.where(members: { user_id: ghost_user.id })
.where(members: { requested_at: nil })
.where(members: { access_level: described_class::ACCESS_LEVEL_OWNER })
.where(
described_class::Group
.arel_table[:name]
......
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