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: Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes EnforcedStyle: double_quotes
Style/SymbolProc:
Enabled: true

View File

@@ -36,7 +36,7 @@ class Admin::Poll::ShiftsController < Admin::Poll::BaseController
end end
def search_officers 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 end
private private

View File

@@ -8,7 +8,7 @@ class Admin::SettingsController < Admin::BaseController
:poster_feature_short_title_setting, :poster_feature_description_setting :poster_feature_short_title_setting, :poster_feature_description_setting
def index def index
all_settings = Setting.all.group_by { |setting| setting.type } all_settings = Setting.all.group_by(&:type)
@configuration_settings = all_settings["configuration"] @configuration_settings = all_settings["configuration"]
@feature_settings = all_settings["feature"] @feature_settings = all_settings["feature"]
@participation_processes_settings = all_settings["process"] @participation_processes_settings = all_settings["process"]

View File

@@ -9,7 +9,7 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
def index def index
@content_blocks = SiteCustomization::ContentBlock.order(:name, :locale) @content_blocks = SiteCustomization::ContentBlock.order(:name, :locale)
@headings_content_blocks = Budget::ContentBlock.all @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"] @html_settings = all_settings["html"]
end end

View File

@@ -91,7 +91,7 @@ class Admin::SystemEmailsController < Admin::BaseController
end end
def load_sample_reply def load_sample_reply
reply = Comment.select { |comment| comment.reply? }.last reply = Comment.select(&:reply?).last
if reply if reply
@email = ReplyEmail.new(reply) @email = ReplyEmail.new(reply)
else else

View File

@@ -73,9 +73,7 @@ module Budgets
def load_map def load_map
@investments ||= [] @investments ||= []
@investments_map_coordinates = MapLocation.where(investment: @investments).map do |loc| @investments_map_coordinates = MapLocation.where(investment: @investments).map(&:json_data)
loc.json_data
end
@map_location = MapLocation.load_from_heading(@heading) @map_location = MapLocation.load_from_heading(@heading)
end end
end end

View File

@@ -19,7 +19,7 @@ class NotificationsController < ApplicationController
end end
def mark_all_as_read 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 redirect_to notifications_path
end end

View File

@@ -13,7 +13,7 @@ class Officing::ResultsController < Officing::BaseController
end end
def create def create
@results.each { |result| result.save! } @results.each(&:save!)
notice = t("officing.results.flash.create") notice = t("officing.results.flash.create")
redirect_to new_officing_poll_result_path(@poll), notice: notice 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 invisible_captcha only: [:create], honeypot: :address, scope: :user
def new def new
super do |user| super(&:build_organization)
user.build_organization
end
end end
def success def success

View File

@@ -26,9 +26,7 @@ class Polls::AnswersController < ApplicationController
def delete def delete
@question = Poll::Question.find_by(id: params[:id]) @question = Poll::Question.find_by(id: params[:id])
!@question.answers.find_by(author: current_user, answer: params[:answer]).destroy !@question.answers.find_by(author: current_user, answer: params[:answer]).destroy
@question.question_answers.each do |question_answer| @question.question_answers.each(&:set_most_voted)
question_answer.set_most_voted
end
question_answers question_answers
load_for_answers load_for_answers
if @question.enum_type&.include?("answer_couples") if @question.enum_type&.include?("answer_couples")

View File

@@ -49,9 +49,7 @@ class Polls::QuestionsController < ApplicationController
answer.touch if answer.persisted? answer.touch if answer.persisted?
answer.save! answer.save!
answer.record_voter_participation(token) answer.record_voter_participation(token)
@question.question_answers.visibles.where(question_id: @question).each do |question_answer| @question.question_answers.visibles.where(question_id: @question).each(&:set_most_voted)
question_answer.set_most_voted
end
end end
def store_answer def store_answer

View File

@@ -82,7 +82,7 @@ module BudgetsHelper
investments = current_budget.investments investments = current_budget.investments
end end
MapLocation.where(investment_id: investments).map { |l| l.json_data } MapLocation.where(investment_id: investments).map(&:json_data)
end end
def display_calculate_winners_button?(budget) def display_calculate_winners_button?(budget)

View File

@@ -64,9 +64,7 @@ module TranslatableFormHelper
end end
def new_translation_for(locale) def new_translation_for(locale)
@object.translations.new(locale: locale).tap do |translation| @object.translations.new(locale: locale).tap(&:mark_for_destruction)
translation.mark_for_destruction
end
end end
def highlight_translation_html_class def highlight_translation_html_class

View File

@@ -67,7 +67,7 @@ module Abilities
can :create, Budget::ValuatorAssignment can :create, Budget::ValuatorAssignment
can [:edit_dossier], Budget::Investment 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 can [:search, :edit, :update, :create, :index, :destroy], Banner

View File

@@ -85,9 +85,7 @@ module Abilities
end end
if user.level_two_or_three_verified? if user.level_two_or_three_verified?
can :vote, Proposal do |proposal| can :vote, Proposal, &:published?
proposal.published?
end
can :vote_featured, Proposal can :vote_featured, Proposal
can :vote, Legislation::Proposal can :vote, Legislation::Proposal

View File

@@ -25,9 +25,7 @@ module Abilities
can :new, DirectMessage can :new, DirectMessage
can [:read, :debate, :draft_publication, :allegations, :result_publication, can [:read, :debate, :draft_publication, :allegations, :result_publication,
:proposals, :milestones], Legislation::Process, published: true :proposals, :milestones], Legislation::Process, published: true
can :resume, Legislation::Process do |process| can :resume, Legislation::Process, &:past?
process.past?
end
can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read, :changes, :go_to_version], Legislation::DraftVersion
can [:read], Legislation::Question can [:read], Legislation::Question
can [:read, :map, :share], Legislation::Proposal can [:read, :map, :share], Legislation::Proposal

View File

@@ -13,6 +13,6 @@ module Relationable
end end
def relationed_contents def relationed_contents
related_contents.not_hidden.map { |related_content| related_content.child_relationable } related_contents.not_hidden.map(&:child_relationable)
end end
end end

View File

@@ -75,7 +75,7 @@ class Poll::Question < ApplicationRecord
end end
def most_voted_answer_id def most_voted_answer_id
question_answers.max_by { |answer| answer.total_votes }.id question_answers.max_by(&:total_votes).id
end end
def answers_with_read_more? def answers_with_read_more?

View File

@@ -4,7 +4,7 @@ class ManagerAuthenticator
end end
def auth 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? return @manager if manager_exists? && application_authorized?
false false

View File

@@ -66,7 +66,7 @@ class RemoteCensusApi
end end
def parse_response_path(path_value) 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
end end

View File

@@ -6,7 +6,7 @@ require "json"
class RemoteTranslations::Microsoft::AvailableLocales class RemoteTranslations::Microsoft::AvailableLocales
def self.available_locales def self.available_locales
daily_cache("locales") do daily_cache("locales") do
remote_available_locales.map { |locale| locale.first } remote_available_locales.map(&:first)
end end
end end

View File

@@ -6,8 +6,8 @@ FactoryBot.define do
factory :geozone do factory :geozone do
sequence(:name) { |n| "District #{n}" } sequence(:name) { |n| "District #{n}" }
sequence(:external_code) { |n| n.to_s } sequence(:external_code, &:to_s)
sequence(:census_code) { |n| n.to_s } sequence(:census_code, &:to_s)
trait :in_census do trait :in_census do
census_code { "01" } census_code { "01" }

View File

@@ -12,6 +12,6 @@ FactoryBot.define do
factory :campaign do factory :campaign do
sequence(:name) { |n| "Campaign #{n}" } sequence(:name) { |n| "Campaign #{n}" }
sequence(:track_id) { |n| n.to_s } sequence(:track_id, &:to_s)
end end
end end

View File

@@ -101,7 +101,7 @@ FactoryBot.define do
incompatible { false } incompatible { false }
trait :with_confidence_score do trait :with_confidence_score do
before(:save) { |i| i.calculate_confidence_score } before(:save, &:calculate_confidence_score)
end end
trait :feasible do trait :feasible do

View File

@@ -23,7 +23,7 @@ FactoryBot.define do
end end
trait :with_confidence_score do trait :with_confidence_score do
before(:save) { |d| d.calculate_confidence_score } before(:save, &:calculate_confidence_score)
end end
trait :valuation do trait :valuation do

View File

@@ -24,11 +24,11 @@ FactoryBot.define do
end end
trait :with_hot_score do trait :with_hot_score do
before(:save) { |d| d.calculate_hot_score } before(:save, &:calculate_hot_score)
end end
trait :with_confidence_score do trait :with_confidence_score do
before(:save) { |d| d.calculate_confidence_score } before(:save, &:calculate_confidence_score)
end end
trait :conflictive do trait :conflictive do

View File

@@ -38,11 +38,11 @@ FactoryBot.define do
end end
trait :with_hot_score do trait :with_hot_score do
before(:save) { |d| d.calculate_hot_score } before(:save, &:calculate_hot_score)
end end
trait :with_confidence_score do trait :with_confidence_score do
before(:save) { |d| d.calculate_confidence_score } before(:save, &:calculate_confidence_score)
end end
trait :conflictive do trait :conflictive do

View File

@@ -632,11 +632,11 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id) visit budget_investments_path(budget, heading_id: heading.id)
within(".submenu .is-active") { expect(page).to have_content "random" } 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 expect(order).not_to be_empty
visit budget_investments_path(budget, heading_id: heading.id) 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) expect(order).to eq(new_order)
end end
@@ -645,14 +645,14 @@ describe "Budget Investments" do
(per_page + 2).times { create(:budget_investment, heading: heading) } (per_page + 2).times { create(:budget_investment, heading: heading) }
visit budget_investments_path(budget, heading_id: heading.id) 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 expect(order).not_to be_empty
click_link "highest rated" click_link "highest rated"
click_link "random" click_link "random"
visit budget_investments_path(budget, heading_id: heading.id) 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) expect(order).to eq(new_order)
end end
@@ -662,7 +662,7 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id) 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 expect(order).not_to be_empty
click_link "Next" click_link "Next"
@@ -671,7 +671,7 @@ describe "Budget Investments" do
click_link "Previous" click_link "Previous"
expect(page).to have_content "You're on page 1" 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) expect(order).to eq(new_order)
end end
@@ -680,13 +680,13 @@ describe "Budget Investments" do
visit budget_investments_path(budget, heading_id: heading.id) 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 expect(order).not_to be_empty
click_link Budget::Investment.first.title click_link Budget::Investment.first.title
click_link "Go back" 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) expect(order).to eq(new_order)
end end
@@ -812,11 +812,11 @@ describe "Budget Investments" do
budget.update!(phase: "finished") budget.update!(phase: "finished")
visit budget_investments_path(budget, heading_id: heading.id) 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 expect(order).not_to be_empty
visit budget_investments_path(budget, heading_id: heading.id) 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) expect(order).to eq(new_order)
end end
@@ -844,7 +844,7 @@ describe "Budget Investments" do
end end
def investments_order def investments_order
all(".budget-investment h3").map { |i| i.text } all(".budget-investment h3").map(&:text)
end end
end end

View File

@@ -229,7 +229,7 @@ describe "Notifications" do
end end
def remove_users_without_pending_notifications def remove_users_without_pending_notifications
users_without_notifications.each { |user| user.destroy } users_without_notifications.each(&:destroy)
end end
def users_without_notifications def users_without_notifications

View File

@@ -418,7 +418,7 @@ describe "Users" do
scenario "Gracefully handle followables that have been hidden" do scenario "Gracefully handle followables that have been hidden" do
create(:proposal, followers: [user]) create(:proposal, followers: [user])
create(:proposal, followers: [user]) { |proposal| proposal.hide } create(:proposal, followers: [user], &:hide)
visit user_path(user) visit user_path(user)

View File

@@ -396,7 +396,7 @@ describe "Consul Schema" do
describe "Geozones" do describe "Geozones" do
it "returns 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 } } } }") response = execute("{ geozones { edges { node { name } } } }")
received_names = extract_fields(response, "geozones", "name") received_names = extract_fields(response, "geozones", "name")