From bea1caa95220b4e3dffd11f00eb6fb158cee0b97 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 8 Feb 2024 11:05:06 +0100 Subject: [PATCH 1/4] Fix safe Rubocop offenses Fixed with rubocop -a --- core/app/models/spree/order.rb | 2 +- core/app/models/spree/promotion_handler/coupon.rb | 2 +- core/lib/spree/money.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb index 781fee27007..aa51dee3f61 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -630,7 +630,7 @@ def total_applicable_store_credit if can_complete? || complete? valid_store_credit_payments.to_a.sum(&:amount) else - [total, (user.try(:available_store_credit_total, currency: currency) || 0.0)].min + [total, user.try(:available_store_credit_total, currency: currency) || 0.0].min end end diff --git a/core/app/models/spree/promotion_handler/coupon.rb b/core/app/models/spree/promotion_handler/coupon.rb index 9e0e4673404..b5556601f83 100644 --- a/core/app/models/spree/promotion_handler/coupon.rb +++ b/core/app/models/spree/promotion_handler/coupon.rb @@ -73,7 +73,7 @@ def handle_present_promotion(promotion) unless promotion.eligible?(order, promotion_code: promotion_code) set_promotion_eligibility_error_code(promotion) - return (error || ineligible_for_this_order) + return error || ineligible_for_this_order end # If any of the actions for the promotion return `true`, diff --git a/core/lib/spree/money.rb b/core/lib/spree/money.rb index dc01d2ccb8d..435bc80429f 100644 --- a/core/lib/spree/money.rb +++ b/core/lib/spree/money.rb @@ -35,7 +35,7 @@ def initialize(amount, options = {}) if amount.is_a?(::Money) @money = amount else - currency = (options[:currency] || Spree::Config[:currency]) + currency = options[:currency] || Spree::Config[:currency] @money = Monetize.from_string(amount, currency) end From 1dbb5972e5816bb2c1a7b6ecba2e2664cf64d00f Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 8 Feb 2024 11:07:56 +0100 Subject: [PATCH 2/4] Fix unsafe rubocop offenses Using rubocop -A and verified they are safe. --- api/app/views/spree/api/images/_image.json.jbuilder | 2 +- .../app/controllers/spree/admin/payment_methods_controller.rb | 2 +- backend/app/controllers/spree/admin/products_controller.rb | 4 ++-- core/app/models/spree/stock/splitter/shipping_category.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/app/views/spree/api/images/_image.json.jbuilder b/api/app/views/spree/api/images/_image.json.jbuilder index 7045b5bdb38..32385b77c52 100644 --- a/api/app/views/spree/api/images/_image.json.jbuilder +++ b/api/app/views/spree/api/images/_image.json.jbuilder @@ -2,6 +2,6 @@ json.(image, *image_attributes) json.(image, :viewable_type, :viewable_id) -Spree::Image.attachment_definitions[:attachment][:styles].each do |key, _value| +Spree::Image.attachment_definitions[:attachment][:styles].each_key do |key| json.set! "#{key}_url", image.url(key) end diff --git a/backend/app/controllers/spree/admin/payment_methods_controller.rb b/backend/app/controllers/spree/admin/payment_methods_controller.rb index e95bbb3d7bf..2dbfb621803 100644 --- a/backend/app/controllers/spree/admin/payment_methods_controller.rb +++ b/backend/app/controllers/spree/admin/payment_methods_controller.rb @@ -28,7 +28,7 @@ def update invoke_callbacks(:update, :before) attributes = payment_method_params - attributes.each do |key, _value| + attributes.each_key do |key| if key.include?("password") && attributes[key].blank? attributes.delete(key) end diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb index 519f4fc87b1..b25eb2c30ec 100644 --- a/backend/app/controllers/spree/admin/products_controller.rb +++ b/backend/app/controllers/spree/admin/products_controller.rb @@ -68,7 +68,7 @@ def location_after_save if updating_variant_property_rules? url_params = {} url_params[:ovi] = [] - params[:product][:variant_property_rules_attributes].each do |_index, param_attrs| + params[:product][:variant_property_rules_attributes].each_value do |param_attrs| url_params[:ovi] += param_attrs[:option_value_ids] end spree.admin_product_product_properties_url(@product, url_params) @@ -133,7 +133,7 @@ def render_after_update_error def normalize_variant_property_rules return unless updating_variant_property_rules? - params[:product][:variant_property_rules_attributes].each do |_index, param_attrs| + params[:product][:variant_property_rules_attributes].each_value do |param_attrs| param_attrs[:option_value_ids] = param_attrs[:option_value_ids].split(',') end end diff --git a/core/app/models/spree/stock/splitter/shipping_category.rb b/core/app/models/spree/stock/splitter/shipping_category.rb index 69ef2d56278..e23efb8b885 100644 --- a/core/app/models/spree/stock/splitter/shipping_category.rb +++ b/core/app/models/spree/stock/splitter/shipping_category.rb @@ -24,7 +24,7 @@ def split_by_category(package) def hash_to_packages(categories) packages = [] - categories.each do |_id, contents| + categories.each_value do |contents| packages << build_package(contents) end packages From 3080632aafb0cccc983e5374ed6122819012a782 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 8 Feb 2024 11:11:14 +0100 Subject: [PATCH 3/4] Disable Rubocop self assign check in order state machine Cherry Picked from bc3944d93a9eb621f3203dcae4ad2bf2a0d10514 Co-Authored-By: Elia Schito --- core/lib/spree/core/state_machines/order.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/spree/core/state_machines/order.rb b/core/lib/spree/core/state_machines/order.rb index db1faf5e3c5..058419d333f 100644 --- a/core/lib/spree/core/state_machines/order.rb +++ b/core/lib/spree/core/state_machines/order.rb @@ -46,7 +46,11 @@ def define_state_machine! # Persist the state on the order after_transition do |order, transition| - order.state = order.state + # Hard to say if this is really necessary, it was introduced in this commit: + # https://github.com/mamhoff/solidus/commit/fa1d66c42e4c04ee7cd1c20d87e4cdb74a226d3d + # But it seems to be harmless, so we'll keep it for now. + order.state = order.state # rubocop:disable Lint/SelfAssignment + order.state_changes.create( previous_state: transition.from, next_state: transition.to, From 042193cbe8f1350a2e78c6e15046ed82a0f4200a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 8 Feb 2024 11:28:41 +0100 Subject: [PATCH 4/4] Disable Rails/RakeEnvironment cop We have tasks that are not needing the Rails environment for builds and such that are not in the Rails app Rubocop flags those by mistake because it does not know we are not an app, but an engine. --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 770b8947b96..b3aa52b0a3f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -128,6 +128,10 @@ Rails/SkipsModelValidations: Exclude: - '*/spec/**/*' +# We have tasks that are not needing the Rails environment for builds and such that are not in the Rails app +Rails/RakeEnvironment: + Enabled: false + # We use a lot of # # expect {