From 9f9918129939a528614f496085267b5fe7f6137c Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 13 Sep 2023 10:05:05 +0200 Subject: [PATCH 1/5] Update all find_each "violations" --- .rubocop.yml | 4 ++++ api/spec/requests/spree/api/checkouts_spec.rb | 2 +- backend/spec/features/admin/orders/order_details_spec.rb | 2 +- core/app/models/spree/reimbursement_tax_calculator.rb | 2 +- core/app/models/spree/stock_location.rb | 2 +- core/app/models/spree/variant.rb | 2 +- core/db/default/spree/states.rb | 2 +- ...80710170104_create_spree_store_credit_reasons_table.rb | 4 ++-- ...6_set_promotions_with_any_policy_to_all_if_possible.rb | 2 +- core/lib/spree/core/controller_helpers/order.rb | 2 +- core/spec/models/spree/exchange_spec.rb | 2 +- core/spec/models/spree/stock/estimator_spec.rb | 8 ++++---- .../spec/models/spree/variant/vat_price_generator_spec.rb | 2 +- sample/db/samples/product_option_types.rb | 2 +- sample/db/samples/stock.rb | 2 +- 15 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a5e9d417242..770b8947b96 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -339,3 +339,7 @@ Lint/MissingSuper: Exclude: - 'core/lib/spree/deprecation.rb' # this is a known class that doesn't require super - 'core/lib/spree/preferences/configuration.rb' # this class has no superclass defining `self.inherited` + +Rails/FindEach: + Exclude: + - 'db/migrate/**/*' diff --git a/api/spec/requests/spree/api/checkouts_spec.rb b/api/spec/requests/spree/api/checkouts_spec.rb index 7edf722e26c..193db21ad59 100644 --- a/api/spec/requests/spree/api/checkouts_spec.rb +++ b/api/spec/requests/spree/api/checkouts_spec.rb @@ -101,7 +101,7 @@ module Spree::Api # Regression Spec for https://github.com/spree/spree/issues/5389 and https://github.com/spree/spree/issues/5880 it "can update addresses but not transition to delivery w/o shipping setup" do - Spree::ShippingMethod.all.each(&:destroy) + Spree::ShippingMethod.all.find_each(&:destroy) put spree.api_checkout_path(order), params: { order_token: order.guest_token, order: { bill_address_attributes: address, diff --git a/backend/spec/features/admin/orders/order_details_spec.rb b/backend/spec/features/admin/orders/order_details_spec.rb index 5abc6b66fcb..459a4c5e94c 100644 --- a/backend/spec/features/admin/orders/order_details_spec.rb +++ b/backend/spec/features/admin/orders/order_details_spec.rb @@ -90,7 +90,7 @@ product.stock_items.where.not(stock_location_id: stock_location_ids).discard_all - product.stock_items.where(stock_location_id: stock_location_ids).each do |stock_item| + product.stock_items.where(stock_location_id: stock_location_ids).find_each do |stock_item| stock_item.set_count_on_hand 1 end diff --git a/core/app/models/spree/reimbursement_tax_calculator.rb b/core/app/models/spree/reimbursement_tax_calculator.rb index 854cde1ff1e..780c3972fc3 100644 --- a/core/app/models/spree/reimbursement_tax_calculator.rb +++ b/core/app/models/spree/reimbursement_tax_calculator.rb @@ -12,7 +12,7 @@ module Spree class ReimbursementTaxCalculator class << self def call(reimbursement) - reimbursement.return_items.includes(:inventory_unit).each do |return_item| + reimbursement.return_items.includes(:inventory_unit).find_each do |return_item| set_tax!(return_item) end end diff --git a/core/app/models/spree/stock_location.rb b/core/app/models/spree/stock_location.rb index 0a8915cef64..f3f6215d62d 100644 --- a/core/app/models/spree/stock_location.rb +++ b/core/app/models/spree/stock_location.rb @@ -121,7 +121,7 @@ def create_stock_items def ensure_one_default if default - Spree::StockLocation.where(default: true).where.not(id: id).each do |stock_location| + Spree::StockLocation.where(default: true).where.not(id: id).find_each do |stock_location| stock_location.default = false stock_location.save! end diff --git a/core/app/models/spree/variant.rb b/core/app/models/spree/variant.rb index 3a9c8741e99..90ecf56b0cd 100644 --- a/core/app/models/spree/variant.rb +++ b/core/app/models/spree/variant.rb @@ -397,7 +397,7 @@ def set_cost_currency end def create_stock_items - StockLocation.where(propagate_all_variants: true).each do |stock_location| + StockLocation.where(propagate_all_variants: true).find_each do |stock_location| stock_location.propagate_variant(self) end end diff --git a/core/db/default/spree/states.rb b/core/db/default/spree/states.rb index dc8b130a16c..e4aaab0ad51 100644 --- a/core/db/default/spree/states.rb +++ b/core/db/default/spree/states.rb @@ -9,7 +9,7 @@ def create_states(subregions, country) end ActiveRecord::Base.transaction do - Spree::Country.all.each do |country| + Spree::Country.all.find_each do |country| carmen_country = Carmen::Country.coded(country.iso) next unless carmen_country.subregions? diff --git a/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb index cd50bd414fc..9d805df56f2 100644 --- a/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb +++ b/core/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb @@ -17,7 +17,7 @@ def up t.timestamps end - StoreCreditUpdateReason.all.each do |update_reason| + StoreCreditUpdateReason.all.find_each do |update_reason| StoreCreditReason.create!(name: update_reason.name) end @@ -45,7 +45,7 @@ def down end end - StoreCreditReason.all.each do |store_credit_reason| + StoreCreditReason.all.find_each do |store_credit_reason| StoreCreditUpdateReason.create!(name: store_credit_reason.name) end diff --git a/core/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb b/core/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb index a36bb5efe90..7c49f8fdac5 100644 --- a/core/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb +++ b/core/db/migrate/20220317165036_set_promotions_with_any_policy_to_all_if_possible.rb @@ -2,7 +2,7 @@ class SetPromotionsWithAnyPolicyToAllIfPossible < ActiveRecord::Migration[5.2] def up - Spree::Promotion.where(match_policy: :any).includes(:promotion_rules).all.each do |promotion| + Spree::Promotion.where(match_policy: :any).includes(:promotion_rules).all.find_each do |promotion| if promotion.promotion_rules.length <= 1 promotion.update!(match_policy: :all) else diff --git a/core/lib/spree/core/controller_helpers/order.rb b/core/lib/spree/core/controller_helpers/order.rb index d63bff9ecf8..e3bb2b61c69 100644 --- a/core/lib/spree/core/controller_helpers/order.rb +++ b/core/lib/spree/core/controller_helpers/order.rb @@ -45,7 +45,7 @@ def associate_user def set_current_order if spree_current_user && current_order - spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).each do |order| + spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).find_each do |order| current_order.merge!(order, spree_current_user) end end diff --git a/core/spec/models/spree/exchange_spec.rb b/core/spec/models/spree/exchange_spec.rb index e780330d68e..4c95f7572e7 100644 --- a/core/spec/models/spree/exchange_spec.rb +++ b/core/spec/models/spree/exchange_spec.rb @@ -54,7 +54,7 @@ module Spree context "when it cannot create shipments for all items" do before do - StockItem.where(variant_id: return_item.exchange_variant_id).each(&:destroy) + StockItem.where(variant_id: return_item.exchange_variant_id).find_each(&:destroy) end it 'raises an UnableToCreateShipments error' do diff --git a/core/spec/models/spree/stock/estimator_spec.rb b/core/spec/models/spree/stock/estimator_spec.rb index 9979fc4eff2..1d6d35c0ca7 100644 --- a/core/spec/models/spree/stock/estimator_spec.rb +++ b/core/spec/models/spree/stock/estimator_spec.rb @@ -85,7 +85,7 @@ module Stock end it "sorts shipping rates by cost" do - ShippingMethod.all.each(&:destroy) + ShippingMethod.all.find_each(&:destroy) create(:shipping_method, cost: 5) create(:shipping_method, cost: 3) create(:shipping_method, cost: 4) @@ -94,7 +94,7 @@ module Stock end context "general shipping methods" do - before { Spree::ShippingMethod.all.each(&:destroy) } + before { Spree::ShippingMethod.all.find_each(&:destroy) } context 'with a custom shipping calculator with no preference' do class Spree::Calculator::Shipping::NoPreferences < Spree::ShippingCalculator @@ -168,7 +168,7 @@ def compute_package(_package) end context "involves backend only shipping methods" do - before{ Spree::ShippingMethod.all.each(&:destroy) } + before{ Spree::ShippingMethod.all.find_each(&:destroy) } let!(:backend_method) { create(:shipping_method, available_to_users: false, cost: 0.00) } let!(:generic_method) { create(:shipping_method, cost: 5.00) } @@ -183,7 +183,7 @@ def compute_package(_package) end context "excludes shipping methods from other stores" do - before{ Spree::ShippingMethod.all.each(&:destroy) } + before{ Spree::ShippingMethod.all.find_each(&:destroy) } let!(:other_method) do create( diff --git a/core/spec/models/spree/variant/vat_price_generator_spec.rb b/core/spec/models/spree/variant/vat_price_generator_spec.rb index 2e15a020d13..b07e023186d 100644 --- a/core/spec/models/spree/variant/vat_price_generator_spec.rb +++ b/core/spec/models/spree/variant/vat_price_generator_spec.rb @@ -37,7 +37,7 @@ # We need to remove the price for FR from the database so it is created in memory, and then run VatPriceGenerator twice to trigger the duplicate price issue. it "will not build duplicate prices on multiple runs" do - variant.prices.where(country_iso: "FR").each(&:destroy) + variant.prices.where(country_iso: "FR").find_each(&:destroy) variant.reload described_class.new(variant).run expect { subject }.not_to change { variant.prices.size } diff --git a/sample/db/samples/product_option_types.rb b/sample/db/samples/product_option_types.rb index 6ebf087f6bb..7f5ac048260 100644 --- a/sample/db/samples/product_option_types.rb +++ b/sample/db/samples/product_option_types.rb @@ -9,7 +9,7 @@ "Solidus T-Shirt", "Solidus Long Sleeve", "Solidus Women's T-Shirt" ] -Spree::Product.all.each do |product| +Spree::Product.all.find_each do |product| product.option_types = [size] product.option_types << color if colored_clothes.include?(product.name) product.save! diff --git a/sample/db/samples/stock.rb b/sample/db/samples/stock.rb index e28fdbd4de4..2cc23eee5eb 100644 --- a/sample/db/samples/stock.rb +++ b/sample/db/samples/stock.rb @@ -7,7 +7,7 @@ location.active = true location.save! -Spree::Variant.all.each do |variant| +Spree::Variant.all.find_each do |variant| variant.stock_items.each do |stock_item| Spree::StockMovement.create(quantity: 10, stock_item: stock_item) end From 990e744d00d0a1e53063bd8a13a5db5c8d4b3199 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Wed, 13 Sep 2023 10:20:15 +0200 Subject: [PATCH 2/5] Parse time using the current zone --- backend/spec/helpers/admin/base_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/spec/helpers/admin/base_helper_spec.rb b/backend/spec/helpers/admin/base_helper_spec.rb index 2dc5a431cc0..da3e78834a3 100644 --- a/backend/spec/helpers/admin/base_helper_spec.rb +++ b/backend/spec/helpers/admin/base_helper_spec.rb @@ -12,7 +12,7 @@ end it "should return a formatted date when date is present" do - date = "2013-08-14".to_time + date = Time.zone.parse("2013-08-14") expect(datepicker_field_value(date)).to eq("2013/08/14") end end From 4e427917bdae84f34cd31eb1941fd295b2127ec9 Mon Sep 17 00:00:00 2001 From: tvdeyen Date: Thu, 2 Nov 2023 08:56:04 +0000 Subject: [PATCH 3/5] Post-release chores after having released Solidus v4.1.3 This code has been automatically generated by our 'Prepare post-release' GitHub action. Make sure that: - [ ] The new release has been published, along with its tag. See https://github.com/solidusio/solidus/releases/tag/v4.1.3 - [ ] The corresponding patch branch exists. See https://github.com/solidusio/solidus/tree/v4.1 - [ ] The corresponding backport-v4.1 label exists. See https://github.com/solidusio/solidus/labels --- core/lib/spree/core/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/spree/core/version.rb b/core/lib/spree/core/version.rb index 1caa60c8402..bfd7f9c3a26 100644 --- a/core/lib/spree/core/version.rb +++ b/core/lib/spree/core/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - VERSION = "4.1.3" + VERSION = "4.1.4.dev" def self.solidus_version VERSION From 79fe082838f0104c1ca8bdc65579a1e6cd48a732 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 1 Nov 2023 09:37:50 +0100 Subject: [PATCH 4/5] CI: Skip install_solidus check on non-current version The installer always uses the current released minor version (4.2 time writing this), but the check runs on all pipeline runs, wasting CI time and precious resources. Also it fails anyway, because of conflicting dependencies. So, we only run the check on main and latest minor now. (cherry picked from commit 8d653a5bef66e7d055a506215d6f02f0da7bc72f) --- .circleci/config.yml | 47 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index eae75dd3db9..1711508b6f3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -249,26 +249,33 @@ jobs: ruby: "3.0" steps: - checkout - - libvips - - - install_solidus: { flags: "--sample=false --frontend=starter --authentication=devise" } - - test_page: { expected_text: "The only eCommerce platform you’ll ever need." } - - run: - name: Ensure the correct PayPal is installed for SSF - command: | - cd /tmp/my_app - bundle list | grep 'solidus_paypal_commerce_platform (1.' - - - install_solidus: { flags: "--sample=false --frontend=starter --authentication=devise --payment-method=stripe" } - - test_page: { expected_text: "The only eCommerce platform you’ll ever need." } - - - install_dummy_app - - - install_dummy_app: { extra_gems: "solidus_frontend" } - - run: - name: "Ensure solidus_frontend installer is run" - command: | - test -f /tmp/dummy_extension/spec/dummy/config/initializers/solidus_frontend.rb + - when: + condition: + or: + - equal: [main, << pipeline.git.branch >>] + - equal: [v4.2, << pipeline.git.branch >>] + steps: + - libvips + - install_solidus: + flags: "--sample=false --frontend=starter --authentication=devise" + - test_page: + expected_text: "The only eCommerce platform you’ll ever need." + - run: + name: Ensure the correct PayPal is installed for SSF + command: | + cd /tmp/my_app + bundle list | grep 'solidus_paypal_commerce_platform (1.' + - install_solidus: + flags: "--sample=false --frontend=starter --authentication=devise --payment-method=stripe" + - test_page: + expected_text: "The only eCommerce platform you’ll ever need." + - install_dummy_app + - install_dummy_app: + extra_gems: "solidus_frontend" + - run: + name: "Ensure solidus_frontend installer is run" + command: | + test -f /tmp/dummy_extension/spec/dummy/config/initializers/solidus_frontend.rb test_solidus: parameters: From e5b4241f73eed4e3b15d980ef43897c2a465fb41 Mon Sep 17 00:00:00 2001 From: elia Date: Fri, 5 Jan 2024 16:48:37 +0000 Subject: [PATCH 5/5] Prepare release for Solidus v4.1.4 This code has been automatically generated by our 'Prepare release' GitHub action. The actual release is not part of the automation, and it still needs to be manually done by a maintainer. --- CHANGELOG.md | 20 ++++++++++++++++++++ core/lib/spree/core/version.rb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a3f233d6a9..d990f633c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +## Solidus v4.1.4 (2024-01-05) + +## Solidus Core +* [4.1] Use ActiveRecord's `.find_each` instead of `.each` whenever possible by @tvdeyen in https://github.com/solidusio/solidus/pull/5484 + +## Solidus Backend +* [4.1] Use ActiveRecord's `.find_each` instead of `.each` whenever possible by @tvdeyen in https://github.com/solidusio/solidus/pull/5484 + +## Solidus API +* [4.1] Use ActiveRecord's `.find_each` instead of `.each` whenever possible by @tvdeyen in https://github.com/solidusio/solidus/pull/5484 + +## Solidus Sample +* [4.1] Use ActiveRecord's `.find_each` instead of `.each` whenever possible by @tvdeyen in https://github.com/solidusio/solidus/pull/5484 + +## Solidus + + +**Full Changelog**: https://github.com/solidusio/solidus/compare/v4.1.3...v4.1.4 + + ## Solidus v4.1.3 (2023-11-02) ## Solidus Core diff --git a/core/lib/spree/core/version.rb b/core/lib/spree/core/version.rb index bfd7f9c3a26..8e1a5ddbf09 100644 --- a/core/lib/spree/core/version.rb +++ b/core/lib/spree/core/version.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - VERSION = "4.1.4.dev" + VERSION = "4.1.4" def self.solidus_version VERSION