Merge pull request #5271 from consuldemocracy/dependabot/bundler/rubocop-rails-2.21.2

Bump rubocop-rails from 2.20.2 to 2.21.2
This commit is contained in:
Javi Martín
2023-11-20 17:54:30 +01:00
committed by GitHub
32 changed files with 83 additions and 72 deletions

View File

@@ -38,5 +38,9 @@ linters:
Enabled: false
Lint/UselessAssignment:
Enabled: false
Rails/HttpStatus:
Enabled: true
Exclude:
- app/views/dashboard/*
Rails/OutputSafety:
Enabled: false

View File

@@ -443,6 +443,9 @@ Rails/PluralizationGrammar:
Rails/Presence:
Enabled: true
Rails/RedundantActiveRecordAllMethod:
Enabled: true
Rails/RedundantTravelBack:
Enabled: true
@@ -466,6 +469,9 @@ Rails/SaveBang:
Enabled: true
Severity: refactor
Rails/SelectMap:
Enabled: true
Rails/SkipsModelValidations:
Enabled: true
ForbiddenMethods:
@@ -689,6 +695,7 @@ Style/InvertibleUnlessCondition:
Enabled: true
InverseMethods:
:blank?: :present?
:include?: ~
:present?: :blank?
:zero?: ~

View File

@@ -109,7 +109,7 @@ group :development do
gem "rubocop-capybara", "~> 2.19.0", require: false
gem "rubocop-factory_bot", "~> 2.24.0", require: false
gem "rubocop-performance", "~> 1.19.1", require: false
gem "rubocop-rails", "~> 2.20.2", require: false
gem "rubocop-rails", "~> 2.21.2", require: false
gem "rubocop-rspec", "~> 2.24.1", require: false
gem "rvm1-capistrano3", "~> 1.4.0", require: false
gem "scss_lint", "~> 0.60.0", require: false

View File

@@ -536,7 +536,7 @@ GEM
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.20.2)
rubocop-rails (2.21.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
@@ -754,7 +754,7 @@ DEPENDENCIES
rubocop-capybara (~> 2.19.0)
rubocop-factory_bot (~> 2.24.0)
rubocop-performance (~> 1.19.1)
rubocop-rails (~> 2.20.2)
rubocop-rails (~> 2.21.2)
rubocop-rspec (~> 2.24.1)
rvm1-capistrano3 (~> 1.4.0)
sassc-rails (~> 2.1.2)

View File

@@ -115,7 +115,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def load_valuator_groups
@valuator_groups = ValuatorGroup.all.order(name: :asc)
@valuator_groups = ValuatorGroup.order(name: :asc)
end
def load_tags

View File

@@ -4,7 +4,7 @@ class Admin::GeozonesController < Admin::BaseController
load_and_authorize_resource
def index
@geozones = Geozone.all.order(Arel.sql("LOWER(name)"))
@geozones = Geozone.order(Arel.sql("LOWER(name)"))
end
def new

View File

@@ -46,7 +46,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController
end
def manage
@booths = ::Poll::Booth.all.order(name: :asc).page(params[:page]).per(300)
@booths = ::Poll::Booth.order(name: :asc).page(params[:page]).per(300)
@poll = Poll.find(params[:poll_id])
end

View File

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

View File

@@ -59,7 +59,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController
private
def load_geozones
@geozones = Geozone.all.order(:name)
@geozones = Geozone.order(:name)
end
def poll_params

View File

@@ -1,6 +1,6 @@
class Admin::SignatureSheetsController < Admin::BaseController
def index
@signature_sheets = SignatureSheet.all.order(created_at: :desc)
@signature_sheets = SignatureSheet.order(created_at: :desc)
end
def new

View File

@@ -1,6 +1,6 @@
class Admin::ValuatorGroupsController < Admin::BaseController
def index
@groups = ValuatorGroup.all.page(params[:page])
@groups = ValuatorGroup.page(params[:page])
end
def show

View File

@@ -83,7 +83,7 @@ module CommentableActions
end
def load_geozones
@geozones = Geozone.all.order(name: :asc)
@geozones = Geozone.order(name: :asc)
end
def set_geozone

View File

@@ -4,6 +4,6 @@ module GeozonesHelper
end
def geozone_select_options
Geozone.all.order(name: :asc).map { |g| [g.name, g.id] }
Geozone.order(name: :asc).map { |g| [g.name, g.id] }
end
end

View File

@@ -171,7 +171,7 @@ module Statisticable
end
def geozones
Geozone.all.order("name")
Geozone.order("name")
end
def geozone_stats

View File

@@ -48,7 +48,7 @@ section "Creating Budgets" do
end
end
Budget.all.each do |budget|
Budget.find_each do |budget|
city_group = budget.groups.create!(
random_locales_attributes(name: -> { I18n.t("seeds.budgets.groups.all_city") })
)
@@ -94,7 +94,7 @@ end
section "Creating Investments" do
tags = Faker::Lorem.words(number: 10)
100.times do
heading = Budget::Heading.all.sample
heading = Budget::Heading.sample
translation_attributes = random_locales.each_with_object({}) do |locale, attributes|
attributes["title_#{locale.to_s.underscore}"] = "Title for locale #{locale}"
@@ -102,7 +102,7 @@ section "Creating Investments" do
end
investment = Budget::Investment.create!({
author: User.all.sample,
author: User.sample,
heading: heading,
group: heading.group,
budget: heading.group.budget,
@@ -145,9 +145,9 @@ end
section "Winner Investments" do
budget = Budget.finished.first
50.times do
heading = budget.headings.all.sample
heading = budget.headings.sample
investment = Budget::Investment.create!(
author: User.all.sample,
author: User.sample,
heading: heading,
group: heading.group,
budget: heading.group.budget,
@@ -169,6 +169,6 @@ end
section "Creating Valuation Assignments" do
(1..50).to_a.sample.times do
Budget::Investment.all.sample.valuators << Valuator.first
Budget::Investment.sample.valuators << Valuator.first
end
end

View File

@@ -1,8 +1,8 @@
section "Commenting Investments, Debates & Proposals" do
%w[Budget::Investment Debate Proposal].each do |commentable_class|
100.times do
commentable = commentable_class.constantize.all.sample
Comment.create!(user: User.all.sample,
commentable = commentable_class.constantize.sample
Comment.create!(user: User.sample,
created_at: rand(commentable.created_at..Time.current),
commentable: commentable,
body: Faker::Lorem.sentence)
@@ -12,8 +12,8 @@ end
section "Commenting Comments" do
200.times do
parent = Comment.all.sample
Comment.create!(user: User.all.sample,
parent = Comment.sample
Comment.create!(user: User.sample,
created_at: rand(parent.created_at..Time.current),
commentable_id: parent.commentable_id,
commentable_type: parent.commentable_type,

View File

@@ -5,15 +5,15 @@ end
section "Creating Communities Topics" do
Community.find_each do |community|
Topic.create(community: community, author: User.all.sample,
Topic.create(community: community, author: User.sample,
title: Faker::Lorem.sentence(word_count: 3).truncate(60), description: Faker::Lorem.sentence)
end
end
section "Commenting Community Topics" do
30.times do
author = User.all.sample
topic = Topic.all.sample
author = User.sample
topic = Topic.sample
Comment.create!(user: author,
created_at: rand(topic.created_at..Time.current),
commentable: topic,

View File

@@ -1,14 +1,14 @@
section "Creating Debates" do
tags = Faker::Lorem.words(number: 25)
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do
@@ -21,7 +21,7 @@ section "Creating Debates" do
tags = Tag.where(kind: "category")
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
debate = Debate.create!(author: author,
@@ -29,7 +29,7 @@ section "Creating Debates" do
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do

View File

@@ -1,19 +1,19 @@
section "Flagging Debates & Comments" do
40.times do
debate = Debate.all.sample
flagger = User.where.not(id: debate.author_id).all.sample
debate = Debate.sample
flagger = User.where.not(id: debate.author_id).sample
Flag.flag(flagger, debate)
end
40.times do
comment = Comment.all.sample
flagger = User.where.not(id: comment.user_id).all.sample
comment = Comment.sample
flagger = User.where.not(id: comment.user_id).sample
Flag.flag(flagger, comment)
end
40.times do
proposal = Proposal.all.sample
flagger = User.where.not(id: proposal.author_id).all.sample
proposal = Proposal.sample
flagger = User.where.not(id: proposal.author_id).sample
Flag.flag(flagger, proposal)
end
end

View File

@@ -3,8 +3,8 @@ section "Creating legislation proposals" do
Legislation::Proposal.create!(title: Faker::Lorem.sentence(word_count: 3).truncate(60),
description: Faker::Lorem.paragraphs.join("\n\n"),
summary: Faker::Lorem.paragraph,
author: User.all.sample,
process: Legislation::Process.all.sample,
author: User.sample,
process: Legislation::Process.sample,
terms_of_service: "1",
selected: rand <= 1.0 / 3)
end

View File

@@ -11,7 +11,7 @@ section "Creating investment milestones" do
rand(1..5).times do
milestone = record.milestones.build(
publication_date: Date.tomorrow,
status_id: Milestone::Status.all.sample
status_id: Milestone::Status.sample
)
random_locales.map do |locale|

View File

@@ -56,7 +56,7 @@ section "Creating Poll Questions & Answers" do
Poll.find_each do |poll|
(3..5).to_a.sample.times do
question_title = Faker::Lorem.sentence(word_count: 3).truncate(60) + "?"
question = Poll::Question.new(author: User.all.sample,
question = Poll::Question.new(author: User.sample,
title: question_title,
poll: poll)
I18n.available_locales.map do |locale|
@@ -96,13 +96,13 @@ section "Creating Poll Booths & BoothAssignments" do
20.times do |i|
Poll::Booth.create(name: "Booth #{i}",
location: Faker::Address.street_address,
polls: [Poll.all.sample])
polls: [Poll.sample])
end
end
section "Creating Poll Shifts for Poll Officers" do
Poll.find_each do |poll|
Poll::BoothAssignment.where(poll: poll).each do |booth_assignment|
Poll::BoothAssignment.where(poll: poll).find_each do |booth_assignment|
scrutiny = (poll.ends_at.to_datetime..poll.ends_at.to_datetime + Poll::RECOUNT_DURATION)
Poll::Officer.find_each do |poll_officer|
{
@@ -125,8 +125,8 @@ end
section "Commenting Polls" do
30.times do
author = User.all.sample
poll = Poll.all.sample
author = User.sample
poll = Poll.sample
Comment.create!(user: author,
created_at: rand(poll.created_at..Time.current),
commentable: poll,
@@ -136,7 +136,7 @@ end
section "Creating Poll Voters" do
def vote_poll_on_booth(user, poll)
officer = Poll::Officer.all.sample
officer = Poll::Officer.sample
Poll::Voter.create!(document_type: user.document_type,
document_number: user.document_number,
@@ -230,7 +230,7 @@ end
section "Creating Poll Questions from Proposals" do
3.times do
proposal = Proposal.all.sample
proposal = Proposal.sample
poll = Poll.current.first
question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)
@@ -260,7 +260,7 @@ end
section "Creating Successful Proposals" do
10.times do
proposal = Proposal.all.sample
proposal = Proposal.sample
poll = Poll.current.first
question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)

View File

@@ -19,7 +19,7 @@ section "Creating Proposals" do
30.times do
title = Faker::Lorem.sentence(word_count: 3).truncate(60)
summary = Faker::Lorem.sentence(word_count: 3)
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
@@ -29,7 +29,7 @@ section "Creating Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
@@ -47,7 +47,7 @@ end
section "Creating Archived Proposals" do
tags = Faker::Lorem.words(number: 25)
5.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
@@ -55,7 +55,7 @@ section "Creating Archived Proposals" do
responsible_name: Faker::Name.name,
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
created_at: Setting.archived_proposals_date_limit,
published_at: Setting.archived_proposals_date_limit)
@@ -74,7 +74,7 @@ end
section "Creating Successful Proposals" do
tags = Faker::Lorem.words(number: 25)
10.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
@@ -83,7 +83,7 @@ section "Creating Successful Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
cached_votes_up: Setting["votes_for_proposal_success"],
published_at: Time.current)
@@ -100,7 +100,7 @@ section "Creating Successful Proposals" do
tags = Tag.where(kind: "category")
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 4).truncate(60),
@@ -109,7 +109,7 @@ section "Creating Successful Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
@@ -128,7 +128,7 @@ section "Creating proposal notifications" do
100.times do |i|
ProposalNotification.create!(title: "Proposal notification title #{i}",
body: "Proposal notification body #{i}",
author: User.all.sample,
proposal: Proposal.all.sample)
author: User.sample,
proposal: Proposal.sample)
end
end

View File

@@ -32,7 +32,7 @@ section "Creating Sustainable Development Goals" do
end
section "Creating SDG homepage cards" do
SDG::Phase.all.each do |phase|
SDG::Phase.find_each do |phase|
Widget::Card.create!(cardable: phase, title: "#{phase.title} card",
link_text: "Link Text", link_url: "/any_path")
end

View File

@@ -110,7 +110,7 @@ section "Creating Users" do
confirmed_phone: Faker::PhoneNumber.phone_number,
document_number: unique_document_number,
document_type: "1",
geozone: Geozone.all.sample)
geozone: Geozone.sample)
end
if level == 3
user.update(verified_at: Time.current, document_number: unique_document_number)

View File

@@ -1,22 +1,22 @@
section "Voting Debates, Proposals & Comments" do
not_org_users = User.where.not(id: User.organizations)
100.times do
voter = not_org_users.level_two_or_three_verified.all.sample
voter = not_org_users.level_two_or_three_verified.sample
vote = [true, false].sample
debate = Debate.all.sample
debate = Debate.sample
debate.vote_by(voter: voter, vote: vote)
end
100.times do
voter = not_org_users.all.sample
voter = not_org_users.sample
vote = [true, false].sample
comment = Comment.all.sample
comment = Comment.sample
comment.vote_by(voter: voter, vote: vote)
end
100.times do
voter = not_org_users.level_two_or_three_verified.all.sample
proposal = Proposal.all.sample
voter = not_org_users.level_two_or_three_verified.sample
proposal = Proposal.sample
proposal.vote_by(voter: voter, vote: true)
end
end

View File

@@ -63,7 +63,7 @@ module ActsAsParanoidAliases
def restore_all(ids)
return if ids.blank?
only_hidden.where(id: ids).each(&:restore)
only_hidden.where(id: ids).find_each(&:restore)
end
end
end

View File

@@ -75,7 +75,7 @@ describe Shared::BannerComponent do
end
it "does not render anything with no active banners" do
Banner.all.each { |banner| banner.update!(post_ended_at: Date.current - 1.day) }
Banner.find_each { |banner| banner.update!(post_ended_at: Date.current - 1.day) }
render_inline Shared::BannerComponent.new("debates")

View File

@@ -24,6 +24,6 @@ describe Poll::BoothAssignment do
assignment.destroy!
expect(Poll::Shift.all.count).to eq(0)
expect(Poll::Shift.count).to eq 0
end
end

View File

@@ -71,7 +71,7 @@ describe Poll::Shift do
expect do
create(:poll_shift, booth: booth, officer: officer, date: Date.current)
end.to change { Poll::OfficerAssignment.all.count }.by(2)
end.to change { Poll::OfficerAssignment.count }.by(2)
officer_assignments = Poll::OfficerAssignment.all
oa1 = officer_assignments.first
@@ -91,7 +91,7 @@ describe Poll::Shift do
booth_assignment: booth_assignment1,
date: Date.tomorrow)
expect { Poll::Shift.last.destroy }.to change { Poll::OfficerAssignment.all.count }.by(-2)
expect { Poll::Shift.last.destroy }.to change { Poll::OfficerAssignment.count }.by(-2)
end
it "creates final officer_assignments" do

View File

@@ -167,7 +167,7 @@ describe ProposalNotification do
it "removes all notifications related to the proposal notification" do
proposal_notification.moderate_system_email(admin.user)
expect(Notification.all.count).to be(0)
expect(Notification.count).to be 0
end
it "records the moderation action in the Activity table" do

View File

@@ -241,7 +241,7 @@ describe "Notifications" do
end
def users_without_notifications
User.all.select do |user|
User.select do |user|
user.notifications.not_emailed.where(notifiable_type: "ProposalNotification").blank?
end
end