From 2937595a3365c4301a2b89cafe4021a84197e1f4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 May 2024 22:49:38 +0000 Subject: [PATCH 1/6] chore(deps-dev): bump rubocop-rails from 2.24.1 to 2.25.0 Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.24.1 to 2.25.0. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.24.1...v2.25.0) --- updated-dependencies: - dependency-name: rubocop-rails dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index bea6c459db..e53118fb36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -683,7 +683,7 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) - rubocop-rails (2.24.1) + rubocop-rails (2.25.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) From 49ec9a3136db58a842a7d0c492bc3ba250614b10 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jan 2025 08:43:58 +1100 Subject: [PATCH 2/6] Style Rails/WhereRange --- app/models/invoice.rb | 2 +- app/models/order_cycle.rb | 6 +++--- .../order_management/subscriptions/proxy_order_syncer.rb | 5 ++--- lib/tasks/data/remove_transient_data.rb | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 7cfc71c9a6..69c89d673f 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -32,6 +32,6 @@ class Invoice < ApplicationRecord end def previous_invoice - order.invoices.where("id < ?", id).first + order.invoices.where(id: ...id).first end end diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index f87e850fdd..e5c41974c5 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -53,7 +53,7 @@ class OrderCycle < ApplicationRecord Time.zone.now, Time.zone.now) } - scope :active_or_complete, lambda { where('order_cycles.orders_open_at <= ?', Time.zone.now) } + scope :active_or_complete, lambda { where(order_cycles: { orders_open_at: ..Time.zone.now }) } scope :inactive, lambda { where('order_cycles.orders_open_at > ? OR order_cycles.orders_close_at < ?', Time.zone.now, @@ -64,8 +64,8 @@ class OrderCycle < ApplicationRecord where('order_cycles.orders_close_at > ? OR order_cycles.orders_close_at IS NULL', Time.zone.now) } scope :closed, lambda { - where('order_cycles.orders_close_at < ?', - Time.zone.now).order("order_cycles.orders_close_at DESC") + where(order_cycles: { orders_close_at: ...Time.zone.now }) + .order("order_cycles.orders_close_at DESC") } scope :unprocessed, -> { where(processed_at: nil) } scope :undated, -> { where('order_cycles.orders_open_at IS NULL OR orders_close_at IS NULL') } diff --git a/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb b/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb index e906a0ed16..0b4975e14c 100644 --- a/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb +++ b/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb @@ -90,9 +90,8 @@ module OrderManagement end def in_range_order_cycles - order_cycles.where("orders_close_at >= ? AND orders_close_at <= ?", - begins_at, - ends_at || 100.years.from_now) + ends_at_or_limit = ends_at || 100.years.from_now + order_cycles.where(orders_close_at: begins_at..ends_at_or_limit ) end end end diff --git a/lib/tasks/data/remove_transient_data.rb b/lib/tasks/data/remove_transient_data.rb index ffe136cd08..95573c1a0a 100644 --- a/lib/tasks/data/remove_transient_data.rb +++ b/lib/tasks/data/remove_transient_data.rb @@ -18,9 +18,9 @@ class RemoveTransientData def call Rails.logger.info("#{self.class.name}: processing") - Spree::StateChange.where("created_at < ?", expiration_date).delete_all - Spree::LogEntry.where("created_at < ?", expiration_date).delete_all - Session.where("updated_at < ?", expiration_date).delete_all + Spree::StateChange.where(created_at: ...expiration_date).delete_all + Spree::LogEntry.where(created_at: ...expiration_date).delete_all + Session.where(updated_at: ...expiration_date).delete_all clear_old_cart_data! end From f9d436b1c9b907c4b371c01c3469e74fd5a65fcf Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jan 2025 08:57:20 +1100 Subject: [PATCH 3/6] Simplify subscription query The artificial limit of 100 years was just set because the old SQL query wouldn't deal with `null` well. Comparing with null always is always false and returns nothing. But Rails is now clever enough to interpret `begins_at..nil` as open end query. This shouldn't have any practical impact as there's unlikely to be an order cycle closing in more than 100 years. And if there was, it would be confusing that it's not treated like other order cycles ending in 80 years. --- .../order_management/subscriptions/proxy_order_syncer.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb b/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb index 0b4975e14c..c256ae0134 100644 --- a/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb +++ b/engines/order_management/app/services/order_management/subscriptions/proxy_order_syncer.rb @@ -90,8 +90,7 @@ module OrderManagement end def in_range_order_cycles - ends_at_or_limit = ends_at || 100.years.from_now - order_cycles.where(orders_close_at: begins_at..ends_at_or_limit ) + order_cycles.where(orders_close_at: begins_at..ends_at) end end end From 6cf1a0500dd8f87a4e51d13b7854459a7ffbeeac Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jan 2025 09:07:04 +1100 Subject: [PATCH 4/6] Bump rubocop-rails from 2.25.0 to 2.28.0 --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e53118fb36..0d9d2b78a6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -683,10 +683,10 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) - rubocop-rails (2.25.0) + rubocop-rails (2.28.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) rubocop-rspec (2.29.2) rubocop (~> 1.40) From c1198c8e1f92d445c3279611ff9175ced73c79a0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jan 2025 09:07:04 +1100 Subject: [PATCH 5/6] UNSAFE Style Rails/CompactBlank --- app/models/spree/address.rb | 4 ++-- app/services/address_geocoder.rb | 2 +- .../order_cycle_supplier_totals_by_distributor_report_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 9d7cac881f..c9cbeef466 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -126,7 +126,7 @@ module Spree end def address_and_city - [address1, address2, city].select(&:present?).join(' ') + [address1, address2, city].compact_blank.join(' ') end private @@ -176,7 +176,7 @@ module Spree end def render_address(parts) - parts.select(&:present?).join(', ') + parts.compact_blank.join(', ') end end end diff --git a/app/services/address_geocoder.rb b/app/services/address_geocoder.rb index 789e0695d4..61de7b2547 100644 --- a/app/services/address_geocoder.rb +++ b/app/services/address_geocoder.rb @@ -18,7 +18,7 @@ class AddressGeocoder attr_reader :address def geocode_address - address_parts.select(&:present?).join(', ') + address_parts.compact_blank.join(', ') end def address_parts diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb index ff73f6d12e..8ab11c88c8 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_supplier_totals_by_distributor_report_spec.rb @@ -37,7 +37,7 @@ module Reporting order.line_items[0].variant.product.update(name: "Cucumber") order.line_items[1].variant.product.update(name: "Apple") order.line_items[2].variant.product.update(name: "Banane") - product_names = report.rows.map(&:product).filter(&:present?) + product_names = report.rows.map(&:product).compact_blank expect(product_names).to eq(["Apple", "Banane", "Cucumber"]) end end @@ -84,7 +84,7 @@ module Reporting order.line_items[0].variant.product.update(name: "Cucumber") order.line_items[1].variant.product.update(name: "Apple") order.line_items[2].variant.product.update(name: "Banane") - product_names = report.rows.map(&:product).filter(&:present?) + product_names = report.rows.map(&:product).compact_blank # only the supplier's variant is displayed expect(product_names).to include("Cucumber") expect(product_names).not_to include("Apple", "Banane") From f8788d358eba3d71dcefd27f3ecd30cac1601175 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jan 2025 09:08:54 +1100 Subject: [PATCH 6/6] UNSAFE style Rails/RootPathnameMethods --- spec/base_spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 5579890b64..026e538315 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -44,7 +44,7 @@ WebMock.disable_net_connect!( # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } +Rails.root.glob("spec/support/**/*.rb").sort.each { |f| require f } Capybara.server = :puma Capybara.disable_animation = true