diff --git a/.rubocop.yml b/.rubocop.yml index 82dd6e4b1..398f75b46 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -420,3 +420,6 @@ Style/StringLiterals: Style/StringLiteralsInInterpolation: EnforcedStyle: double_quotes + +Style/SymbolProc: + Enabled: true diff --git a/app/controllers/admin/poll/shifts_controller.rb b/app/controllers/admin/poll/shifts_controller.rb index c85d9064a..8805f4304 100644 --- a/app/controllers/admin/poll/shifts_controller.rb +++ b/app/controllers/admin/poll/shifts_controller.rb @@ -36,7 +36,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController end def search_officers - @officers = User.search(params[:search]).order(username: :asc).select { |o| o.poll_officer? } + @officers = User.search(params[:search]).order(username: :asc).select(&:poll_officer?) end private diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index e4e475053..d5d8810ce 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -8,7 +8,7 @@ class Admin::SettingsController < Admin::BaseController :poster_feature_short_title_setting, :poster_feature_description_setting def index - all_settings = Setting.all.group_by { |setting| setting.type } + all_settings = Setting.all.group_by(&:type) @configuration_settings = all_settings["configuration"] @feature_settings = all_settings["feature"] @participation_processes_settings = all_settings["process"] diff --git a/app/controllers/admin/site_customization/content_blocks_controller.rb b/app/controllers/admin/site_customization/content_blocks_controller.rb index 54b695342..ed04b85a0 100644 --- a/app/controllers/admin/site_customization/content_blocks_controller.rb +++ b/app/controllers/admin/site_customization/content_blocks_controller.rb @@ -9,7 +9,7 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati def index @content_blocks = SiteCustomization::ContentBlock.order(:name, :locale) @headings_content_blocks = Budget::ContentBlock.all - all_settings = Setting.all.group_by { |setting| setting.type } + all_settings = Setting.all.group_by(&:type) @html_settings = all_settings["html"] end diff --git a/app/controllers/admin/system_emails_controller.rb b/app/controllers/admin/system_emails_controller.rb index 0baf0970a..d3b60c686 100644 --- a/app/controllers/admin/system_emails_controller.rb +++ b/app/controllers/admin/system_emails_controller.rb @@ -91,7 +91,7 @@ class Admin::SystemEmailsController < Admin::BaseController end def load_sample_reply - reply = Comment.select { |comment| comment.reply? }.last + reply = Comment.select(&:reply?).last if reply @email = ReplyEmail.new(reply) else diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 58e9c43f4..124bfba83 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -73,9 +73,7 @@ module Budgets def load_map @investments ||= [] - @investments_map_coordinates = MapLocation.where(investment: @investments).map do |loc| - loc.json_data - end + @investments_map_coordinates = MapLocation.where(investment: @investments).map(&:json_data) @map_location = MapLocation.load_from_heading(@heading) end end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 7510d94bb..f01856408 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -19,7 +19,7 @@ class NotificationsController < ApplicationController end def mark_all_as_read - current_user.notifications.unread.each { |notification| notification.mark_as_read } + current_user.notifications.unread.each(&:mark_as_read) redirect_to notifications_path end diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb index 6cc93a712..b25baae63 100644 --- a/app/controllers/officing/results_controller.rb +++ b/app/controllers/officing/results_controller.rb @@ -13,7 +13,7 @@ class Officing::ResultsController < Officing::BaseController end def create - @results.each { |result| result.save! } + @results.each(&:save!) notice = t("officing.results.flash.create") redirect_to new_officing_poll_result_path(@poll), notice: notice diff --git a/app/controllers/organizations/registrations_controller.rb b/app/controllers/organizations/registrations_controller.rb index 2a770e2da..d4acb3c7b 100644 --- a/app/controllers/organizations/registrations_controller.rb +++ b/app/controllers/organizations/registrations_controller.rb @@ -2,9 +2,7 @@ class Organizations::RegistrationsController < Devise::RegistrationsController invisible_captcha only: [:create], honeypot: :address, scope: :user def new - super do |user| - user.build_organization - end + super(&:build_organization) end def success diff --git a/app/controllers/polls/answers_controller.rb b/app/controllers/polls/answers_controller.rb index eb0702d2b..08fbed082 100644 --- a/app/controllers/polls/answers_controller.rb +++ b/app/controllers/polls/answers_controller.rb @@ -26,9 +26,7 @@ class Polls::AnswersController < ApplicationController def delete @question = Poll::Question.find_by(id: params[:id]) !@question.answers.find_by(author: current_user, answer: params[:answer]).destroy - @question.question_answers.each do |question_answer| - question_answer.set_most_voted - end + @question.question_answers.each(&:set_most_voted) question_answers load_for_answers if @question.enum_type&.include?("answer_couples") diff --git a/app/controllers/polls/questions_controller.rb b/app/controllers/polls/questions_controller.rb index 49299fd7e..bdb791406 100644 --- a/app/controllers/polls/questions_controller.rb +++ b/app/controllers/polls/questions_controller.rb @@ -49,9 +49,7 @@ class Polls::QuestionsController < ApplicationController answer.touch if answer.persisted? answer.save! answer.record_voter_participation(token) - @question.question_answers.visibles.where(question_id: @question).each do |question_answer| - question_answer.set_most_voted - end + @question.question_answers.visibles.where(question_id: @question).each(&:set_most_voted) end def store_answer diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index dd5c9f4a3..7915b10a3 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -82,7 +82,7 @@ module BudgetsHelper investments = current_budget.investments end - MapLocation.where(investment_id: investments).map { |l| l.json_data } + MapLocation.where(investment_id: investments).map(&:json_data) end def display_calculate_winners_button?(budget) diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 21fe5f703..efe0e2b48 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -64,9 +64,7 @@ module TranslatableFormHelper end def new_translation_for(locale) - @object.translations.new(locale: locale).tap do |translation| - translation.mark_for_destruction - end + @object.translations.new(locale: locale).tap(&:mark_for_destruction) end def highlight_translation_html_class diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 9f3d99973..973d0fe23 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -67,7 +67,7 @@ module Abilities can :create, Budget::ValuatorAssignment can [:edit_dossier], Budget::Investment - can(:read_admin_stats, Budget) { |budget| budget.balloting_or_later? } + can :read_admin_stats, Budget, &:balloting_or_later? can [:search, :edit, :update, :create, :index, :destroy], Banner diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 04155f8fc..b514a20eb 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -85,9 +85,7 @@ module Abilities end if user.level_two_or_three_verified? - can :vote, Proposal do |proposal| - proposal.published? - end + can :vote, Proposal, &:published? can :vote_featured, Proposal can :vote, Legislation::Proposal diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 20f53f5f1..506032203 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -25,9 +25,7 @@ module Abilities can :new, DirectMessage can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals, :milestones], Legislation::Process, published: true - can :resume, Legislation::Process do |process| - process.past? - end + can :resume, Legislation::Process, &:past? can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:read, :map, :share], Legislation::Proposal diff --git a/app/models/concerns/relationable.rb b/app/models/concerns/relationable.rb index 538ee8738..86c58b4dd 100644 --- a/app/models/concerns/relationable.rb +++ b/app/models/concerns/relationable.rb @@ -13,6 +13,6 @@ module Relationable end def relationed_contents - related_contents.not_hidden.map { |related_content| related_content.child_relationable } + related_contents.not_hidden.map(&:child_relationable) end end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index c7d927bd8..6563887d9 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -75,7 +75,7 @@ class Poll::Question < ApplicationRecord end def most_voted_answer_id - question_answers.max_by { |answer| answer.total_votes }.id + question_answers.max_by(&:total_votes).id end def answers_with_read_more? diff --git a/lib/manager_authenticator.rb b/lib/manager_authenticator.rb index 9d27fcdb0..5ad17cb07 100644 --- a/lib/manager_authenticator.rb +++ b/lib/manager_authenticator.rb @@ -4,7 +4,7 @@ class ManagerAuthenticator end def auth - return false unless [@manager[:login], @manager[:user_key], @manager[:date]].all? { |manager| manager.present? } + return false unless [@manager[:login], @manager[:user_key], @manager[:date]].all?(&:present?) return @manager if manager_exists? && application_authorized? false diff --git a/lib/remote_census_api.rb b/lib/remote_census_api.rb index 7cda5af29..25f3c083a 100644 --- a/lib/remote_census_api.rb +++ b/lib/remote_census_api.rb @@ -66,7 +66,7 @@ class RemoteCensusApi end def parse_response_path(path_value) - path_value.split(".").map { |section| section.to_sym } if path_value.present? + path_value.split(".").map(&:to_sym) if path_value.present? end end diff --git a/lib/remote_translations/microsoft/available_locales.rb b/lib/remote_translations/microsoft/available_locales.rb index 17077de80..8adee78f7 100644 --- a/lib/remote_translations/microsoft/available_locales.rb +++ b/lib/remote_translations/microsoft/available_locales.rb @@ -6,7 +6,7 @@ require "json" class RemoteTranslations::Microsoft::AvailableLocales def self.available_locales daily_cache("locales") do - remote_available_locales.map { |locale| locale.first } + remote_available_locales.map(&:first) end end diff --git a/spec/factories/administration.rb b/spec/factories/administration.rb index 591453de3..a596d45dd 100644 --- a/spec/factories/administration.rb +++ b/spec/factories/administration.rb @@ -6,8 +6,8 @@ FactoryBot.define do factory :geozone do sequence(:name) { |n| "District #{n}" } - sequence(:external_code) { |n| n.to_s } - sequence(:census_code) { |n| n.to_s } + sequence(:external_code, &:to_s) + sequence(:census_code, &:to_s) trait :in_census do census_code { "01" } diff --git a/spec/factories/analytics.rb b/spec/factories/analytics.rb index c5cbeb11e..17b1db3b4 100644 --- a/spec/factories/analytics.rb +++ b/spec/factories/analytics.rb @@ -12,6 +12,6 @@ FactoryBot.define do factory :campaign do sequence(:name) { |n| "Campaign #{n}" } - sequence(:track_id) { |n| n.to_s } + sequence(:track_id, &:to_s) end end diff --git a/spec/factories/budgets.rb b/spec/factories/budgets.rb index 751bdc4dc..877742f5e 100644 --- a/spec/factories/budgets.rb +++ b/spec/factories/budgets.rb @@ -101,7 +101,7 @@ FactoryBot.define do incompatible { false } trait :with_confidence_score do - before(:save) { |i| i.calculate_confidence_score } + before(:save, &:calculate_confidence_score) end trait :feasible do diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index 1127836d5..3e35e0e2d 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -23,7 +23,7 @@ FactoryBot.define do end trait :with_confidence_score do - before(:save) { |d| d.calculate_confidence_score } + before(:save, &:calculate_confidence_score) end trait :valuation do diff --git a/spec/factories/debates.rb b/spec/factories/debates.rb index 3293df786..972819059 100644 --- a/spec/factories/debates.rb +++ b/spec/factories/debates.rb @@ -24,11 +24,11 @@ FactoryBot.define do end trait :with_hot_score do - before(:save) { |d| d.calculate_hot_score } + before(:save, &:calculate_hot_score) end trait :with_confidence_score do - before(:save) { |d| d.calculate_confidence_score } + before(:save, &:calculate_confidence_score) end trait :conflictive do diff --git a/spec/factories/proposals.rb b/spec/factories/proposals.rb index aed8b8339..ac357aa6f 100644 --- a/spec/factories/proposals.rb +++ b/spec/factories/proposals.rb @@ -38,11 +38,11 @@ FactoryBot.define do end trait :with_hot_score do - before(:save) { |d| d.calculate_hot_score } + before(:save, &:calculate_hot_score) end trait :with_confidence_score do - before(:save) { |d| d.calculate_confidence_score } + before(:save, &:calculate_confidence_score) end trait :conflictive do diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 801d4f76f..3e432ad5d 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -632,11 +632,11 @@ describe "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) within(".submenu .is-active") { expect(page).to have_content "random" } - order = all(".budget-investment h3").map { |i| i.text } + order = all(".budget-investment h3").map(&:text) expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = all(".budget-investment h3").map { |i| i.text } + new_order = all(".budget-investment h3").map(&:text) expect(order).to eq(new_order) end @@ -645,14 +645,14 @@ describe "Budget Investments" do (per_page + 2).times { create(:budget_investment, heading: heading) } visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").map { |i| i.text } + order = all(".budget-investment h3").map(&:text) expect(order).not_to be_empty click_link "highest rated" click_link "random" visit budget_investments_path(budget, heading_id: heading.id) - new_order = all(".budget-investment h3").map { |i| i.text } + new_order = all(".budget-investment h3").map(&:text) expect(order).to eq(new_order) end @@ -662,7 +662,7 @@ describe "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").map { |i| i.text } + order = all(".budget-investment h3").map(&:text) expect(order).not_to be_empty click_link "Next" @@ -671,7 +671,7 @@ describe "Budget Investments" do click_link "Previous" expect(page).to have_content "You're on page 1" - new_order = all(".budget-investment h3").map { |i| i.text } + new_order = all(".budget-investment h3").map(&:text) expect(order).to eq(new_order) end @@ -680,13 +680,13 @@ describe "Budget Investments" do visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").map { |i| i.text } + order = all(".budget-investment h3").map(&:text) expect(order).not_to be_empty click_link Budget::Investment.first.title click_link "Go back" - new_order = all(".budget-investment h3").map { |i| i.text } + new_order = all(".budget-investment h3").map(&:text) expect(order).to eq(new_order) end @@ -812,11 +812,11 @@ describe "Budget Investments" do budget.update!(phase: "finished") visit budget_investments_path(budget, heading_id: heading.id) - order = all(".budget-investment h3").map { |i| i.text } + order = all(".budget-investment h3").map(&:text) expect(order).not_to be_empty visit budget_investments_path(budget, heading_id: heading.id) - new_order = all(".budget-investment h3").map { |i| i.text } + new_order = all(".budget-investment h3").map(&:text) expect(order).to eq(new_order) end @@ -844,7 +844,7 @@ describe "Budget Investments" do end def investments_order - all(".budget-investment h3").map { |i| i.text } + all(".budget-investment h3").map(&:text) end end diff --git a/spec/features/notifications_spec.rb b/spec/features/notifications_spec.rb index 8391ff048..43e5a045c 100644 --- a/spec/features/notifications_spec.rb +++ b/spec/features/notifications_spec.rb @@ -229,7 +229,7 @@ describe "Notifications" do end def remove_users_without_pending_notifications - users_without_notifications.each { |user| user.destroy } + users_without_notifications.each(&:destroy) end def users_without_notifications diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index 2a47e1fe0..778ecdb7b 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -418,7 +418,7 @@ describe "Users" do scenario "Gracefully handle followables that have been hidden" do create(:proposal, followers: [user]) - create(:proposal, followers: [user]) { |proposal| proposal.hide } + create(:proposal, followers: [user], &:hide) visit user_path(user) diff --git a/spec/lib/graphql_spec.rb b/spec/lib/graphql_spec.rb index ba232e74f..1a2efcce8 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -396,7 +396,7 @@ describe "Consul Schema" do describe "Geozones" do it "returns geozones" do - geozone_names = [create(:geozone), create(:geozone)].map { |geozone| geozone.name } + geozone_names = [create(:geozone), create(:geozone)].map(&:name) response = execute("{ geozones { edges { node { name } } } }") received_names = extract_fields(response, "geozones", "name")