From 18869979db93636abc3035ec04aacec25f7c8a69 Mon Sep 17 00:00:00 2001 From: David Thomas Date: Thu, 26 Feb 2026 15:34:45 -0500 Subject: [PATCH] Safely autocorrect Rails/Presence Inspecting 1721 files ...................................C.................................................................................................................................................................................................................................................................................................................................................C................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... Offenses: app/controllers/admin/enterprises_controller.rb:180:7: C: [Corrected] Rails/Presence: Use @object.custom_tab.presence&.destroy instead of @object.custom_tab.destroy if @object.custom_tab.present?. @object.custom_tab.destroy if @object.custom_tab.present? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/controllers/admin/enterprises_controller.rb:243:9: C: [Corrected] Rails/Presence: Use (enterprises.presence&.includes(supplied_products: [:variants, :image])) instead of if enterprises.present? ... end. if enterprises.present? ... ^^^^^^^^^^^^^^^^^^^^^^^ app/controllers/admin/enterprises_controller.rb:243:9: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call. (enterprises.presence&.includes(supplied_products: [:variants, :image])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/product.rb:298:7: C: [Corrected] Rails/Presence: Use (first_variant.supplier.presence&.touch) instead of first_variant.supplier.touch if first_variant.supplier.present?. first_variant.supplier.touch if first_variant.supplier.present? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ app/models/spree/product.rb:298:7: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call. (first_variant.supplier.presence&.touch) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1721 files inspected, 5 offenses detected, 5 offenses corrected --- .rubocop_todo.yml | 7 ------- app/controllers/admin/enterprises_controller.rb | 6 ++---- app/models/spree/product.rb | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e2d6ddbe75..e41f3f6231 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -335,13 +335,6 @@ Rails/OrderArguments: - 'spec/services/orders/generate_invoice_service_spec.rb' - 'spec/system/admin/order_cycles/simple_spec.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -Rails/Presence: - Exclude: - - 'app/controllers/admin/enterprises_controller.rb' - - 'app/models/spree/product.rb' - # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). Rails/RedirectBackOrTo: diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index de96364445..5d13ec0883 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -177,7 +177,7 @@ module Admin protected def delete_custom_tab - @object.custom_tab.destroy if @object.custom_tab.present? + @object.custom_tab.presence&.destroy enterprise_params.delete(:custom_tab_attributes) end @@ -240,9 +240,7 @@ module Admin enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle) .visible_enterprises - if enterprises.present? - enterprises.includes(supplied_products: [:variants, :image]) - end + enterprises.presence&.includes(supplied_products: [:variants, :image]) when :index if spree_current_user.admin? OpenFoodNetwork::Permissions.new(spree_current_user). diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index e077af407b..f3cf46aeda 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -295,7 +295,7 @@ module Spree # The variant is invalid if no supplier is present, but this method can be triggered when # importing product. In this scenario the variant has not been updated with the supplier yet # hence the check. - first_variant.supplier.touch if first_variant.supplier.present? + first_variant.supplier.presence&.touch end def validate_image