From 413af46416918b60201885eed6bfcfa9616ca536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Busqu=C3=A9?= Date: Mon, 16 Jan 2023 06:00:14 +0100 Subject: [PATCH] Use `call` in the adjustments recalculator's interface We introduced an extension point for promotion adjustments in #4460 [1]. We change the expected interface from `#adjust!` to `#call` for consistency, as that's the new standard we want to follow (see #4677 [2] for an example). That's going to ease the adoption of a service layer if we eventually introduce it. [1] - https://github.com/solidusio/solidus/pull/4460 [2] - https://github.com/solidusio/solidus/pull/4677 --- core/app/models/spree/order_updater.rb | 2 +- .../models/spree/promotion/order_adjustments_recalculator.rb | 2 +- .../spree/promotion/order_adjustments_recalculator_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/order_updater.rb b/core/app/models/spree/order_updater.rb index 06b123d6a78..1b112fed409 100644 --- a/core/app/models/spree/order_updater.rb +++ b/core/app/models/spree/order_updater.rb @@ -197,7 +197,7 @@ def log_state_change(name) end def update_promotions - Spree::Config.promotion_adjuster_class.new(order).adjust! + Spree::Config.promotion_adjuster_class.new(order).call end # DEPRECATED; this functionality is handled in #update_promotions diff --git a/core/app/models/spree/promotion/order_adjustments_recalculator.rb b/core/app/models/spree/promotion/order_adjustments_recalculator.rb index b78db1ef25a..ed848a4cdc5 100644 --- a/core/app/models/spree/promotion/order_adjustments_recalculator.rb +++ b/core/app/models/spree/promotion/order_adjustments_recalculator.rb @@ -14,7 +14,7 @@ def initialize(order) @order = order end - def adjust! + def call all_items = line_items + shipments all_items.each do |item| promotion_adjustments = item.adjustments.select(&:promotion?) diff --git a/core/spec/models/spree/promotion/order_adjustments_recalculator_spec.rb b/core/spec/models/spree/promotion/order_adjustments_recalculator_spec.rb index 5f3c348bb76..ff782b514c4 100644 --- a/core/spec/models/spree/promotion/order_adjustments_recalculator_spec.rb +++ b/core/spec/models/spree/promotion/order_adjustments_recalculator_spec.rb @@ -3,9 +3,9 @@ require 'rails_helper' RSpec.describe Spree::Promotion::OrderAdjustmentsRecalculator do - subject { described_class.new(order).adjust! } + subject { described_class.new(order).call } - describe '#adjust! ' do + describe '#call ' do describe 'promotion recalculation' do let(:order) { create(:order_with_line_items, line_items_count: 1, line_items_price: 10) } let(:line_item) { order.line_items[0] }