Add and apply MultilineMethodCallIndentation rule

This commit is contained in:
Javi Martín
2023-07-01 18:08:54 +02:00
parent 629e208e9d
commit 5b6de96241
35 changed files with 131 additions and 110 deletions

View File

@@ -108,6 +108,9 @@ Layout/MultilineHashBraceLayout:
Layout/MultilineHashKeyLineBreaks:
Enabled: true
Layout/MultilineMethodCallIndentation:
Enabled: true
Layout/MultilineOperationIndentation:
Enabled: true

View File

@@ -9,7 +9,9 @@ class Budgets::Executions::ImageComponent < ApplicationComponent
private
def milestone
investment.milestones.order_by_publication_date
.select { |milestone| milestone.image.present? }.last
investment.milestones
.order_by_publication_date
.select { |milestone| milestone.image.present? }
.last
end
end

View File

@@ -8,8 +8,9 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll
load_and_authorize_resource :process, class: "Legislation::Process"
def index
@processes = ::Legislation::Process.send(@current_filter).order(start_date: :desc)
.page(params[:page])
@processes = ::Legislation::Process.send(@current_filter)
.order(start_date: :desc)
.page(params[:page])
end
def create

View File

@@ -5,11 +5,11 @@ class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController
def index
@officers = ::Poll::Officer
.includes(:user)
.order("users.username")
.where(
id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id)
).page(params[:page]).per(50)
.includes(:user)
.order("users.username")
.where(id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id))
.page(params[:page])
.per(50)
end
def by_officer

View File

@@ -4,9 +4,10 @@ class Admin::VerificationsController < Admin::BaseController
end
def search
@users = User.incomplete_verification.search(params[:search])
.page(params[:page])
.for_render
@users = User.incomplete_verification
.search(params[:search])
.page(params[:page])
.for_render
render :index
end
end

View File

@@ -37,11 +37,11 @@ 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)
.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

View File

@@ -10,8 +10,11 @@ class Legislation::ProcessesController < Legislation::BaseController
def index
@current_filter ||= "open"
@processes = ::Legislation::Process.send(@current_filter).published
.not_in_draft.order(start_date: :desc).page(params[:page])
@processes = ::Legislation::Process.send(@current_filter)
.published
.not_in_draft
.order(start_date: :desc)
.page(params[:page])
end
def show

View File

@@ -43,12 +43,12 @@ class Officing::BallotSheetsController < Officing::BaseController
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment
.includes(booth_assignment: [:booth])
.joins(:booth_assignment)
.final
.where(id: current_user.poll_officer.officer_assignment_ids)
.where(poll_booth_assignments: { poll_id: @poll.id })
.where(date: Date.current)
.includes(booth_assignment: [:booth])
.joins(:booth_assignment)
.final
.where(id: current_user.poll_officer.officer_assignment_ids)
.where(poll_booth_assignments: { poll_id: @poll.id })
.where(date: Date.current)
end
def load_officer_assignment

View File

@@ -22,11 +22,11 @@ class Officing::ResultsController < Officing::BaseController
def index
@booth_assignment = ::Poll::BoothAssignment.includes(:booth).find(index_params[:booth_assignment_id])
if current_user.poll_officer.officer_assignments.final
.where(booth_assignment_id: @booth_assignment.id).exists?
.where(booth_assignment_id: @booth_assignment.id).exists?
@partial_results = ::Poll::PartialResult.includes(:question)
.where(booth_assignment_id: index_params[:booth_assignment_id])
.where(date: index_params[:date])
.where(booth_assignment_id: index_params[:booth_assignment_id])
.where(date: index_params[:date])
@recounts = ::Poll::Recount.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date])
end
end
@@ -90,17 +90,17 @@ class Officing::ResultsController < Officing::BaseController
def load_officer_assignment
@officer_assignment = current_user.poll_officer
.officer_assignments.final.find_by(id: results_params[:officer_assignment_id])
.officer_assignments.final.find_by(id: results_params[:officer_assignment_id])
end
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment
.includes(booth_assignment: [:booth])
.joins(:booth_assignment)
.final
.where(id: current_user.poll_officer.officer_assignment_ids)
.where(poll_booth_assignments: { poll_id: @poll.id })
.where(date: Date.current)
.includes(booth_assignment: [:booth])
.joins(:booth_assignment)
.final
.where(id: current_user.poll_officer.officer_assignment_ids)
.where(poll_booth_assignments: { poll_id: @poll.id })
.where(date: Date.current)
end
def load_partial_results

View File

@@ -155,8 +155,10 @@ class ProposalsController < ApplicationController
return unless !@advanced_search_terms && @search_terms.blank? && params[:retired].blank? && @current_order != "recommendations"
if Setting["feature.featured_proposals"]
@featured_proposals = Proposal.not_archived.unsuccessful
.sort_by_confidence_score.limit(Setting["featured_proposals_number"])
@featured_proposals = Proposal.not_archived
.unsuccessful
.sort_by_confidence_score
.limit(Setting["featured_proposals_number"])
if @featured_proposals.present?
@resources = @resources.where.not(id: @featured_proposals)
end

View File

@@ -23,7 +23,7 @@ module AdminBudgetInvestmentsHelper
def valuator_select_options(budget)
budget.valuators.order("description ASC").order("users.email ASC").includes(:user)
.map { |v| [v.description_or_email, "valuator_#{v.id}"] }
.map { |v| [v.description_or_email, "valuator_#{v.id}"] }
end
def valuator_group_select_options

View File

@@ -48,7 +48,7 @@ module ApplicationHelper
def self.asset_data_base64(path)
asset = (Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application))
.find_asset(path)
.find_asset(path)
throw "Could not find asset '#{path}'" if asset.nil?
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
"data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"

View File

@@ -11,8 +11,8 @@ class Budget
def name_uniqueness_by_budget
if budget.groups.joins(:translations)
.where(name: name)
.where.not("budget_group_translations.budget_group_id": budget_group_id).any?
.where(name: name)
.where.not("budget_group_translations.budget_group_id": budget_group_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end

View File

@@ -199,7 +199,7 @@ class Budget
with_joins = with_translations(Globalize.fallbacks(I18n.locale))
with_joins.where(id: title_or_id)
.or(with_joins.where("budget_investment_translations.title ILIKE ?", "%#{title_or_id}%"))
.or(with_joins.where("budget_investment_translations.title ILIKE ?", "%#{title_or_id}%"))
end
def searchable_values

View File

@@ -129,8 +129,8 @@ class Budget::Stats
def balloters_by_heading(heading_id)
stats_cache("balloters_by_heading_#{heading_id}") do
budget.ballots.joins(:lines)
.where(budget_ballot_lines: { heading_id: heading_id })
.distinct.pluck(:user_id)
.where(budget_ballot_lines: { heading_id: heading_id })
.distinct.pluck(:user_id)
end
end

View File

@@ -110,10 +110,10 @@ module Globalizable
end.join(", ")
translations_ids = translation_class
.select("DISTINCT ON (#{translations_foreign_key}) id")
.where(locale: fallbacks)
.joins("LEFT JOIN (VALUES #{fallbacks_with_order}) AS locales(name, ordering) ON locale = locales.name")
.order(translations_foreign_key, "locales.ordering")
.select("DISTINCT ON (#{translations_foreign_key}) id")
.where(locale: fallbacks)
.joins("LEFT JOIN (VALUES #{fallbacks_with_order}) AS locales(name, ordering) ON locale = locales.name")
.order(translations_foreign_key, "locales.ordering")
with_translations(fallbacks).where("#{translations_table_name}.id": translations_ids)
end

View File

@@ -108,9 +108,10 @@ class Dashboard::Action < ApplicationRecord
end
def self.calculate_actions(proposal_votes, day_offset, proposal)
Dashboard::Action.active.where("required_supports <= ?", proposal_votes)
.where("day_offset <= ?", day_offset)
.by_published_proposal(proposal.published?)
Dashboard::Action.active
.where("required_supports <= ?", proposal_votes)
.where("day_offset <= ?", day_offset)
.by_published_proposal(proposal.published?)
end
def self.calculate_votes(proposal, date)

View File

@@ -104,7 +104,7 @@ class Poll < ApplicationRecord
return none if user.nil? || user.unverified?
current.left_joins(:geozones)
.where("geozone_restricted = ? OR geozones.id = ?", false, user.geozone_id)
.where("geozone_restricted = ? OR geozones.id = ?", false, user.geozone_id)
end
def self.votable_by(user)

View File

@@ -16,17 +16,19 @@ class Poll
end
def voting_days_assigned_polls
officer_assignments.voting_days.includes(booth_assignment: :poll)
.map(&:booth_assignment)
.map(&:poll).uniq.compact
.sort { |x, y| y.ends_at <=> x.ends_at }
officer_assignments.voting_days
.includes(booth_assignment: :poll)
.map(&:booth_assignment)
.map(&:poll).uniq.compact
.sort { |x, y| y.ends_at <=> x.ends_at }
end
def final_days_assigned_polls
officer_assignments.final.includes(booth_assignment: :poll)
.map(&:booth_assignment)
.map(&:poll).uniq.compact
.sort { |x, y| y.ends_at <=> x.ends_at }
officer_assignments.final
.includes(booth_assignment: :poll)
.map(&:booth_assignment)
.map(&:poll).uniq.compact
.sort { |x, y| y.ends_at <=> x.ends_at }
end
def todays_booths

View File

@@ -8,10 +8,10 @@ class TagCloud
def tags
resource_model_scoped
.last_week.send(counts)
.where("lower(name) NOT IN (?)", category_names + geozone_names + default_blacklist)
.order("#{table_name}_count": :desc, name: :asc)
.limit(10)
.last_week.send(counts)
.where("lower(name) NOT IN (?)", category_names + geozone_names + default_blacklist)
.order("#{table_name}_count": :desc, name: :asc)
.limit(10)
end
def counts

View File

@@ -3,7 +3,7 @@ class Verification::Management::ManagedUser
def self.find(document_type, document_number)
User.where.not(document_number: nil)
.find_or_initialize_by(document_type: document_type,
document_number: document_number)
.find_or_initialize_by(document_type: document_type,
document_number: document_number)
end
end

View File

@@ -1,5 +1,8 @@
<% annotation.comments.roots.sort_by_most_voted
.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE).each do |comment| %>
<% annotation.comments
.roots
.sort_by_most_voted
.limit(Legislation::Annotation::COMMENTS_PAGE_SIZE)
.each do |comment| %>
<div class="comment">
<div class="comment-text">
<p><%= truncate comment.body, length: 250 %></p>

View File

@@ -22,7 +22,7 @@ FactoryBot.define do
factory :sdg_review, class: "SDG::Review" do
SDG::Related::RELATABLE_TYPES.map { |relatable_type| relatable_type.downcase.gsub("::", "_") }
.each do |relatable|
.each do |relatable|
trait :"#{relatable}_review" do
association :relatable, factory: relatable
end

View File

@@ -221,7 +221,7 @@ describe RemoteTranslations::Caller, :remote_translations do
fake_response = ["translated title", "translated description", "translated summary", nil]
expect_any_instance_of(client).to receive(:call).with(field_values_sanitized, locale)
.and_return(fake_response)
.and_return(fake_response)
caller.call
end

View File

@@ -62,13 +62,13 @@ describe RemoteTranslations::Microsoft::Client do
response_end_text = [end_translated_text_es]
expect_any_instance_of(BingTranslator).to receive(:translate_array).with([start_text_en], to: :es)
.exactly(1)
.times
.and_return(response_start_text)
.exactly(1)
.times
.and_return(response_start_text)
expect_any_instance_of(BingTranslator).to receive(:translate_array).with([end_text_en], to: :es)
.exactly(1)
.times
.and_return(response_end_text)
.exactly(1)
.times
.and_return(response_end_text)
start_another_text_en = Faker::Lorem.characters(number: 12) + "."
end_another_text_en = Faker::Lorem.characters(number: 12)
@@ -81,13 +81,13 @@ describe RemoteTranslations::Microsoft::Client do
response_another_end_text = [another_end_translated_text_es]
expect_any_instance_of(BingTranslator).to receive(:translate_array).with([start_another_text_en], to: :es)
.exactly(1)
.times
.and_return(response_another_start_text)
.exactly(1)
.times
.and_return(response_another_start_text)
expect_any_instance_of(BingTranslator).to receive(:translate_array).with([end_another_text_en], to: :es)
.exactly(1)
.times
.and_return(response_another_end_text)
.exactly(1)
.times
.and_return(response_another_end_text)
result = client.call([text_en, another_text_en], :es)

View File

@@ -101,23 +101,23 @@ describe Comment do
it "expires cache when the author is hidden" do
expect { comment.user.hide }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
end
it "expires cache when the author is erased" do
expect { comment.user.erase }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
end
it "expires cache when the author changes" do
expect { comment.user.update(username: "Isabel") }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
end
it "expires cache when the author's organization get verified" do
create(:organization, user: comment.user)
expect { comment.user.organization.verify }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
.to change { [comment.reload.cache_version, comment.author.cache_version] }
end
end

View File

@@ -376,23 +376,23 @@ describe Debate do
it "expires cache when the author is hidden" do
expect { debate.author.hide }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
end
it "expires cache when the author is erased" do
expect { debate.author.erase }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
end
it "expires cache when its author changes" do
expect { debate.author.update(username: "Eva") }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
end
it "expires cache when the author's organization get verified" do
create(:organization, user: debate.author)
expect { debate.author.organization.verify }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
.to change { [debate.reload.cache_version, debate.author.cache_version] }
end
end

View File

@@ -181,7 +181,7 @@ describe Legislation::Process do
debate_end_date: Date.current - 1.day)
expect(process).to be_invalid
expect(process.errors.messages[:debate_end_date])
.to include("must be on or after the debate start date")
.to include("must be on or after the debate start date")
end
it "is valid if draft_end_date is the same as draft_start_date" do
@@ -195,7 +195,7 @@ describe Legislation::Process do
draft_end_date: Date.current - 1.day)
expect(process).to be_invalid
expect(process.errors.messages[:draft_end_date])
.to include("must be on or after the draft start date")
.to include("must be on or after the draft start date")
end
it "is invalid if allegations_end_date is before allegations_start_date" do
@@ -203,7 +203,7 @@ describe Legislation::Process do
allegations_end_date: Date.current - 1.day)
expect(process).to be_invalid
expect(process.errors.messages[:allegations_end_date])
.to include("must be on or after the comments start date")
.to include("must be on or after the comments start date")
end
it "is valid if allegations_end_date is the same as allegations_start_date" do

View File

@@ -81,7 +81,7 @@ describe LocalCensusRecords::Import do
expect(import.invalid_records.map(&:date_of_birth))
.to eq(invalid_records_date_of_births)
expect(import.invalid_records.map(&:postal_code))
.to eq(invalid_records_postal_codes)
.to eq(invalid_records_postal_codes)
end
end
end

View File

@@ -427,23 +427,23 @@ describe Proposal do
it "expires cache when the author is hidden" do
expect { proposal.author.hide }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end
it "expires cache when the author is erased" do
expect { proposal.author.erase }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end
it "expires cache when its author changes" do
expect { proposal.author.update(username: "Eva") }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end
it "expires cache when the author's organization get verified" do
create(:organization, user: proposal.author)
expect { proposal.author.organization.verify }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
.to change { [proposal.reload.cache_version, proposal.author.cache_version] }
end
end

View File

@@ -10,8 +10,9 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
before do
Setting["feature.remote_translations"] = true
available_locales_response = %w[de en es fr pt zh-Hans]
expect(RemoteTranslations::Microsoft::AvailableLocales).to receive(:available_locales).at_most(4).times
.and_return(available_locales_response)
expect(RemoteTranslations::Microsoft::AvailableLocales)
.to receive(:available_locales).at_most(4).times
.and_return(available_locales_response)
allow(Rails.application.secrets).to receive(:microsoft_api_key).and_return("123")
end

View File

@@ -36,7 +36,7 @@ module CommonActions
def validate_officer
allow_any_instance_of(Officing::BaseController)
.to receive(:verify_officer_assignment).and_return(true)
.to receive(:verify_officer_assignment).and_return(true)
end
def fill_in_proposal
@@ -70,7 +70,7 @@ module CommonActions
booth = create(:poll_booth) if booth.blank?
allow_any_instance_of(Officing::BaseController)
.to receive(:current_booth).and_return(booth)
.to receive(:current_booth).and_return(booth)
end
def click_sdg_goal(code)

View File

@@ -56,7 +56,7 @@ describe "Admin custom information texts", :admin do
within("#information-texts-tabs") { click_link "Proposals" }
expect(find("a[href=\"/admin/site_customization/information_texts?tab=proposals\"].is-active"))
.to have_content "Proposals"
.to have_content "Proposals"
end
context "Globalization" do

View File

@@ -149,7 +149,7 @@ describe "Votes" do
participation = find(".participation-not-allowed")
headings = participation.text
.match(/You have already supported investments in (.+) and (.+)\./)&.captures
.match(/You have already supported investments in (.+) and (.+)\./)&.captures
expect(headings).to match_array [new_york.name, san_francisco.name]
@@ -183,7 +183,7 @@ describe "Votes" do
participation = find(".participation-not-allowed")
headings = participation.text
.match(/You have already supported investments in (.+) and (.+)\./)&.captures
.match(/You have already supported investments in (.+) and (.+)\./)&.captures
expect(headings).to match_array [new_york.name, san_francisco.name]

View File

@@ -32,8 +32,9 @@ describe "DocumentVerifications" do
describe "Verifying througth Census" do
context "Census API" do
scenario "Verifying a user which does not exist and is not in the census shows an error" do
expect_any_instance_of(Verification::Management::Document).to receive(:in_census?)
.and_return(false)
expect_any_instance_of(Verification::Management::Document)
.to receive(:in_census?)
.and_return(false)
login_as_manager
visit management_document_verifications_path
@@ -55,8 +56,9 @@ describe "DocumentVerifications" do
context "Remote Census API", :remote_census do
scenario "Verifying a user which does not exist and is not in the census shows an error" do
expect_any_instance_of(Verification::Management::Document).to receive(:in_census?)
.and_return(false)
expect_any_instance_of(Verification::Management::Document)
.to receive(:in_census?)
.and_return(false)
login_as_manager
visit management_document_verifications_path