diff --git a/.rubocop.yml b/.rubocop.yml index eef2a9d38..dbd429996 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -325,6 +325,9 @@ Rails/UnknownEnv: Rails/Validation: Enabled: true +Rails/WhereEquals: + Enabled: true + Rails/WhereNot: Enabled: true diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 4ed198efa..85e4359ff 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -43,7 +43,7 @@ class DashboardController < Dashboard::BaseController end 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 end diff --git a/app/controllers/officing/ballot_sheets_controller.rb b/app/controllers/officing/ballot_sheets_controller.rb index afc885f61..55b6fcc77 100644 --- a/app/controllers/officing/ballot_sheets_controller.rb +++ b/app/controllers/officing/ballot_sheets_controller.rb @@ -47,7 +47,7 @@ class Officing::BallotSheetsController < Officing::BaseController joins(:booth_assignment). final. 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) end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index b0baf6b7d..6dbfe96ab 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -99,7 +99,7 @@ class Officing::ResultsController < Officing::BaseController joins(:booth_assignment). final. 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) end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 06d10b5a7..d490a3bf1 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -104,12 +104,12 @@ class Budget scope :for_render, -> { includes(:heading) } 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 def self.by_valuator_group(valuator_group_id) 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 before_validation :set_responsible_name diff --git a/app/models/comment.rb b/app/models/comment.rb index f6607a849..89e6c88f1 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -32,10 +32,8 @@ class Comment < ApplicationRecord before_save :calculate_confidence_score scope :for_render, -> { with_hidden.includes(user: :organization) } - scope :with_visible_author, -> { joins(:user).where("users.hidden_at IS NULL") } - scope :not_as_admin_or_moderator, -> do - where("administrator_id IS NULL").where("moderator_id IS NULL") - end + scope :with_visible_author, -> { joins(:user).where(users: { hidden_at: nil }) } + scope :not_as_admin_or_moderator, -> { where(administrator_id: nil).where(moderator_id: nil) } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :public_for_api, -> do not_valuations diff --git a/app/models/concerns/followable.rb b/app/models/concerns/followable.rb index 8a08d6809..7d6210369 100644 --- a/app/models/concerns/followable.rb +++ b/app/models/concerns/followable.rb @@ -6,7 +6,7 @@ module Followable has_many :followers, through: :follows, source: :user scope :followed_by_user, ->(user) { - joins(:follows).where("follows.user_id = ?", user.id) + joins(:follows).where(follows: { user_id: user.id }) } end diff --git a/app/models/poll.rb b/app/models/poll.rb index de8b56187..ac9fd07fc 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -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 :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 :published, -> { where("published = ?", true) } + scope :published, -> { where(published: true) } scope :by_geozone_id, ->(geozone_id) { where(geozones: { id: geozone_id }.joins(:geozones)) } scope :public_for_api, -> { all } scope :not_budget, -> { where(budget_id: nil) }