From 0aee5689778fe5dc3b35e1f53007ed40bc6d1ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 3 Oct 2023 19:45:00 +0200 Subject: [PATCH] Add and apply Rails/RedundantActiveRecordAllMethod This rule was introduced in rubocop-rails 2.21.0. --- .rubocop.yml | 3 +++ app/controllers/admin/budget_investments_controller.rb | 2 +- app/controllers/admin/geozones_controller.rb | 2 +- app/controllers/admin/poll/booth_assignments_controller.rb | 2 +- app/controllers/admin/poll/polls_controller.rb | 2 +- app/controllers/admin/signature_sheets_controller.rb | 2 +- app/controllers/admin/valuator_groups_controller.rb | 2 +- app/controllers/concerns/commentable_actions.rb | 2 +- app/helpers/geozones_helper.rb | 2 +- app/models/concerns/statisticable.rb | 2 +- db/dev_seeds/budgets.rb | 2 +- db/dev_seeds/sdg.rb | 2 +- spec/components/shared/banner_component_spec.rb | 2 +- spec/models/poll/booth_assignment_spec.rb | 2 +- spec/models/poll/shift_spec.rb | 4 ++-- spec/models/proposal_notification_spec.rb | 2 +- spec/system/notifications_spec.rb | 2 +- 17 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 90759c3ac..5227398e3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -437,6 +437,9 @@ Rails/PluralizationGrammar: Rails/Presence: Enabled: true +Rails/RedundantActiveRecordAllMethod: + Enabled: true + Rails/RedundantTravelBack: Enabled: true diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 04c3e74df..c4d68ae43 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -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 diff --git a/app/controllers/admin/geozones_controller.rb b/app/controllers/admin/geozones_controller.rb index 794a5985f..a9d2e652c 100644 --- a/app/controllers/admin/geozones_controller.rb +++ b/app/controllers/admin/geozones_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 7d9a462ea..1ad6d28e8 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -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 diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 68ba02a01..3f1d65e55 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -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 diff --git a/app/controllers/admin/signature_sheets_controller.rb b/app/controllers/admin/signature_sheets_controller.rb index cc417f6b8..e75a3ae90 100644 --- a/app/controllers/admin/signature_sheets_controller.rb +++ b/app/controllers/admin/signature_sheets_controller.rb @@ -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 diff --git a/app/controllers/admin/valuator_groups_controller.rb b/app/controllers/admin/valuator_groups_controller.rb index d2b23e60b..461207a41 100644 --- a/app/controllers/admin/valuator_groups_controller.rb +++ b/app/controllers/admin/valuator_groups_controller.rb @@ -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 diff --git a/app/controllers/concerns/commentable_actions.rb b/app/controllers/concerns/commentable_actions.rb index 86ea1dde8..1bd7fcfa5 100644 --- a/app/controllers/concerns/commentable_actions.rb +++ b/app/controllers/concerns/commentable_actions.rb @@ -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 diff --git a/app/helpers/geozones_helper.rb b/app/helpers/geozones_helper.rb index 20831986d..401eb4091 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).map { |g| [g.name, g.id] } + Geozone.order(name: :asc).map { |g| [g.name, g.id] } end end diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 9b32b22b3..5d3c67a07 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -171,7 +171,7 @@ module Statisticable end def geozones - Geozone.all.order("name") + Geozone.order("name") end def geozone_stats diff --git a/db/dev_seeds/budgets.rb b/db/dev_seeds/budgets.rb index b82587473..2aa10f190 100644 --- a/db/dev_seeds/budgets.rb +++ b/db/dev_seeds/budgets.rb @@ -48,7 +48,7 @@ section "Creating Budgets" do end end - Budget.all.find_each do |budget| + Budget.find_each do |budget| city_group = budget.groups.create!( random_locales_attributes(name: -> { I18n.t("seeds.budgets.groups.all_city") }) ) diff --git a/db/dev_seeds/sdg.rb b/db/dev_seeds/sdg.rb index 27558cb5e..5a65c0265 100644 --- a/db/dev_seeds/sdg.rb +++ b/db/dev_seeds/sdg.rb @@ -32,7 +32,7 @@ section "Creating Sustainable Development Goals" do end section "Creating SDG homepage cards" do - SDG::Phase.all.find_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 diff --git a/spec/components/shared/banner_component_spec.rb b/spec/components/shared/banner_component_spec.rb index 2dda4dca8..6d2512373 100644 --- a/spec/components/shared/banner_component_spec.rb +++ b/spec/components/shared/banner_component_spec.rb @@ -75,7 +75,7 @@ describe Shared::BannerComponent do end it "does not render anything with no active banners" do - Banner.all.find_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") diff --git a/spec/models/poll/booth_assignment_spec.rb b/spec/models/poll/booth_assignment_spec.rb index e42e637ad..046f27144 100644 --- a/spec/models/poll/booth_assignment_spec.rb +++ b/spec/models/poll/booth_assignment_spec.rb @@ -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 diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index be7d3f7d5..0b22c6fca 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -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 diff --git a/spec/models/proposal_notification_spec.rb b/spec/models/proposal_notification_spec.rb index 2279ab542..c92773c81 100644 --- a/spec/models/proposal_notification_spec.rb +++ b/spec/models/proposal_notification_spec.rb @@ -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 diff --git a/spec/system/notifications_spec.rb b/spec/system/notifications_spec.rb index 0d23d9b02..379aaed3a 100644 --- a/spec/system/notifications_spec.rb +++ b/spec/system/notifications_spec.rb @@ -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