Add and apply Rails/PluckId rubocop rule

This commit is contained in:
Javi Martín
2021-08-09 22:32:00 +02:00
parent 8d47acc12b
commit 69dda19af7
10 changed files with 18 additions and 18 deletions

View File

@@ -270,6 +270,9 @@ Rails/OutputSafety:
Exclude:
- app/helpers/text_with_links_helper.rb
Rails/PluckId:
Enabled: true
Rails/PluralizationGrammar:
Enabled: true

View File

@@ -24,7 +24,7 @@ class Admin::StatsController < Admin::BaseController
.count(:voter_id)
@user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals
budgets_ids = Budget.where.not(phase: "finished").pluck(:id)
budgets_ids = Budget.where.not(phase: "finished").ids
@budgets = budgets_ids.size
@investments = Budget::Investment.where(budget_id: budgets_ids).count
end

View File

@@ -44,7 +44,7 @@ module Budgets
def index
@investments = investments.page(params[:page]).per(PER_PAGE).for_render
@investment_ids = @investments.pluck(:id)
@investment_ids = @investments.ids
@investments_map_coordinates = MapLocation.where(investment: investments).map(&:json_data)
@tag_cloud = tag_cloud

View File

@@ -117,7 +117,7 @@ module ProposalsDashboardHelper
def new_resources_since_last_login?(resources, new_actions_since_last_login)
if resources.present?
resources.pluck(:id).any? { |id| new_actions_since_last_login.include?(id) }
resources.ids.any? { |id| new_actions_since_last_login.include?(id) }
end
end

View File

@@ -164,10 +164,10 @@ class Budget
results = results.winners if params[:advanced_filters].include?("winners")
ids = []
ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?("feasible")
ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?("selected")
ids += results.undecided.pluck(:id) if params[:advanced_filters].include?("undecided")
ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?("unfeasible")
ids += results.valuation_finished_feasible.ids if params[:advanced_filters].include?("feasible")
ids += results.where(selected: true).ids if params[:advanced_filters].include?("selected")
ids += results.undecided.ids if params[:advanced_filters].include?("undecided")
ids += results.unfeasible.ids if params[:advanced_filters].include?("unfeasible")
results = results.where(id: ids) if ids.any?
results
end
@@ -191,8 +191,8 @@ class Budget
return results if max_per_heading <= 0
ids = []
budget.headings.pluck(:id).each do |hid|
ids += Investment.where(heading_id: hid).order(confidence_score: :desc).limit(max_per_heading).pluck(:id)
budget.headings.ids.each do |hid|
ids += Investment.where(heading_id: hid).order(confidence_score: :desc).limit(max_per_heading).ids
end
results.where(id: ids)

View File

@@ -3,7 +3,7 @@ module Randomizable
class_methods do
def sort_by_random(seed = rand(10_000_000))
ids = order(:id).pluck(:id).shuffle(random: Random.new(seed))
ids = order(:id).ids.shuffle(random: Random.new(seed))
return all if ids.empty?

View File

@@ -86,10 +86,7 @@ class Dashboard::Action < ApplicationRecord
actions_for_today = get_actions_for_today(proposal)
actions_for_date = get_actions_for_date(proposal, date)
actions_for_today_ids = actions_for_today.pluck(:id)
actions_for_date_ids = actions_for_date.pluck(:id)
actions_for_today_ids - actions_for_date_ids
actions_for_today.ids - actions_for_date.ids
end
private

View File

@@ -22,11 +22,11 @@ class Legislation::Question < ApplicationRecord
scope :sorted, -> { order("id ASC") }
def next_question_id
@next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first
@next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).ids.first
end
def first_question_id
@first_question_id ||= process.questions.sorted.limit(1).pluck(:id).first
@first_question_id ||= process.questions.sorted.limit(1).ids.first
end
def answer_for_user(user)

View File

@@ -114,7 +114,7 @@ class Proposal < ApplicationRecord
end
def self.not_followed_by_user(user)
where.not(id: followed_by_user(user).pluck(:id))
where.not(id: followed_by_user(user).ids)
end
def to_param

View File

@@ -243,7 +243,7 @@ class User < ApplicationRecord
Comment.hide_all comment_ids
Proposal.hide_all proposal_ids
Budget::Investment.hide_all budget_investment_ids
ProposalNotification.hide_all ProposalNotification.where(author_id: id).pluck(:id)
ProposalNotification.hide_all ProposalNotification.where(author_id: id).ids
end
def full_restore