From bc3944d93a9eb621f3203dcae4ad2bf2a0d10514 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 4 Dec 2023 15:48:37 +0100 Subject: [PATCH] Fix rubocop violations after the latest release --- api/app/views/spree/api/images/_image.json.jbuilder | 3 ++- .../controllers/spree/admin/payment_methods_controller.rb | 2 +- backend/app/controllers/spree/admin/products_controller.rb | 4 ++-- core/app/models/spree/order.rb | 2 +- core/app/models/spree/promotion_handler/coupon.rb | 2 +- core/app/models/spree/stock/splitter/shipping_category.rb | 2 +- core/lib/spree/core/state_machines/order.rb | 6 +++++- core/lib/spree/money.rb | 2 +- sample/db/samples/shipping_methods.rb | 3 ++- 9 files changed, 16 insertions(+), 10 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..83b1df55909 100644 --- a/api/app/views/spree/api/images/_image.json.jbuilder +++ b/api/app/views/spree/api/images/_image.json.jbuilder @@ -2,6 +2,7 @@ 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/order.rb b/core/app/models/spree/order.rb index 8587165b2f2..11f92c965cc 100644 --- a/core/app/models/spree/order.rb +++ b/core/app/models/spree/order.rb @@ -637,7 +637,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/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 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, 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 diff --git a/sample/db/samples/shipping_methods.rb b/sample/db/samples/shipping_methods.rb index dfff4dada84..aeb23eb2794 100644 --- a/sample/db/samples/shipping_methods.rb +++ b/sample/db/samples/shipping_methods.rb @@ -50,7 +50,8 @@ } ]) -{ +# The just below rubocop:disable directive will be removed once https://github.com/rubocop/rubocop/issues/12441 is resolved. +{ # rubocop:disable Style/HashEachMethods "UPS Ground (USD)" => [5, "USD"], "UPS Ground (EU)" => [5, "USD"], "UPS One Day (USD)" => [15, "USD"],