diff --git a/.rubocop.yml b/.rubocop.yml index d89574c31..255a9f392 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -58,12 +58,21 @@ Layout/EndOfLine: Layout/ExtraSpacing: Enabled: true +Layout/IndentAssignment: + Enabled: true + +Layout/IndentHeredoc: + Enabled: true + Layout/IndentationConsistency: EnforcedStyle: indented_internal_methods Layout/IndentationWidth: Enabled: true +Layout/LeadingBlankLines: + Enabled: true + Layout/MultilineBlockLayout: Enabled: true @@ -106,6 +115,9 @@ Layout/SpaceBeforeFirstArg: Layout/SpaceBeforeSemicolon: Enabled: true +Layout/SpaceInLambdaLiteral: + Enabled: true + Layout/SpaceInsideArrayLiteralBrackets: Enabled: true @@ -355,14 +367,65 @@ Security/JSONLoad: Security/YAMLLoad: Enabled: true +Style/AndOr: + Enabled: true + Style/BlockDelimiters: Enabled: true +Style/ClassCheck: + Enabled: true + +Style/ClassVars: + Enabled: true + +Style/CollectionMethods: + Enabled: true + +Style/HashSyntax: + Enabled: true + +Style/IdenticalConditionalBranches: + Enabled: true + +Style/MethodDefParentheses: + Enabled: true + +Style/MutableConstant: + Enabled: true + +Style/Not: + Enabled: true + +Style/OrAssignment: + Enabled: true + Style/PercentLiteralDelimiters: Enabled: true +Style/Proc: + Enabled: true + +Style/RedundantFreeze: + Enabled: true + +Style/RedundantReturn: + Enabled: true + Style/SafeNavigation: Enabled: true Style/StringLiterals: EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes + +Style/SymbolProc: + Enabled: true + +Style/TrailingCommaInArrayLiteral: + Enabled: true + +Style/TrailingCommaInHashLiteral: + Enabled: true diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index 9acc6f2ee..afbf009f4 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -62,7 +62,6 @@ class Admin::BannersController < Admin::BaseController end def resource - @banner = Banner.find(params[:id]) unless @banner - @banner + @banner ||= Banner.find(params[:id]) end end diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index c532ef320..aab41bbcf 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -84,7 +84,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController def load_investments @investments = Budget::Investment.scoped_filter(params, @current_filter).order_filter(params) - @investments = Kaminari.paginate_array(@investments) if @investments.kind_of?(Array) + @investments = Kaminari.paginate_array(@investments) if @investments.is_a?(Array) @investments = @investments.page(params[:page]) unless request.format.csv? end 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/site_customization/images_controller.rb b/app/controllers/admin/site_customization/images_controller.rb index 149b5f489..c05647e29 100644 --- a/app/controllers/admin/site_customization/images_controller.rb +++ b/app/controllers/admin/site_customization/images_controller.rb @@ -29,11 +29,11 @@ class Admin::SiteCustomization::ImagesController < Admin::SiteCustomization::Bas @image.image = nil if @image.save notice = t("admin.site_customization.images.destroy.notice") - redirect_to admin_site_customization_images_path, notice: notice else notice = t("admin.site_customization.images.destroy.error") - redirect_to admin_site_customization_images_path, notice: notice end + + redirect_to admin_site_customization_images_path, notice: notice end private diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 94fa1da7f..b7c6c6cad 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -80,9 +80,9 @@ class Admin::StatsController < Admin::BaseController @vote_count = @budget.lines.count - @vote_count_by_heading = @budget.lines.group(:heading_id).count.collect { |k, v| [Budget::Heading.find(k).name, v] }.sort + @vote_count_by_heading = @budget.lines.group(:heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort - @user_count_by_district = User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.collect { |k, v| [Budget::Heading.find(k).name, v] }.sort + @user_count_by_district = User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.map { |k, v| [Budget::Heading.find(k).name, v] }.sort end def polls 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/concerns/dashboard/group_supports.rb b/app/controllers/concerns/dashboard/group_supports.rb index abe833729..f9dfe0fbc 100644 --- a/app/controllers/concerns/dashboard/group_supports.rb +++ b/app/controllers/concerns/dashboard/group_supports.rb @@ -15,7 +15,7 @@ module Dashboard::GroupSupports def accumulate_supports(grouped_votes) grouped_votes.each do |group, votes| - grouped_votes[group] = votes.inject(0) { |sum, vote| sum + vote.vote_weight } + grouped_votes[group] = votes.reduce(0) { |sum, vote| sum + vote.vote_weight } end accumulated = 0 diff --git a/app/controllers/concerns/remotely_translatable.rb b/app/controllers/concerns/remotely_translatable.rb index 35662b5fb..b21f6c39b 100644 --- a/app/controllers/concerns/remotely_translatable.rb +++ b/app/controllers/concerns/remotely_translatable.rb @@ -20,7 +20,7 @@ module RemotelyTranslatable end def resources_groups(*args) - feeds = args.detect { |arg| arg&.first.class == Widget::Feed } || [] + feeds = args.find { |arg| arg&.first.class == Widget::Feed } || [] args.compact - [feeds] + feeds.map(&:items) end diff --git a/app/controllers/dashboard/achievements_controller.rb b/app/controllers/dashboard/achievements_controller.rb index b149fb7be..320dbc2ce 100644 --- a/app/controllers/dashboard/achievements_controller.rb +++ b/app/controllers/dashboard/achievements_controller.rb @@ -36,12 +36,12 @@ class Dashboard::AchievementsController < Dashboard::BaseController def executed_proposed_actions @executed_proposed_actions ||= - Dashboard::ExecutedAction - .joins(:action) - .includes(:action) - .where(proposal: proposal) - .where(executed_at: start_date.beginning_of_day..end_date.end_of_day) - .where(dashboard_actions: { action_type: 0 }) - .order(executed_at: :asc) + Dashboard::ExecutedAction + .joins(:action) + .includes(:action) + .where(proposal: proposal) + .where(executed_at: start_date.beginning_of_day..end_date.end_of_day) + .where(dashboard_actions: { action_type: 0 }) + .order(executed_at: :asc) 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/controllers/tracking/budget_investments_controller.rb b/app/controllers/tracking/budget_investments_controller.rb index 3a9c2a34c..e5fe27f28 100644 --- a/app/controllers/tracking/budget_investments_controller.rb +++ b/app/controllers/tracking/budget_investments_controller.rb @@ -58,7 +58,7 @@ class Tracking::BudgetInvestmentsController < Tracking::BaseController } ] - investment_headings.inject(all_headings_filter) do |filters, heading| + investment_headings.reduce(all_headings_filter) do |filters, heading| filters << { name: heading.name, id: heading.id, diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index 817562163..9a05f3cc8 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -83,7 +83,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController } ] - investment_headings.inject(all_headings_filter) do |filters, heading| + investment_headings.reduce(all_headings_filter) do |filters, heading| filters << { name: heading.name, id: heading.id, diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 96d1e9e48..d9ff773fc 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -83,9 +83,7 @@ module AdminHelper end def admin_select_options - Administrator.with_user - .collect { |v| [v.description_or_name, v.id] } - .sort_by { |a| a[0] } + Administrator.with_user.map { |v| [v.description_or_name, v.id] }.sort_by { |a| a[0] } end def admin_submit_action(resource) 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/embed_videos_helper.rb b/app/helpers/embed_videos_helper.rb index 08a3179f8..af4f23ac2 100644 --- a/app/helpers/embed_videos_helper.rb +++ b/app/helpers/embed_videos_helper.rb @@ -1,6 +1,6 @@ module EmbedVideosHelper - VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ - YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/.freeze + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/.freeze def embedded_video_code(resource) link = resource.video_url diff --git a/app/helpers/geozones_helper.rb b/app/helpers/geozones_helper.rb index cf53a086e..20831986d 100644 --- a/app/helpers/geozones_helper.rb +++ b/app/helpers/geozones_helper.rb @@ -4,6 +4,6 @@ module GeozonesHelper end def geozone_select_options - Geozone.all.order(name: :asc).collect { |g| [g.name, g.id] } + Geozone.all.order(name: :asc).map { |g| [g.name, g.id] } end end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index ba158fb08..f04993d4c 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -1,6 +1,6 @@ module PollsHelper def poll_select_options(include_all = nil) - options = @polls.collect do |poll| + options = @polls.map do |poll| [poll.name, current_path_with_query_params(poll_id: poll.id)] end options << all_polls if include_all diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index e7f10f9db..e5dccab2e 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -28,7 +28,7 @@ module ProposalsHelper end def retire_proposals_options - Proposal::RETIRE_OPTIONS.collect { |option| [t("proposals.retire_options.#{option}"), option] } + Proposal::RETIRE_OPTIONS.map { |option| [t("proposals.retire_options.#{option}"), option] } end def empty_recommended_proposals_message_text(user) diff --git a/app/helpers/shifts_helper.rb b/app/helpers/shifts_helper.rb index 4fe10f7c8..deb4d62b6 100644 --- a/app/helpers/shifts_helper.rb +++ b/app/helpers/shifts_helper.rb @@ -8,7 +8,7 @@ module ShiftsHelper def shift_recount_scrutiny_dates(booth, polls) return [] if polls.blank? - dates = polls.map(&:ends_at).map(&:to_date).sort.inject([]) do |total, date| + dates = polls.map(&:ends_at).map(&:to_date).sort.reduce([]) do |total, date| initial_date = date < Date.current ? Date.current : date total << (initial_date..date + Poll::RECOUNT_DURATION).to_a end @@ -33,7 +33,7 @@ module ShiftsHelper end def officer_select_options(officers) - officers.collect { |officer| [officer.name, officer.id] } + officers.map { |officer| [officer.name, officer.id] } end private diff --git a/app/helpers/signature_sheets_helper.rb b/app/helpers/signature_sheets_helper.rb index 0c32bd925..252973f0a 100644 --- a/app/helpers/signature_sheets_helper.rb +++ b/app/helpers/signature_sheets_helper.rb @@ -26,7 +26,7 @@ module SignatureSheetsHelper text_help += tag(:br) text_help += t("admin.signature_sheets.new.text_help.required_fields_structure_note") - return text_help + text_help end def example_text_help @@ -45,6 +45,6 @@ module SignatureSheetsHelper end text_example += "#{example_1}; #{example_2}" - return text_example + text_example end end diff --git a/app/helpers/translatable_form_helper.rb b/app/helpers/translatable_form_helper.rb index 78ce9566d..efe0e2b48 100644 --- a/app/helpers/translatable_form_helper.rb +++ b/app/helpers/translatable_form_helper.rb @@ -60,13 +60,11 @@ module TranslatableFormHelper end def existing_translation_for(locale) - @object.translations.detect { |translation| translation.locale == locale } + @object.translations.find { |translation| translation.locale == locale } 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/helpers/user_segments_helper.rb b/app/helpers/user_segments_helper.rb index 796ff03da..72925c6b1 100644 --- a/app/helpers/user_segments_helper.rb +++ b/app/helpers/user_segments_helper.rb @@ -1,6 +1,6 @@ module UserSegmentsHelper def user_segments_options - UserSegments::SEGMENTS.collect do |user_segment_name| + UserSegments::SEGMENTS.map do |user_segment_name| [t("admin.segment_recipient.#{user_segment_name}"), user_segment_name] end end diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb index 2ffe8ad94..9dab279ef 100644 --- a/app/helpers/valuation_helper.rb +++ b/app/helpers/valuation_helper.rb @@ -5,11 +5,11 @@ module ValuationHelper def valuator_select_options Valuator.order("description ASC").order("users.email ASC").includes(:user). - collect { |v| [v.description_or_email, "valuator_#{v.id}"] } + map { |v| [v.description_or_email, "valuator_#{v.id}"] } end def valuator_group_select_options - ValuatorGroup.order("name ASC").collect { |g| [g.name, "group_#{g.id}"] } + ValuatorGroup.order("name ASC").map { |g| [g.name, "group_#{g.id}"] } end def explanation_field(field) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 278862070..f44f0ac0d 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,6 @@ class ApplicationMailer < ActionMailer::Base helper :settings helper :application - default from: Proc.new { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" } + default from: proc { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" } layout "mailer" end 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/activity.rb b/app/models/activity.rb index a0c862c25..3accc495b 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -2,7 +2,7 @@ class Activity < ApplicationRecord belongs_to :actionable, -> { with_hidden }, polymorphic: true belongs_to :user, -> { with_hidden }, inverse_of: :activities - VALID_ACTIONS = %w[hide block restore valuate email] + VALID_ACTIONS = %w[hide block restore valuate email].freeze validates :action, inclusion: { in: VALID_ACTIONS } diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 3e3d8b07d..51616c0a2 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -1,6 +1,6 @@ class Budget class Heading < ApplicationRecord - OSM_DISTRICT_LEVEL_ZOOM = 12.freeze + OSM_DISTRICT_LEVEL_ZOOM = 12 include Sluggable diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 68010ec3d..2ee462a0f 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -376,11 +376,11 @@ class Budget end def assigned_valuators - self.valuators.collect(&:description_or_name).compact.join(", ").presence + self.valuators.map(&:description_or_name).compact.join(", ").presence end def assigned_valuation_groups - self.valuator_groups.collect(&:name).compact.join(", ").presence + self.valuator_groups.map(&:name).compact.join(", ").presence end def valuation_tag_list diff --git a/app/models/budget/reclassified_vote.rb b/app/models/budget/reclassified_vote.rb index 1e9053428..ea73d27c1 100644 --- a/app/models/budget/reclassified_vote.rb +++ b/app/models/budget/reclassified_vote.rb @@ -1,6 +1,6 @@ class Budget class ReclassifiedVote < ApplicationRecord - REASONS = %w[heading_changed unfeasible] + REASONS = %w[heading_changed unfeasible].freeze belongs_to :user belongs_to :investment diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 2ff34469e..f929246ea 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -54,7 +54,7 @@ class Budget::Stats end def total_votes - budget.ballots.pluck(:ballot_lines_count).inject(0) { |sum, x| sum + x } + budget.ballots.pluck(:ballot_lines_count).reduce(0) { |sum, x| sum + x } end def total_selected_investments @@ -72,18 +72,18 @@ class Budget::Stats end groups[:total] = Hash.new(0) - groups[:total][:total_investments_count] = groups.collect { |_k, v| v[:total_investments_count] }.sum - groups[:total][:total_participants_support_phase] = groups.collect { |_k, v| v[:total_participants_support_phase] }.sum - groups[:total][:total_participants_vote_phase] = groups.collect { |_k, v| v[:total_participants_vote_phase] }.sum - groups[:total][:total_participants_every_phase] = groups.collect { |_k, v| v[:total_participants_every_phase] }.sum + groups[:total][:total_investments_count] = groups.map { |_k, v| v[:total_investments_count] }.sum + groups[:total][:total_participants_support_phase] = groups.map { |_k, v| v[:total_participants_support_phase] }.sum + groups[:total][:total_participants_vote_phase] = groups.map { |_k, v| v[:total_participants_vote_phase] }.sum + groups[:total][:total_participants_every_phase] = groups.map { |_k, v| v[:total_participants_every_phase] }.sum budget.headings.each do |heading| groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population)) end - groups[:total][:percentage_participants_support_phase] = groups.collect { |_k, v| v[:percentage_participants_support_phase] }.sum - groups[:total][:percentage_participants_vote_phase] = groups.collect { |_k, v| v[:percentage_participants_vote_phase] }.sum - groups[:total][:percentage_participants_every_phase] = groups.collect { |_k, v| v[:percentage_participants_every_phase] }.sum + groups[:total][:percentage_participants_support_phase] = groups.map { |_k, v| v[:percentage_participants_support_phase] }.sum + groups[:total][:percentage_participants_vote_phase] = groups.map { |_k, v| v[:percentage_participants_vote_phase] }.sum + groups[:total][:percentage_participants_every_phase] = groups.map { |_k, v| v[:percentage_participants_every_phase] }.sum groups end diff --git a/app/models/budget_administrator.rb b/app/models/budget_administrator.rb index 0f4b121a2..4cf18a3ce 100644 --- a/app/models/budget_administrator.rb +++ b/app/models/budget_administrator.rb @@ -1,4 +1,3 @@ - class BudgetAdministrator < ApplicationRecord belongs_to :budget belongs_to :administrator diff --git a/app/models/concerns/measurable.rb b/app/models/concerns/measurable.rb index affb113c2..77042efae 100644 --- a/app/models/concerns/measurable.rb +++ b/app/models/concerns/measurable.rb @@ -3,11 +3,11 @@ module Measurable class_methods do def title_max_length - @@title_max_length ||= (columns.find { |c| c.name == "title" }.limit rescue nil) || 80 + @title_max_length ||= (columns.find { |c| c.name == "title" }&.limit) || 80 end def responsible_name_max_length - @@responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }.limit rescue nil) || 60 + @responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }&.limit) || 60 end def question_max_length 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/concerns/search_cache.rb b/app/models/concerns/search_cache.rb index 02634e55d..3ec8bc33f 100644 --- a/app/models/concerns/search_cache.rb +++ b/app/models/concerns/search_cache.rb @@ -15,7 +15,7 @@ module SearchCache def searchable_values_sql searchable_values .select { |k, _| k.present? } - .collect { |value, weight| set_tsvector(value, weight) } + .map { |value, weight| set_tsvector(value, weight) } .join(" || ") end diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 144367559..83ab583f8 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -1,6 +1,6 @@ module Statisticable extend ActiveSupport::Concern - PARTICIPATIONS = %w[gender age geozone] + PARTICIPATIONS = %w[gender age geozone].freeze included do attr_reader :resource diff --git a/app/models/custom/verification/residence.rb b/app/models/custom/verification/residence.rb index 95c94a99b..a0e71dda5 100644 --- a/app/models/custom/verification/residence.rb +++ b/app/models/custom/verification/residence.rb @@ -1,4 +1,3 @@ - require_dependency Rails.root.join("app", "models", "verification", "residence").to_s class Verification::Residence diff --git a/app/models/debate.rb b/app/models/debate.rb index 7512a5342..756563007 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -74,7 +74,7 @@ class Debate < ApplicationRecord { author.username => "B", tag_list.join(" ") => "B", - geozone&.name => "B", + geozone&.name => "B" }.merge!(searchable_globalized_values) end @@ -165,6 +165,6 @@ class Debate < ApplicationRecord def self.debates_orders(user) orders = %w[hot_score confidence_score created_at relevance] orders << "recommendations" if Setting["feature.user.recommendations_on_debates"] && user&.recommended_debates - return orders + orders end end diff --git a/app/models/i18n_content.rb b/app/models/i18n_content.rb index c742db04a..53af6f51e 100644 --- a/app/models/i18n_content.rb +++ b/app/models/i18n_content.rb @@ -40,7 +40,7 @@ class I18nContent < ApplicationRecord return output.update({ path => input }) unless input.is_a? Hash input.map { |key, value| flat_hash(value, [path, key].compact.join("."), output) } - return output + output end def self.content_for(tab) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 1e079bb8e..93b65eb8f 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -1,5 +1,5 @@ class Legislation::DraftVersion < ApplicationRecord - VALID_STATUSES = %w[draft published] + VALID_STATUSES = %w[draft published].freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 359c31001..e11bc3b09 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -23,7 +23,7 @@ class Legislation::Process < ApplicationRecord proposals_phase people_proposals_phase draft_publication result_publication].freeze - CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i + CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i.freeze has_many :draft_versions, -> { order(:id) }, foreign_key: "legislation_process_id", diff --git a/app/models/local_census_record.rb b/app/models/local_census_record.rb index a14a8fb92..71ead77a7 100644 --- a/app/models/local_census_record.rb +++ b/app/models/local_census_record.rb @@ -7,7 +7,7 @@ class LocalCensusRecord < ApplicationRecord validates :postal_code, presence: true validates :document_number, uniqueness: { scope: :document_type } - scope :search, -> (terms) { where("document_number ILIKE ?", "%#{terms}%") } + scope :search, ->(terms) { where("document_number ILIKE ?", "%#{terms}%") } private diff --git a/app/models/organization.rb b/app/models/organization.rb index 32d545249..abda49873 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -42,11 +42,11 @@ class Organization < ApplicationRecord end def self.name_max_length - @@name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60 + @name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60 end def self.responsible_name_max_length - @@responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60 + @responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60 end private diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index d608044cc..134cf377d 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -1,5 +1,5 @@ class Poll::PartialResult < ApplicationRecord - VALID_ORIGINS = %w[web booth] + VALID_ORIGINS = %w[web booth].freeze belongs_to :question, -> { with_hidden }, inverse_of: :partial_results belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :poll_partial_results @@ -9,7 +9,7 @@ class Poll::PartialResult < ApplicationRecord validates :question, presence: true validates :author, presence: true validates :answer, presence: true - validates :answer, inclusion: { in: -> (a) { a.question.possible_answers }}, + validates :answer, inclusion: { in: ->(a) { a.question.possible_answers }}, unless: ->(a) { a.question.blank? } validates :origin, inclusion: { in: VALID_ORIGINS } diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index f7314ac22..6563887d9 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -26,7 +26,7 @@ class Poll::Question < ApplicationRecord validates_translation :title, presence: true, length: { minimum: 4 } validates :author, presence: true - validates :poll_id, presence: true, if: Proc.new { |question| question.poll.nil? } + validates :poll_id, presence: true, if: proc { |question| question.poll.nil? } validates_associated :votation_type accepts_nested_attributes_for :question_answers, reject_if: :all_blank, allow_destroy: true @@ -71,11 +71,11 @@ class Poll::Question < ApplicationRecord end def answers_total_votes - question_answers.visibles.inject(0) { |total, question_answer| total + question_answer.total_votes } + question_answers.visibles.reduce(0) { |total, question_answer| total + question_answer.total_votes } 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/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index 91320743c..97a002752 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -15,7 +15,7 @@ class Poll::Question::Answer < ApplicationRecord validates_translation :title, presence: true validates :given_order, presence: true, uniqueness: { scope: :question_id } - scope :by_author, -> (author) { where(author: author) } + scope :by_author, ->(author) { where(author: author) } scope :visibles, -> { where(hidden: false) } diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb index 6cf9e7cc6..5f5407bcc 100644 --- a/app/models/poll/question/answer/video.rb +++ b/app/models/poll/question/answer/video.rb @@ -1,8 +1,8 @@ class Poll::Question::Answer::Video < ApplicationRecord belongs_to :answer, class_name: "Poll::Question::Answer" - VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ - YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ + VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/.freeze + YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/.freeze validates :title, presence: true validate :valid_url? diff --git a/app/models/progress_bar.rb b/app/models/progress_bar.rb index f60e4f2b3..3da9c072b 100644 --- a/app/models/progress_bar.rb +++ b/app/models/progress_bar.rb @@ -1,6 +1,6 @@ class ProgressBar < ApplicationRecord self.inheritance_column = nil - RANGE = 0..100 + RANGE = (0..100).freeze enum kind: %i[primary secondary] diff --git a/app/models/proposal.rb b/app/models/proposal.rb index c02e09bd1..c9b5a5d19 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -26,7 +26,7 @@ class Proposal < ApplicationRecord acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - RETIRE_OPTIONS = %w[duplicated started unfeasible done other] + RETIRE_OPTIONS = %w[duplicated started unfeasible done other].freeze translates :title, touch: true translates :description, touch: true @@ -243,7 +243,7 @@ class Proposal < ApplicationRecord def self.proposals_orders(user) orders = %w[hot_score confidence_score created_at relevance archival_date] orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals - return orders + orders end def skip_user_verification? diff --git a/app/models/report.rb b/app/models/report.rb index 857cb462f..e8d26a829 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,5 +1,5 @@ class Report < ApplicationRecord - KINDS = %i[results stats advanced_stats] + KINDS = %i[results stats advanced_stats].freeze belongs_to :process, polymorphic: true end diff --git a/app/models/signature.rb b/app/models/signature.rb index 144a21309..bec7d7f39 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -71,7 +71,7 @@ class Signature < ApplicationRecord end def in_census? - document_types.detect do |document_type| + document_types.find do |document_type| response = CensusCaller.new.call(document_type, document_number, date_of_birth, postal_code) if response.valid? @census_api_response = response diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index 26d7ec072..aa6fdbb71 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -2,7 +2,7 @@ class SignatureSheet < ApplicationRecord belongs_to :signable, polymorphic: true belongs_to :author, class_name: "User" - VALID_SIGNABLES = %w[Proposal Budget::Investment] + VALID_SIGNABLES = %w[Proposal Budget::Investment].freeze has_many :signatures @@ -35,7 +35,7 @@ class SignatureSheet < ApplicationRecord end def parsed_required_fields_to_verify_groups - required_fields_to_verify.split(/[;]/).collect { |d| d.gsub(/\s+/, "") }.map { |group| group.split(/[,]/) } + required_fields_to_verify.split(/[;]/).map { |d| d.gsub(/\s+/, "") }.map { |group| group.split(/[,]/) } end def signable_found @@ -52,11 +52,11 @@ class SignatureSheet < ApplicationRecord def parse_postal_code(required_fields_to_verify) if Setting.force_presence_date_of_birth? && Setting.force_presence_postal_code? - return required_fields_to_verify[2] + required_fields_to_verify[2] elsif Setting.force_presence_postal_code? - return required_fields_to_verify[1] + required_fields_to_verify[1] else - return nil + nil end end end diff --git a/app/models/site_customization/content_block.rb b/app/models/site_customization/content_block.rb index a96bc8b47..a41580e36 100644 --- a/app/models/site_customization/content_block.rb +++ b/app/models/site_customization/content_block.rb @@ -1,5 +1,5 @@ class SiteCustomization::ContentBlock < ApplicationRecord - VALID_BLOCKS = %w[top_links footer subnavigation_left subnavigation_right] + VALID_BLOCKS = %w[top_links footer subnavigation_left subnavigation_right].freeze validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) } validates :name, presence: true, uniqueness: { scope: :locale }, inclusion: { in: VALID_BLOCKS } diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index 0ebf1f929..77f0e16ab 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -7,7 +7,7 @@ class SiteCustomization::Image < ApplicationRecord "budget_execution_no_image" => [800, 600], "map" => [420, 500], "logo_email" => [400, 80] - } + }.freeze has_attached_file :image diff --git a/app/models/site_customization/page.rb b/app/models/site_customization/page.rb index be59d0dcd..03c4bcccc 100644 --- a/app/models/site_customization/page.rb +++ b/app/models/site_customization/page.rb @@ -1,5 +1,5 @@ class SiteCustomization::Page < ApplicationRecord - VALID_STATUSES = %w[draft published] + VALID_STATUSES = %w[draft published].freeze has_many :cards, class_name: "Widget::Card", foreign_key: "site_customization_page_id", diff --git a/app/models/user.rb b/app/models/user.rb index 73388580b..ee618566d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -123,7 +123,7 @@ class User < ApplicationRecord string = "%#{search_string}%" where("username ILIKE ? OR email ILIKE ? OR document_number ILIKE ?", string, string, string) end - scope :between_ages, -> (from, to) do + scope :between_ages, ->(from, to) do where( "date_of_birth > ? AND date_of_birth < ?", to.years.ago.beginning_of_year, @@ -313,7 +313,7 @@ class User < ApplicationRecord end def self.username_max_length - @@username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60 + @username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60 end def self.minimum_required_age diff --git a/app/models/votation_set_answer.rb b/app/models/votation_set_answer.rb index c299881b3..7cc3a55cb 100644 --- a/app/models/votation_set_answer.rb +++ b/app/models/votation_set_answer.rb @@ -2,5 +2,5 @@ class VotationSetAnswer < ApplicationRecord belongs_to :votation_type belongs_to :author, -> { with_hidden }, class_name: "User", inverse_of: :votation_set_answers - scope :by_author, -> (author) { where(author: author) } + scope :by_author, ->(author) { where(author: author) } end diff --git a/app/models/votation_type.rb b/app/models/votation_type.rb index 661a2a2bf..b56b6251c 100644 --- a/app/models/votation_type.rb +++ b/app/models/votation_type.rb @@ -21,7 +21,7 @@ class VotationType < ApplicationRecord answer_set_open: { enum_type: 7, open_answer: true, prioritized: false, variables: [:max_votes, :max_groups_answers] }, answer_set_closed: { enum_type: 8, open_answer: false, prioritized: false, - variables: [:max_votes, :max_groups_answers] }, + variables: [:max_votes, :max_groups_answers] } }.freeze enum enum_type: ENUM_TYPES_PROPS.map { |k, v| [k, v[:enum_type]] }.to_h.freeze diff --git a/app/models/widget/feed.rb b/app/models/widget/feed.rb index 8947e8843..d90cdee2d 100644 --- a/app/models/widget/feed.rb +++ b/app/models/widget/feed.rb @@ -1,7 +1,7 @@ class Widget::Feed < ApplicationRecord self.table_name = "widget_feeds" - KINDS = %w[proposals debates processes] + KINDS = %w[proposals debates processes].freeze def active? setting.value.present? @@ -12,7 +12,7 @@ class Widget::Feed < ApplicationRecord end def self.active - KINDS.collect do |kind| + KINDS.map do |kind| feed = find_or_create_by!(kind: kind) feed if feed.active? end.compact diff --git a/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx b/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx index 6f120a3cb..6dd1ebd65 100644 --- a/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx +++ b/app/views/legislation/processes/resume_to_xlsx.xlsx.axlsx @@ -5,10 +5,10 @@ wb.add_worksheet(name: "Resume") do |sheet| sheet.add_row [t("legislation.summary.debates_phase"), t("legislation.questions.question.total", count: @process.questions.count)] @process.questions.each do |question| sheet.add_row [question.title, t("legislation.summary.comments", count: question.comments.count)] - sheet.add_hyperlink :location => legislation_process_question_url(question.process, question), :ref => sheet.rows.last.cells.first + sheet.add_hyperlink location: legislation_process_question_url(question.process, question), ref: sheet.rows.last.cells.first question.best_comments(3).each do |comment| sheet.add_row [comment.body, (comment.cached_votes_up - comment.cached_votes_down).to_s + space + t("legislation.summary.votes")] - sheet.add_hyperlink :location => comment_url(comment), :ref => sheet.rows.last.cells.first + sheet.add_hyperlink location: comment_url(comment), ref: sheet.rows.last.cells.first end sheet.add_row ["", ""] end @@ -19,7 +19,7 @@ wb.add_worksheet(name: "Resume") do |sheet| Legislation::Proposal.where(legislation_process_id: @process).where(selected: true).order("cached_votes_score desc").each do |proposal| sheet.add_row [proposal.title, (proposal.cached_votes_total - proposal.cached_votes_down).to_s + space + t("legislation.summary.votes")] - sheet.add_hyperlink :location => legislation_process_proposal_url(proposal.legislation_process_id, proposal), :ref => sheet.rows.last.cells.first + sheet.add_hyperlink location: legislation_process_proposal_url(proposal.legislation_process_id, proposal), ref: sheet.rows.last.cells.first end sheet.add_row ["", ""] end @@ -30,7 +30,7 @@ wb.add_worksheet(name: "Resume") do |sheet| @process.get_best_annotation_comments.take(10).each do |comment| sheet.add_row [Legislation::Annotation.find_by(id: comment.commentable_id).quote, ""] sheet.add_row [comment.body, (comment.cached_votes_up - comment.cached_votes_down).to_s + space + t("legislation.summary.votes")] - sheet.add_hyperlink :location => comment_url(comment), :ref => sheet.rows.last.cells.first + sheet.add_hyperlink location: comment_url(comment), ref: sheet.rows.last.cells.first end end end diff --git a/bin/spring b/bin/spring index b44ad1a7a..e46bd19bd 100755 --- a/bin/spring +++ b/bin/spring @@ -8,7 +8,7 @@ unless defined?(Spring) require "bundler" lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } + spring = lockfile.specs.find { |spec| spec.name == "spring" } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem "spring", spring.version diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 3f4a58076..86cefbf61 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -12,7 +12,7 @@ Devise.setup do |config| # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = Proc.new { "'#{Setting["mailer_from_name"]}' <#{Setting["mailer_from_address"]}>" } + config.mailer_sender = proc { "'#{Setting["mailer_from_name"]}' <#{Setting["mailer_from_address"]}>" } # Configure the class responsible to send e-mails. config.mailer = "DeviseMailer" diff --git a/config/initializers/devise_security_extension.rb b/config/initializers/devise_security_extension.rb index 51cf56429..8a86bb15d 100644 --- a/config/initializers/devise_security_extension.rb +++ b/config/initializers/devise_security_extension.rb @@ -62,7 +62,7 @@ module Devise if !self.new_record? && !self.encrypted_password_change.nil? && !self.erased? dummy = self.class.new dummy.encrypted_password = self.encrypted_password_change.first - dummy.password_salt = self.password_salt_change.first if self.respond_to? :password_salt_change and not self.password_salt_change.nil? + dummy.password_salt = self.password_salt_change.first if self.respond_to?(:password_salt_change) && !self.password_salt_change.nil? self.errors.add(:password, :equal_to_current_password) if dummy.valid_password?(self.password) end end diff --git a/config/initializers/graphql_api.rb b/config/initializers/graphql_api.rb index c68334244..cf7b4bc03 100644 --- a/config/initializers/graphql_api.rb +++ b/config/initializers/graphql_api.rb @@ -4,7 +4,7 @@ module GraphQLApi if ActiveRecord::Base.connection.tables.any? api_config = YAML.load_file("./config/api.yml") GraphqlController.const_set "API_TYPE_DEFINITIONS", - GraphQL::ApiTypesCreator::parse_api_config_file(api_config) + GraphQL::ApiTypesCreator.parse_api_config_file(api_config) end end end diff --git a/config/routes/devise.rb b/config/routes/devise.rb index cb60483e4..cfd281409 100644 --- a/config/routes/devise.rb +++ b/config/routes/devise.rb @@ -18,7 +18,7 @@ end devise_for :organizations, class_name: "User", controllers: { registrations: "organizations/registrations", - sessions: "devise/sessions", + sessions: "devise/sessions" }, skip: [:omniauth_callbacks] diff --git a/db/dev_seeds/polls.rb b/db/dev_seeds/polls.rb index 5a3feb64d..e26c99d7d 100644 --- a/db/dev_seeds/polls.rb +++ b/db/dev_seeds/polls.rb @@ -59,7 +59,7 @@ section "Creating Poll Questions & Answers" do end question.save! Faker::Lorem.words((2..4).to_a.sample).each_with_index do |title, index| - description = "

#{Faker::Lorem.paragraphs.join('

')}

" + description = "

#{Faker::Lorem.paragraphs.join("

")}

" answer = Poll::Question::Answer.new(question: question, title: title.capitalize, description: description, diff --git a/db/migrate/20150820103351_create_inappropiate_flags.rb b/db/migrate/20150820103351_create_inappropiate_flags.rb index 3e69fd15c..265bfdda5 100644 --- a/db/migrate/20150820103351_create_inappropiate_flags.rb +++ b/db/migrate/20150820103351_create_inappropiate_flags.rb @@ -10,6 +10,6 @@ class CreateInappropiateFlags < ActiveRecord::Migration[4.2] end add_index :inappropiate_flags, [:flaggable_type, :flaggable_id] - add_index :inappropiate_flags, [:user_id, :flaggable_type, :flaggable_id], :name => "access_inappropiate_flags" + add_index :inappropiate_flags, [:user_id, :flaggable_type, :flaggable_id], name: "access_inappropiate_flags" end end diff --git a/db/migrate/20180801140800_add_collaborative_legislation_translations.rb b/db/migrate/20180801140800_add_collaborative_legislation_translations.rb index 50fb8fea4..7dc385f77 100644 --- a/db/migrate/20180801140800_add_collaborative_legislation_translations.rb +++ b/db/migrate/20180801140800_add_collaborative_legislation_translations.rb @@ -5,7 +5,7 @@ class AddCollaborativeLegislationTranslations < ActiveRecord::Migration[4.2] title: :string, summary: :text, description: :text, - additional_info: :text, + additional_info: :text }, { migrate_data: true } ) diff --git a/db/migrate/20180924071722_add_translate_pages.rb b/db/migrate/20180924071722_add_translate_pages.rb index f29d34600..987da6eb8 100644 --- a/db/migrate/20180924071722_add_translate_pages.rb +++ b/db/migrate/20180924071722_add_translate_pages.rb @@ -9,11 +9,11 @@ class AddTranslatePages < ActiveRecord::Migration[4.2] { migrate_data: true } ) - change_column :site_customization_pages, :title, :string, :null => true + change_column :site_customization_pages, :title, :string, null: true end def self.down SiteCustomization::Page.drop_translation_table! - change_column :site_customization_pages, :title, :string, :null => false + change_column :site_customization_pages, :title, :string, null: false end end diff --git a/lib/graph_ql/api_types_creator.rb b/lib/graph_ql/api_types_creator.rb index 0fca95f61..823e430a8 100644 --- a/lib/graph_ql/api_types_creator.rb +++ b/lib/graph_ql/api_types_creator.rb @@ -8,7 +8,7 @@ module GraphQL float: GraphQL::FLOAT_TYPE, double: GraphQL::FLOAT_TYPE, string: GraphQL::STRING_TYPE - } + }.freeze def self.create(api_types_definitions) created_types = {} 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 430e38b2e..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 @@ -38,7 +38,7 @@ class RemoteTranslations::Microsoft::AvailableLocales request = Net::HTTP::Get.new(uri) request["Ocp-Apim-Subscription-Key"] = Rails.application.secrets.microsoft_api_key - response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == "https") do |http| + response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end diff --git a/lib/remote_translations/microsoft/client.rb b/lib/remote_translations/microsoft/client.rb index 5c4f33d34..d7e1bc5d9 100644 --- a/lib/remote_translations/microsoft/client.rb +++ b/lib/remote_translations/microsoft/client.rb @@ -3,7 +3,7 @@ include RemoteTranslations::Microsoft::SentencesParser class RemoteTranslations::Microsoft::Client CHARACTERS_LIMIT_PER_REQUEST = 5000 - PREVENTING_TRANSLATION_KEY = "notranslate" + PREVENTING_TRANSLATION_KEY = "notranslate".freeze def initialize api_key = Rails.application.secrets.microsoft_api_key diff --git a/lib/tag_sanitizer.rb b/lib/tag_sanitizer.rb index 4a15ab1b8..eedf1f5af 100644 --- a/lib/tag_sanitizer.rb +++ b/lib/tag_sanitizer.rb @@ -1,5 +1,5 @@ class TagSanitizer - DISALLOWED_STRINGS = %w[? < > = /] + DISALLOWED_STRINGS = %w[? < > = /].freeze def sanitize_tag(tag) tag = tag.dup diff --git a/lib/tasks/proposal_actions.rake b/lib/tasks/proposal_actions.rake index 93fdf8c1b..f3897c7ea 100644 --- a/lib/tasks/proposal_actions.rake +++ b/lib/tasks/proposal_actions.rake @@ -384,7 +384,7 @@ namespace :proposal_actions do 5 ] - votes_count = expected_supports.inject(0.0) { |sum, x| sum + x } + votes_count = expected_supports.reduce(0.0) { |sum, x| sum + x } goal_votes = Setting["votes_for_proposal_success"].to_f cached_votes_up = 0 diff --git a/lib/user_segments.rb b/lib/user_segments.rb index d6bd427fb..bf30f4416 100644 --- a/lib/user_segments.rb +++ b/lib/user_segments.rb @@ -7,7 +7,7 @@ class UserSegments feasible_and_undecided_investment_authors selected_investment_authors winner_investment_authors - not_supported_on_current_budget] + not_supported_on_current_budget].freeze def self.all_users User.active 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/legislations.rb b/spec/factories/legislations.rb index bfb1e7948..22c904ffb 100644 --- a/spec/factories/legislations.rb +++ b/spec/factories/legislations.rb @@ -124,19 +124,19 @@ FactoryBot.define do changelog { "What changed in this version" } status { "draft" } final_version { false } - body { <<-LOREM_IPSUM } -Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + body { <<~LOREM_IPSUM } + Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. -Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. + Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. -His audiam deserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu. + His audiam deserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu. -Est ei erat mucius quaeque. Ei his quas phaedrum, efficiantur mediocritatem ne sed, hinc oratio blandit ei sed. Blandit gloriatur eam et. Brute noluisse per et, verear disputando neglegentur at quo. Sea quem legere ei, unum soluta ne duo. Ludus complectitur quo te, ut vide autem homero pro. + Est ei erat mucius quaeque. Ei his quas phaedrum, efficiantur mediocritatem ne sed, hinc oratio blandit ei sed. Blandit gloriatur eam et. Brute noluisse per et, verear disputando neglegentur at quo. Sea quem legere ei, unum soluta ne duo. Ludus complectitur quo te, ut vide autem homero pro. -Vis id minim dicant sensibus. Pri aliquip conclusionemque ad, ad malis evertitur torquatos his. Has ei solum harum reprimique, id illum saperet tractatos his. Ei omnis soleat antiopam quo. Ad augue inani postulant mel, mel ea qualisque forensibus. + Vis id minim dicant sensibus. Pri aliquip conclusionemque ad, ad malis evertitur torquatos his. Has ei solum harum reprimique, id illum saperet tractatos his. Ei omnis soleat antiopam quo. Ad augue inani postulant mel, mel ea qualisque forensibus. -Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui. Ea sanctus democritum mei, per eu alterum electram adversarium. Ea vix probo dicta iuvaret, posse epicurei suavitate eam an, nam et vidit menandri. Ut his accusata petentium. -LOREM_IPSUM + Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui. Ea sanctus democritum mei, per eu alterum electram adversarium. Ea vix probo dicta iuvaret, posse epicurei suavitate eam an, nam et vidit menandri. Ut his accusata petentium. + LOREM_IPSUM trait :published do status { "published" } 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/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 04d271bd9..4e9eae9af 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -157,7 +157,7 @@ describe "Admin collaborative legislation" do end scenario "Create a legislation process with an image", :js do - visit new_admin_legislation_process_path() + visit new_admin_legislation_process_path fill_in "Process Title", with: "An example legislation process" fill_in "Summary", with: "Summary of the process" diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index b1e5b2463..6200837ae 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -194,13 +194,13 @@ describe "Admin booths assignments" do end within("#recounts_list") do - within("#recounting_#{poll.starts_at.to_date.strftime('%Y%m%d')}") do + within("#recounting_#{poll.starts_at.to_date.strftime("%Y%m%d")}") do expect(page).to have_content 1 end - within("#recounting_#{(poll.ends_at.to_date - 5.days).strftime('%Y%m%d')}") do + within("#recounting_#{(poll.ends_at.to_date - 5.days).strftime("%Y%m%d")}") do expect(page).to have_content "-" end - within("#recounting_#{poll.ends_at.to_date.strftime('%Y%m%d')}") do + within("#recounting_#{poll.ends_at.to_date.strftime("%Y%m%d")}") do expect(page).to have_content 1 end end diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index 901e37383..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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |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").collect { |i| i.text } + all(".budget-investment h3").map(&:text) end end @@ -1038,7 +1038,7 @@ describe "Budget Investments" do visit new_budget_investment_path(budget) - select_options = find("#budget_investment_heading_id").all("option").collect(&:text) + select_options = find("#budget_investment_heading_id").all("option").map(&:text) expect(select_options).to eq ["", "Toda la ciudad", "Health: More health professionals", diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 3c06884b1..9c918f17f 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -142,7 +142,7 @@ describe "Legislation" do phases.each do |phase| within(".legislation-process-list") do - find("li", :text => "#{phase}").click_link + find("li", text: "#{phase}").click_link end expect(page).to have_content(document.title) diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index 6935b31bb..f1e27dedf 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -133,7 +133,7 @@ describe "Legislation Proposals" do end def legislation_proposals_order - all("[id^='legislation_proposal_']").collect { |e| e[:id] } + all("[id^='legislation_proposal_']").map { |e| e[:id] } end scenario "Create a legislation proposal with an image", :js do 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/tracking/budget_investments_spec.rb b/spec/features/tracking/budget_investments_spec.rb index ddf00889e..c33c2e8e6 100644 --- a/spec/features/tracking/budget_investments_spec.rb +++ b/spec/features/tracking/budget_investments_spec.rb @@ -276,8 +276,8 @@ describe "Valuation budget investments" do expect(page).to have_content("Create progress bar") - select("Primary", :from => "Type") - fill_in("Current progress", :with => 50) + select("Primary", from: "Type") + fill_in("Current progress", with: 50) click_button "Create Progress bar" @@ -295,9 +295,9 @@ describe "Valuation budget investments" do expect(page).to have_content("Create progress bar") - select("Secondary", :from => "Type") - fill_in("Title", :with => "secondary_progress_bar") - fill_in("Current progress", :with => 50) + select("Secondary", from: "Type") + fill_in("Title", with: "secondary_progress_bar") + fill_in("Current progress", with: 50) click_button "Create Progress bar" @@ -340,7 +340,7 @@ describe "Valuation budget investments" do page.find("#progress_bar_#{secondary_progress_bar.id}").click_link("Edit") - fill_in("Title", :with => "edited") + fill_in("Title", with: "edited") click_button "Update Progress bar" expect(page).to have_content("Progress bars") 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 f38970f96..1a2efcce8 100644 --- a/spec/lib/graphql_spec.rb +++ b/spec/lib/graphql_spec.rb @@ -23,7 +23,7 @@ end def extract_fields(response, collection_name, field_chain) fields = field_chain.split(".") - dig(response, "data.#{collection_name}.edges").collect do |node| + dig(response, "data.#{collection_name}.edges").map do |node| begin if fields.size > 1 node["node"][fields.first][fields.second] @@ -60,8 +60,8 @@ describe "Consul Schema" do comment_2 = create(:comment, author: comments_author, commentable: proposal) response = execute("{ proposal(id: #{proposal.id}) { comments { edges { node { body } } } } }") - comments = dig(response, "data.proposal.comments.edges").collect { |edge| edge["node"] } - comment_bodies = comments.collect { |comment| comment["body"] } + comments = dig(response, "data.proposal.comments.edges").map { |edge| edge["node"] } + comment_bodies = comments.map { |comment| comment["body"] } expect(comment_bodies).to match_array([comment_1.body, comment_2.body]) end @@ -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") diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index 2bc2dd047..9feb6836b 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -197,9 +197,9 @@ describe Dashboard::Mailer do "among other features and rewards that you will discover. "\ "Dont stop adding support and we will not stop rewarding "\ "and helping you!") - expect(email).to have_body_text("You have #{Setting['months_to_archive_proposals']} months "\ + expect(email).to have_body_text("You have #{Setting["months_to_archive_proposals"]} months "\ "since you publish the proposal to get "\ - "#{Setting['votes_for_proposal_success']} support and your "\ + "#{Setting["votes_for_proposal_success"]} support and your "\ "proposal can become a reality. But the first days are the "\ "most important. It is a challenge. Get ready!") expect(email).to have_body_text("And for you to start with all the motivation,") diff --git a/spec/models/concerns/globalizable.rb b/spec/models/concerns/globalizable.rb index c72de6499..dce50d4af 100644 --- a/spec/models/concerns/globalizable.rb +++ b/spec/models/concerns/globalizable.rb @@ -141,7 +141,7 @@ shared_examples_for "globalizable" do |factory_name| record.translations_attributes = [ { id: record.translations.find_by(locale: :es).id, attribute => "" }, - { id: record.translations.find_by(locale: :en).id, _destroy: true }, + { id: record.translations.find_by(locale: :en).id, _destroy: true } ] expect(record).not_to be_valid diff --git a/spec/models/legislation/draft_version_spec.rb b/spec/models/legislation/draft_version_spec.rb index 33eadb98d..b0416d590 100644 --- a/spec/models/legislation/draft_version_spec.rb +++ b/spec/models/legislation/draft_version_spec.rb @@ -20,64 +20,64 @@ describe Legislation::DraftVersion do end def body_markdown - <<-BODY_MARKDOWN -# Title 1 + <<~BODY_MARKDOWN + # Title 1 -Some paragraph. + Some paragraph. -A list: + A list: -- item 1 -- item 2 + - item 1 + - item 2 -## Subtitle + ## Subtitle -Another paragraph. + Another paragraph. -# Title 2 + # Title 2 -Something about this. -BODY_MARKDOWN + Something about this. + BODY_MARKDOWN end def body_html - <<-BODY_HTML -

Title 1

+ <<~BODY_HTML +

Title 1

-

Some paragraph.

+

Some paragraph.

-

A list:

+

A list:

- + -

Subtitle

+

Subtitle

-

Another paragraph.

+

Another paragraph.

-

Title 2

+

Title 2

-

Something about this.

-BODY_HTML +

Something about this.

+ BODY_HTML end def toc_html - <<-TOC_HTML - -TOC_HTML + <<~TOC_HTML + + TOC_HTML end end diff --git a/spec/models/local_census_records/import_spec.rb b/spec/models/local_census_records/import_spec.rb index 0ca18adce..301c6e16d 100644 --- a/spec/models/local_census_records/import_spec.rb +++ b/spec/models/local_census_records/import_spec.rb @@ -59,7 +59,7 @@ describe LocalCensusRecords::Import do import.save! valid_document_numbers = ["44556678T", "33556678T", "22556678T", "X11556678"] - expect(import.created_records.collect(&:document_number)).to eq(valid_document_numbers) + expect(import.created_records.map(&:document_number)).to eq(valid_document_numbers) end it "Add invalid local census records to invalid_records array" do @@ -74,13 +74,13 @@ describe LocalCensusRecords::Import do invalid_records_date_of_births = [Date.parse("07/08/1984"), Date.parse("07/08/1985"), nil, Date.parse("07/08/1987")] invalid_records_postal_codes = ["7008", "7009", "7010", nil] - expect(import.invalid_records.collect(&:document_type)) + expect(import.invalid_records.map(&:document_type)) .to eq(invalid_records_document_types) - expect(import.invalid_records.collect(&:document_number)) + expect(import.invalid_records.map(&:document_number)) .to eq(invalid_records_document_numbers) - expect(import.invalid_records.collect(&:date_of_birth)) + expect(import.invalid_records.map(&:date_of_birth)) .to eq(invalid_records_date_of_births) - expect(import.invalid_records.collect(&:postal_code)) + expect(import.invalid_records.map(&:postal_code)) .to eq(invalid_records_postal_codes) end end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 3cc07c438..7a2a89ac7 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -128,7 +128,7 @@ describe Proposal do it "has a code" do Setting["proposal_code_prefix"] = "TEST" proposal = create(:proposal) - expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime('%Y-%m')}-#{proposal.id}" + expect(proposal.code).to eq "TEST-#{proposal.created_at.strftime("%Y-%m")}-#{proposal.id}" Setting["proposal_code_prefix"] = "MAD" end diff --git a/spec/shared/features/nested_documentable.rb b/spec/shared/features/nested_documentable.rb index d714e5b4e..679cdfee1 100644 --- a/spec/shared/features/nested_documentable.rb +++ b/spec/shared/features/nested_documentable.rb @@ -308,7 +308,7 @@ def documentable_redirected_to_resource_show_or_navigate_to find("a", text: "Not now, go to my proposal") click_on "Not now, go to my proposal" rescue - return + nil end def documentable_attach_new_file(path, success = true) diff --git a/spec/shared/features/nested_imageable.rb b/spec/shared/features/nested_imageable.rb index b1f3ed0ec..4ea707588 100644 --- a/spec/shared/features/nested_imageable.rb +++ b/spec/shared/features/nested_imageable.rb @@ -254,7 +254,7 @@ def imageable_redirected_to_resource_show_or_navigate_to find("a", text: "Not now, go to my proposal") click_on "Not now, go to my proposal" rescue - return + nil end def imageable_attach_new_file(_imageable_factory_name, path, success = true)