Apply Style/SymbolProc rubocop rule

This style is much more concise.
This commit is contained in:
Javi Martín
2019-10-26 13:48:32 +02:00
parent 34e66acdda
commit a727dcc031
31 changed files with 46 additions and 57 deletions

View File

@@ -420,3 +420,6 @@ Style/StringLiterals:
Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes
Style/SymbolProc:
Enabled: true

View File

@@ -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

View File

@@ -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"]

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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?

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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" }

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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")