Add and apply Rails/WhereEquals rubocop rule

We were already following this style in most places.
This commit is contained in:
Javi Martín
2021-08-09 23:30:36 +02:00
parent 8ae138aa19
commit 884fd2b27b
8 changed files with 12 additions and 11 deletions

View File

@@ -325,6 +325,9 @@ Rails/UnknownEnv:
Rails/Validation: Rails/Validation:
Enabled: true Enabled: true
Rails/WhereEquals:
Enabled: true
Rails/WhereNot: Rails/WhereNot:
Enabled: true Enabled: true

View File

@@ -43,7 +43,7 @@ class DashboardController < Dashboard::BaseController
end end
def set_done_and_pending_actions def set_done_and_pending_actions
@done_actions = proposed_actions.joins(:proposals).where("proposals.id = ?", proposal.id) @done_actions = proposed_actions.joins(:proposals).where(proposals: { id: proposal.id })
@pending_actions = proposed_actions - @done_actions @pending_actions = proposed_actions - @done_actions
end end

View File

@@ -47,7 +47,7 @@ class Officing::BallotSheetsController < Officing::BaseController
joins(:booth_assignment). joins(:booth_assignment).
final. final.
where(id: current_user.poll_officer.officer_assignment_ids). where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id). where(poll_booth_assignments: { poll_id: @poll.id }).
where(date: Date.current) where(date: Date.current)
end end

View File

@@ -99,7 +99,7 @@ class Officing::ResultsController < Officing::BaseController
joins(:booth_assignment). joins(:booth_assignment).
final. final.
where(id: current_user.poll_officer.officer_assignment_ids). where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id). where(poll_booth_assignments: { poll_id: @poll.id }).
where(date: Date.current) where(date: Date.current)
end end

View File

@@ -104,12 +104,12 @@ class Budget
scope :for_render, -> { includes(:heading) } scope :for_render, -> { includes(:heading) }
def self.by_valuator(valuator_id) def self.by_valuator(valuator_id)
where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) where(budget_valuator_assignments: { valuator_id: valuator_id }).joins(:valuator_assignments)
end end
def self.by_valuator_group(valuator_group_id) def self.by_valuator_group(valuator_group_id)
joins(:valuator_group_assignments). joins(:valuator_group_assignments).
where("budget_valuator_group_assignments.valuator_group_id = ?", valuator_group_id) where(budget_valuator_group_assignments: { valuator_group_id: valuator_group_id })
end end
before_validation :set_responsible_name before_validation :set_responsible_name

View File

@@ -32,10 +32,8 @@ class Comment < ApplicationRecord
before_save :calculate_confidence_score before_save :calculate_confidence_score
scope :for_render, -> { with_hidden.includes(user: :organization) } scope :for_render, -> { with_hidden.includes(user: :organization) }
scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } scope :with_visible_author, -> { joins(:user).where(users: { hidden_at: nil }) }
scope :not_as_admin_or_moderator, -> do scope :not_as_admin_or_moderator, -> { where(administrator_id: nil).where(moderator_id: nil) }
where("administrator_id IS NULL").where("moderator_id IS NULL")
end
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :public_for_api, -> do scope :public_for_api, -> do
not_valuations not_valuations

View File

@@ -6,7 +6,7 @@ module Followable
has_many :followers, through: :follows, source: :user has_many :followers, through: :follows, source: :user
scope :followed_by_user, ->(user) { scope :followed_by_user, ->(user) {
joins(:follows).where("follows.user_id = ?", user.id) joins(:follows).where(follows: { user_id: user.id })
} }
end end

View File

@@ -45,7 +45,7 @@ class Poll < ApplicationRecord
scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) } scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) }
scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) } scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) }
scope :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) } scope :recounting, -> { where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) }
scope :published, -> { where("published = ?", true) } scope :published, -> { where(published: true) }
scope :by_geozone_id, ->(geozone_id) { where(geozones: { id: geozone_id }.joins(:geozones)) } scope :by_geozone_id, ->(geozone_id) { where(geozones: { id: geozone_id }.joins(:geozones)) }
scope :public_for_api, -> { all } scope :public_for_api, -> { all }
scope :not_budget, -> { where(budget_id: nil) } scope :not_budget, -> { where(budget_id: nil) }