Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Removed five classes that only tests called (#14805)

Damian Legawiec7542667c0231
diff --git a/docs/developer/upgrades/5.6-to-6.0.mdx b/docs/developer/upgrades/5.6-to-6.0.mdx
index 3d2d6b439f..5efe25c361 100644
--- a/docs/developer/upgrades/5.6-to-6.0.mdx
+++ b/docs/developer/upgrades/5.6-to-6.0.mdx
@@ -426,7 +426,7 @@ New seams with no legacy counterpart:
| `order_discount_create_service` | `Spree::Orders::Discounts::Create` | renamed from `order_add_manual_discount_service` (never released) |
| `order_update_statuses_service` | `Spree::Orders::UpdateStatuses` | the sole status writer |
-Removed keys (their classes no longer exist): `carts_validate_service` (completion validation is `Spree::Checkout::Requirements` directly), plus the dead legacy `Spree::Cart::*` service namespace registrations.
+Removed keys (their classes no longer exist): `carts_validate_service` (completion validation is `Spree::Checkout::Requirements` directly), `cart_empty_service` and `payment_create_service` (see [Unused services are gone](#unused-services-are-gone)), plus the dead legacy `Spree::Cart::*` service namespace registrations.
If you override a workflow seam, subclass the shipped workflow (or implement the same `perform` keyword contract) — workflow arguments are plain Ruby keywords, so a mismatch raises `ArgumentError` at call time, not silently.
@@ -515,6 +515,16 @@ Two behavior notes for extension authors: `Spree::Metadata` no longer includes t
Single-store installations notice nothing. **A multi-store installation ends up with its whole schema on the default store**, and its other stores start empty: create the fields you want on each store, or run `bin/rake spree:upgrade:backfill_custom_field_definition_stores` first if the migration ran before any store existed. Existing values keep pointing at the definitions they always did, which is why the rows are not copied — copies would render blank anyway. Two definitions whose `namespace`/`key` pair flattens to one `cf_…` key (`("a_b", "c")` and `("a", "b_c")`) can no longer coexist in a store; the migration suffixes the later one and names it in its output so you can rename it.
+### Unused services are gone
+
+These had no caller left in Spree, so they are removed with no replacement shim. Setting or reading their `Spree::Dependencies` keys now raises `NoMethodError`.
+
+| Removed | Use instead |
+|---|---|
+| `Spree::PromotionHandler::Page` (activating a promotion by visiting its `path`) | apply the promotion with a coupon code, or as an automatic promotion |
+| `Spree::Carts::Empty` and `cart_empty_service` | remove items through the Store API cart items endpoints, or delete the cart with `Spree.cart_destroy_service` |
+| `Spree::Payments::Create` and `payment_create_service` | the Store API payments endpoint, `Spree::StoreCredits::Apply` or `Spree.gift_card_apply_workflow` |
+
### The Legacy order-routing strategy is gone
`Spree::OrderRouting::Strategy::Legacy` — the pre-5.5 escape hatch that delegated straight to `Spree::Stock::Coordinator` and consulted no routing rules — is removed and no longer registered in `Spree.order_routing.strategies`.
diff --git a/spree/core/app/models/spree/promotion_handler/page.rb b/spree/core/app/models/spree/promotion_handler/page.rb
deleted file mode 100644
index 3886bbc9d7..0000000000
--- a/spree/core/app/models/spree/promotion_handler/page.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module Spree
- module PromotionHandler
- class Page
- attr_reader :order, :path, :store
-
- def initialize(order, path)
- @order = order
- @store = order.store
- @path = path.gsub(/\A\//, '')
- end
-
- def activate
- if promotion&.eligible?(order)
- promotion.activate(order: order)
- end
- end
-
- private
-
- def promotion
- @promotion ||= store.promotions.active.find_by(path: path)
- end
- end
- end
-end
diff --git a/spree/core/app/services/spree/carts/empty.rb b/spree/core/app/services/spree/carts/empty.rb
deleted file mode 100644
index 8e9f25133e..0000000000
--- a/spree/core/app/services/spree/carts/empty.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-module Spree
- module Carts
- class Empty
- prepend Spree::ServiceModule::Base
-
- def call(cart: nil, order: nil)
- if order
- Spree::Deprecation.warn('Calling Spree::Carts::Empty with order: is deprecated and will be removed in Spree 6.1. Pass cart: instead.')
- cart ||= order
- end
- rewrite_input!(remove: [:order], cart: cart)
- run :check_if_can_be_empty
- run :empty_order
- end
-
- private
-
- def check_if_can_be_empty(cart:)
- return failure(Spree.t(:cannot_empty)) if cart.nil? || cart.completed?
-
- success(cart: cart)
- end
-
- def empty_order(cart:)
- ActiveRecord::Base.transaction do
- cart.line_items.destroy_all
- cart.update_columns(total_quantity: 0, updated_at: Time.current)
- cart.tax_lines.destroy_all
- cart.discounts.destroy_all
- cart.fees.destroy_all
- cart.fulfillments.destroy_all
- cart.order_promotions.destroy_all
- cart.recalculate_totals!
-
- Spree::StockReservations::Release.call(cart: cart)
-
- success(cart)
- end
- end
- end
- end
-end
diff --git a/spree/core/app/services/spree/payments/create.rb b/spree/core/app/services/spree/payments/create.rb
deleted file mode 100644
index 484e208ad9..0000000000
--- a/spree/core/app/services/spree/payments/create.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-module Spree
- module Payments
- # @deprecated Unused since 6.0 and removed in 7.0. Nothing in Spree
- # calls this: the storefront creates payments through the Store API
- # controller, store credit through Spree::StoreCredits::Apply,
- # gift cards through Spree::GiftCards::Apply, and a partial capture's
- # remainder through Spree::Payment#split_uncaptured_amount.
- #
- # It also cannot serve those callers as written — it resolves the
- # payment method from +params[:payment_method_id]+ against the
- # storefront-visible list and builds a source from client attributes,
- # while they already hold both (the gift card flow creates its payment
- # method by type when the store has none).
- class Create
- prepend Spree::ServiceModule::Base
-
- def call(order:, params: {})
- ApplicationRecord.transaction do
- run :prepare_payment_attributes
- run :find_or_create_payment_source
- run :save_payment
- end
- # Gateway I/O — after the transaction, on the in-memory graph (some
- # gateways need the raw card number, which never persists).
- run :store_gateway_profile
- end
-
- protected
-
- def prepare_payment_attributes(order:, params:)
- payment_method = order.payment_methods.find { |pm| pm.id.to_s == params[:payment_method_id]&.to_s }
-
- payment_attributes = {
- amount: params[:amount] || order.order_total_after_store_credit,
- payment_method: payment_method
- }
-
- return failure(nil, :payment_method_not_found) if payment_method.blank?
-
- success(order: order, params: params, payment_attributes: payment_attributes)
- end
-
- def find_or_create_payment_source(order:, params:, payment_attributes:)
- payment_method = payment_attributes[:payment_method]
-
- if payment_method&.source_required?
- if order.customer.present? && params[:source_id].present?
- source = payment_method.payment_source_class.find_by(id: params[:source_id], customer: order.customer)
-
- return failure(nil, :source_not_found) if source.nil?
- else
- result = Wallet::CreatePaymentSource.call(
- payment_method: payment_method,
- params: params.delete(:source_attributes),
- user: order.customer
- )
-
- return failure(nil, result.error.value) if result.failure?
-
- source = result.value
- end
-
- payment_attributes[:source] = source
- end
-
- success(order: order, payment_attributes: payment_attributes)
- end
-
- def save_payment(order:, payment_attributes:)
- payment = order.payments.new(payment_attributes)
-
- if payment.save
- success(payment: payment)
- else
- failure(payment)
- end
- end
-
- # A payment that cannot be profiled must not linger half-created — the
- # old after_save callback rolled the whole save back on gateway failure.
- def store_gateway_profile(payment:)
- return success(payment) unless payment.profiles_supported?
-
- payment.create_payment_profile
- success(payment)
- rescue Spree::Core::GatewayError => e
- payment.destroy
- failure(payment, e.message)
- end
- end
- end
-end
diff --git a/spree/core/app/workflows/spree/fulfillments/fulfill.rb b/spree/core/app/workflows/spree/fulfillments/fulfill.rb
index 3645f5cd65..bb2d82d912 100644
--- a/spree/core/app/workflows/spree/fulfillments/fulfill.rb
+++ b/spree/core/app/workflows/spree/fulfillments/fulfill.rb
@@ -70,7 +70,7 @@ module Spree
# box, hand it over), and the ordering that lets the shipped email
# carry the tracking number the provider discovered instead of racing
# it. No-op when a label was already bought through
- # Spree::Fulfillments::PurchaseLabel (the flow where a failure is
+ # Spree::ShippingLabels::Purchase (the flow where a failure is
# loud), or when the provider has no dispatch mechanics (Manual). A
# failure here still degrades to "no label yet" — a carrier outage
# must never stop a merchant recording a parcel that physically left.
diff --git a/spree/core/app/workflows/spree/fulfillments/purchase_label.rb b/spree/core/app/workflows/spree/fulfillments/purchase_label.rb
deleted file mode 100644
index d45e1cbfb9..0000000000
--- a/spree/core/app/workflows/spree/fulfillments/purchase_label.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-module Spree
- module Fulfillments
- # Buys the shipping label for a parcel that has not shipped yet — the step
- # a warehouse performs BEFORE anything is handed over: print the label,
- # stick it on the box, then mark the fulfillment fulfilled.
- #
- # This is where a purchase failure is loud. The one-click fulfill path
- # degrades a label failure to "no label yet" because a carrier outage must
- # never stop a merchant recording a parcel that physically left; here
- # nothing has left, so a failed purchase simply fails and the merchant
- # retries.
- #
- # Thin over Spree::ShippingLabels::Purchase, kept as its own workflow for
- # the hooks that have been public since the label-leads amendment.
- class PurchaseLabel < Spree::Workflow
- hooks :validate, :after_purchase_label
-
- # @param fulfillment [Spree::Fulfillment] the parcel to buy a label for
- # @return [Spree::ServiceModule::Result] the fulfillment with its label
- # and delivery attached on success
- def perform(fulfillment:)
- super
-
- run_hooks :validate
-
- step :purchase
-
- run_hooks :after_purchase_label
- success(fulfillment.reload)
- end
-
- private
-
- def purchase
- result = Spree.shipping_label_purchase_workflow.call(owner: fulfillment)
- failure(fulfillment, result.error.to_s) if result.failure?
- end
- end
- end
-end
diff --git a/spree/core/app/workflows/spree/returns/purchase_label.rb b/spree/core/app/workflows/spree/returns/purchase_label.rb
deleted file mode 100644
index 0243d0229d..0000000000
--- a/spree/core/app/workflows/spree/returns/purchase_label.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-module Spree
- module Returns
- # Buys the customer's return label: an inbound parcel from the address
- # the order shipped to back to the return's stock location, bought
- # through the provider that shipped the goods out. The label attaches to
- # the return as its owner and mints the inbound delivery, whose arrival
- # never receives the return — Spree::Returns::Receive stays a staff act.
- class PurchaseLabel < Spree::Workflow
- hooks :validate, :after_purchase_label
-
- # @param return_record [Spree::Return]
- # @return [Spree::ServiceModule::Result] the return with its label on success
- def perform(return_record:)
- super
-
- run_hooks :validate
-
- step :purchase
-
- run_hooks :after_purchase_label
- success(return_record.reload)
- end
-
- private
-
- def purchase
- result = Spree.shipping_label_purchase_workflow.call(owner: return_record)
- failure(return_record, result.error.to_s) if result.failure?
- end
- end
- end
-end
diff --git a/spree/core/config/locales/en.yml b/spree/core/config/locales/en.yml
index c87922affb..2cf01b17a0 100644
--- a/spree/core/config/locales/en.yml
+++ b/spree/core/config/locales/en.yml
@@ -710,7 +710,6 @@ en:
canceled_at: Canceled at
canceler: Canceler
cannot_be_destroyed: Order cannot be destroyed.
- cannot_empty: Cannot empty order.
capture: Capture
capture_events: Capture events
cart: Cart
diff --git a/spree/core/lib/spree/core/dependencies.rb b/spree/core/lib/spree/core/dependencies.rb
index 272f5a8a4d..b692267620 100644
--- a/spree/core/lib/spree/core/dependencies.rb
+++ b/spree/core/lib/spree/core/dependencies.rb
@@ -37,7 +37,6 @@ module Spree
order_update_item_service: 'Spree::Orders::UpdateItem',
order_remove_line_item_service: 'Spree::Orders::RemoveLineItem',
order_remove_item_service: 'Spree::Orders::RemoveItem',
- cart_empty_service: 'Spree::Carts::Empty',
cart_destroy_service: 'Spree::Carts::Destroy',
cart_associate_service: 'Spree::Carts::Associate',
cart_remove_out_of_stock_items_service: 'Spree::Carts::RemoveOutOfStockItems',
@@ -83,7 +82,6 @@ module Spree
fulfillment_fulfill_workflow: 'Spree::Fulfillments::Fulfill',
fulfillment_cancel_workflow: 'Spree::Fulfillments::Cancel',
fulfillment_mark_delivered_workflow: 'Spree::Fulfillments::MarkDelivered',
- fulfillment_purchase_label_workflow: 'Spree::Fulfillments::PurchaseLabel',
# shipping labels + deliveries
shipping_label_purchase_workflow: 'Spree::ShippingLabels::Purchase',
@@ -97,7 +95,6 @@ module Spree
fulfillment_stand_down_service: 'Spree::Fulfillments::StandDownProvider',
fulfillment_recalculate_delivery_service: 'Spree::Fulfillments::RecalculateDelivery',
delivery_destroy_service: 'Spree::Deliveries::Destroy',
- return_purchase_label_workflow: 'Spree::Returns::PurchaseLabel',
# inventory operations
stock_level_correct_service: 'Spree::StockLevels::Correct',
@@ -242,7 +239,6 @@ module Spree
# payment is arranged (deposits, net terms).
purchase_amount_due_at_checkout_service: 'Spree::Purchases::AmountDueAtCheckout',
- payment_create_service: 'Spree::Payments::Create',
payment_process_workflow: 'Spree::Payments::Process',
payment_capture_workflow: 'Spree::Payments::Capture',
payment_void_workflow: 'Spree::Payments::Void',
diff --git a/spree/core/spec/models/spree/promotion_handler/page_spec.rb b/spree/core/spec/models/spree/promotion_handler/page_spec.rb
deleted file mode 100644
index 5028b09e9d..0000000000
--- a/spree/core/spec/models/spree/promotion_handler/page_spec.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require 'spec_helper'
-
-module Spree
- module PromotionHandler
- describe Page, type: :model do
- let(:order) { create(:order_with_line_items, line_items_count: 1) }
-
- let(:promotion) { create(:promotion, name: '10% off', path: '10off', store: order.store) }
-
- before do
- calculator = Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10)
- action = Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
- promotion.actions << action
- end
-
- it 'activates at the right path' do
- expect(order.line_item_discounts.count).to eq(0)
- Spree::PromotionHandler::Page.new(order, '10off').activate
- expect(order.line_item_discounts.count).to eq(1)
- end
-
- context 'when promotion is expired' do
- before do
- promotion.update_columns(
- starts_at: 1.week.ago,
- expires_at: 1.day.ago
- )
- end
-
- it 'is not activated' do
- expect(order.line_item_discounts.count).to eq(0)
- Spree::PromotionHandler::Page.new(order, '10off').activate
- expect(order.line_item_discounts.count).to eq(0)
- end
- end
-
- it 'does not activate at the wrong path' do
- expect(order.line_item_discounts.count).to eq(0)
- Spree::PromotionHandler::Page.new(order, 'wrongpath').activate
- expect(order.line_item_discounts.count).to eq(0)
- end
- end
- end
-end
diff --git a/spree/core/spec/models/spree/stock_reservation_spec.rb b/spree/core/spec/models/spree/stock_reservation_spec.rb
index 504d33371e..d07ecb0e1b 100644
--- a/spree/core/spec/models/spree/stock_reservation_spec.rb
+++ b/spree/core/spec/models/spree/stock_reservation_spec.rb
@@ -114,16 +114,6 @@ describe Spree::StockReservation, type: :model do
expect(level.reload.reserved_count).to eq(0)
end
-
- it 'is given back when the cart is emptied' do
- cart = create(:cart_with_line_items, line_items_count: 1)
- cart_reservation = create(:stock_reservation, cart: cart, line_item: cart.line_items.first, quantity: 2)
- cart_level = cart_reservation.stock_level
-
- Spree::Carts::Empty.call(cart: cart)
-
- expect(cart_level.reload.reserved_count).to eq(0)
- end
end
describe 'cleanup via dependent: :destroy' do
diff --git a/spree/core/spec/services/spree/carts/destroy_spec.rb b/spree/core/spec/services/spree/carts/destroy_spec.rb
index ab6fd071be..c243bd37b4 100644
--- a/spree/core/spec/services/spree/carts/destroy_spec.rb
+++ b/spree/core/spec/services/spree/carts/destroy_spec.rb
@@ -109,18 +109,6 @@ module Spree
end
end
- context 'when empty service is called first' do
- before { Spree::Carts::Empty.call(cart: cart) }
-
- it 'destroys the cart' do
- expect(cart.destroyed?).not_to be true
-
- subject
-
- expect(cart.destroyed?).to be true
- end
- end
-
context 'when a gift card is applied' do
let(:gift_card) { create(:gift_card, amount: 50, store: cart.store) }
diff --git a/spree/core/spec/services/spree/carts/empty_spec.rb b/spree/core/spec/services/spree/carts/empty_spec.rb
deleted file mode 100644
index 668323c2d2..0000000000
--- a/spree/core/spec/services/spree/carts/empty_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Carts::Empty do
- subject { described_class.call cart: cart }
-
- context 'when a cart is given' do
- let(:cart) { create(:cart_with_line_items, line_items_count: 2) }
- let(:promotion) { create(:promotion, code: '10off') }
-
- before do
- Spree::OrderPromotion.create!(cart: cart, promotion: promotion)
- end
-
- context 'completed cart' do
- before do
- cart.update_columns(completed_at: Time.current)
- cart.reload
- end
-
- it 'returns failure' do
- expect(subject.success?).to be false
- expect(subject.value).to eq Spree.t(:cannot_empty)
- end
- end
-
- context 'incomplete cart' do
- before { subject }
-
- it 'returns success' do
- expect(subject.success?).to be true
- expect(subject.value).to eq(cart)
- end
-
- it 'clears out line items, typed rows and totals' do
- expect(cart.line_items.count).to be_zero
- expect(cart.discounts.count).to be_zero
- expect(cart.fulfillments.count).to be_zero
- expect(cart.order_promotions.count).to be_zero
- expect(cart.discount_total).to be_zero
- expect(cart.item_total).to be_zero
- expect(cart.delivery_total).to be_zero
- expect(cart.total_quantity).to be_zero
- end
- end
- end
-
- context 'when nil is given' do
- let(:cart) { nil }
-
- before { subject }
-
- it 'returns failure' do
- expect(subject.success?).to be false
- expect(subject.value).to eq Spree.t(:cannot_empty)
- end
- end
-
- context 'with stock reservations' do
- let(:cart) { create(:cart_with_line_items, line_items_count: 1) }
- let(:line_item) { cart.line_items.first }
-
- before do
- line_item.variant.stock_levels.first.update!(backorderable: false)
- line_item.variant.stock_levels.first.set_count_on_hand(10)
- create(
- :stock_reservation,
- stock_level: line_item.variant.stock_levels.first,
- line_item: line_item,
- cart: cart,
- quantity: line_item.quantity,
- expires_at: 5.minutes.from_now
- )
- end
-
- it 'releases all reservations belonging to the cart' do
- expect { described_class.call(cart: cart) }
- .to change { Spree::StockReservation.where(cart_id: cart.id).count }.from(1).to(0)
- end
- end
- end
-end
diff --git a/spree/core/spec/services/spree/payments/create_spec.rb b/spree/core/spec/services/spree/payments/create_spec.rb
deleted file mode 100644
index 497b93c688..0000000000
--- a/spree/core/spec/services/spree/payments/create_spec.rb
+++ /dev/null
@@ -1,155 +0,0 @@
-require 'spec_helper'
-
-module Spree
- describe Payments::Create do
- subject { described_class }
-
- let(:store) { @default_store }
- let(:order) { create(:order_with_totals, store: store, customer: nil, email: '[email protected]') }
-
- let(:execute) { subject.call(order: order, params: params) }
- let(:value) { execute.value }
-
- let(:params) do
- {
- payment_method_id: payment_method.id,
- amount: order.total,
- source_attributes: {
- gateway_payment_profile_id: '12345',
- cc_type: 'visa',
- last_digits: '1111',
- name: 'John',
- month: '12',
- year: '2021'
- }
- }
- end
-
- let!(:payment_method) { create(:credit_card_payment_method) }
- let(:payment_source) { payment_method.payment_source_class.last }
- let(:payment) { order.payments.last }
-
- context 'valid attributes' do
- shared_context 'creates a payment' do
- it 'creates new payment record' do
- expect { execute }.to change(order.payments, :count).by(1)
- expect(payment.payment_method).to eq(payment_method)
- end
-
- it { expect(execute.success?).to eq(true) }
- it { expect(execute.value).to be_kind_of(Spree::Payment) }
- end
-
- shared_context 'creates a payment source' do
- it 'creates new payment source record' do
- expect { execute }.to change(payment_method.payment_source_class, :count).by(1)
- expect(payment.payment_source).to eq(payment_source)
- end
- end
-
- context 'with new source attributes' do
- include_context 'creates a payment'
- include_context 'creates a payment source'
-
- context 'with user' do
- let(:user) { create(:user) }
- let(:order) { create(:order_with_totals, store: store, customer: user) }
-
- include_context 'creates a payment'
- include_context 'creates a payment source'
-
- context 'assigns user' do
- before { execute }
-
- it { expect(payment_source.customer).to eq(user) }
- end
- end
- end
-
- context 'with existing source' do
- let(:params) do
- {
- payment_method_id: payment_method.id,
- amount: order.total,
- source_id: payment_source.id
- }
- end
-
- context 'valid source' do
- let(:user) { create(:user) }
- let(:order) { create(:order_with_totals, store: store, customer: user) }
- let!(:payment_source) { create(:credit_card, payment_method: payment_method, customer: user) }
-
- include_context 'creates a payment'
-
- it { expect { execute }.not_to change(payment_method.payment_source_class, :count) }
- end
-
- context 'source assigned to a different user' do
- let(:user) { create(:user) }
- let(:order) { create(:order_with_totals, store: store, customer: user) }
- let!(:payment_source) { create(:credit_card, payment_method: payment_method, customer: create(:user)) }
-
- it { expect(execute.success?).to eq(false) }
- it { expect(execute.error.to_s).to eq('source_not_found') }
- end
- end
-
- context 'without source' do
- let(:params) do
- {
- payment_method_id: payment_method.id,
- amount: order.total,
- source_id: 'wrong-id'
- }
- end
-
- let(:user) { create(:user) }
- let(:order) { create(:order_with_totals, store: store, customer: user) }
-
- it { expect(execute.success?).to eq(false) }
- it { expect(execute.error.to_s).to eq('source_not_found') }
- end
- end
-
- context 'missing payment method' do
- let(:params) do
- {
- payment_method_id: '',
- amount: order.total,
- source_attributes: {
- gateway_payment_profile_id: '12345',
- cc_type: 'visa',
- last_digits: '1111',
- name: 'John',
- month: '12',
- year: '2021'
- }
- }
- end
-
- it { expect(execute.success?).to eq(false) }
- it { expect(execute.error.to_s).to eq('payment_method_not_found') }
- end
-
- context 'invalid attributes' do
- let(:params) do
- {
- payment_method_id: payment_method.id,
- amount: order.total,
- source_attributes: {
- gateway_payment_profile_id: '',
- cc_type: '',
- last_digits: '',
- name: 'John',
- month: '12',
- year: '2021'
- }
- }
- end
-
- it { expect(execute.success?).to eq(false) }
- it { expect(execute.error.value).to be_kind_of(ActiveModel::Errors) }
- end
- end
-end
diff --git a/spree/core/spec/workflows/spree/fulfillments/fulfill_spec.rb b/spree/core/spec/workflows/spree/fulfillments/fulfill_spec.rb
index 8e9e50f03e..c8ea539041 100644
--- a/spree/core/spec/workflows/spree/fulfillments/fulfill_spec.rb
+++ b/spree/core/spec/workflows/spree/fulfillments/fulfill_spec.rb
@@ -422,7 +422,7 @@ module Spree
end
it 'does not buy twice when a label was bought beforehand' do
- Spree.fulfillment_purchase_label_workflow.call(fulfillment: fulfillment)
+ Spree.shipping_label_purchase_workflow.call(owner: fulfillment)
subject.call(fulfillment: fulfillment)
diff --git a/spree/core/spec/workflows/spree/fulfillments/purchase_label_spec.rb b/spree/core/spec/workflows/spree/fulfillments/purchase_label_spec.rb
deleted file mode 100644
index 0730d6cc09..0000000000
--- a/spree/core/spec/workflows/spree/fulfillments/purchase_label_spec.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-require 'spec_helper'
-require 'spree/testing_support/label_provider'
-
-module Spree
- describe Fulfillments::PurchaseLabel do
- subject { described_class }
-
- let(:store) { @default_store }
- let(:order) { create(:order_ready_to_ship, store: store) }
- let(:fulfillment) { order.fulfillments.first }
-
- before do
- Spree::TestingSupport::LabelProvider.reset!
- allow(fulfillment).to receive(:provider).and_return(Spree::TestingSupport::LabelProvider.new)
- allow(SsrfFilter).to receive(:get).and_raise(SocketError.new('offline'))
- # The factory seeds a tracking number; a parcel awaiting its label has none.
- fulfillment.deliveries.destroy_all
- end
-
- it 'buys the label and attaches tracking without fulfilling' do
- result = subject.call(fulfillment: fulfillment)
-
- expect(result).to be_success
- expect(fulfillment.reload.tracking).to eq('1Z879E930346834440')
- expect(fulfillment.active_shipping_label).to be_present
- expect(fulfillment).to be_unfulfilled
- end
-
- it 'pins the carrier the provider sold the label for' do
- subject.call(fulfillment: fulfillment)
-
- expect(fulfillment.reload.primary_delivery.carrier).to eq('ups')
- end
-
- # The one-click fulfill degrades a label failure; here nothing has left
- # the building, so failing loudly is the point.
- it 'fails when the provider cannot produce a label' do
- allow(fulfillment.provider).to receive(:purchase_label).and_return(nil)
-
- result = subject.call(fulfillment: fulfillment)
-
- expect(result).to be_failure
- expect(result.error.to_s).to eq(Spree.t('fulfillments.errors.label_purchase_failed'))
- expect(fulfillment.reload).to be_unfulfilled
- end
-
- it 'refuses a provider without labels' do
- allow(fulfillment).to receive(:provider).and_return(Spree::FulfillmentProvider::Manual.new)
-
- result = subject.call(fulfillment: fulfillment)
-
- expect(result).to be_failure
- expect(result.error.to_s).to eq(Spree.t('shipping_labels.errors.provider_has_no_labels'))
- end
-
- it 'refuses a second label while one is active' do
- subject.call(fulfillment: fulfillment)
-
- result = subject.call(fulfillment: fulfillment)
-
- expect(result).to be_failure
- expect(result.error.to_s).to eq(Spree.t('shipping_labels.errors.already_purchased'))
- end
-
- it 'refuses a fulfillment that already shipped' do
- fulfillment.update!(status: 'fulfilled')
-
- expect(subject.call(fulfillment: fulfillment)).to be_failure
- end
-
- it 'binds the label to a merchant-entered tracking number' do
- Spree::Deliveries::Create.new.call(owner: fulfillment, tracking_number: '1Z879E930346834440')
-
- subject.call(fulfillment: fulfillment)
-
- expect(fulfillment.reload.deliveries.count).to eq(1)
- expect(fulfillment.primary_delivery.shipping_label).to be_present
- end
-
- describe 'hooks' do
- before { Spree.hooks.clear! }
- after { Spree.hooks.clear! }
-
- it 'runs its own hooks around the purchase' do
- seen = []
- Spree.hooks.register('fulfillments.purchase_label.after_purchase_label') { |flow| seen << flow.fulfillment }
-
- subject.call(fulfillment: fulfillment)
-
- expect(seen).to eq([fulfillment])
- end
- end
- end
-end
diff --git a/spree/core/spec/workflows/spree/returns/purchase_label_spec.rb b/spree/core/spec/workflows/spree/returns/purchase_label_spec.rb
deleted file mode 100644
index cd48c1e234..0000000000
--- a/spree/core/spec/workflows/spree/returns/purchase_label_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require 'spec_helper'
-require 'spree/testing_support/label_provider'
-
-module Spree
- describe Returns::PurchaseLabel do
- subject { described_class }
-
- let(:store) { @default_store }
- let(:return_record) { create(:return, order: create(:shipped_order, store: store)) }
-
- before do
- Spree::TestingSupport::LabelProvider.reset!
- allow(return_record).to receive(:provider).and_return(Spree::TestingSupport::LabelProvider.new)
- allow(SsrfFilter).to receive(:get).and_raise(SocketError.new('offline'))
- end
-
- it 'buys the return label and records the inbound consignment' do
- result = subject.call(return_record: return_record)
-
- expect(result).to be_success
- expect(return_record.reload.active_shipping_label.tracking_number).to eq('1Z879E930346834440')
- expect(return_record.deliveries.first.tracking_number).to eq('1Z879E930346834440')
- expect(return_record).to be_requested
- end
-
- it 'passes the purchase failure through' do
- allow(return_record.provider).to receive(:purchase_label).and_return(nil)
-
- result = subject.call(return_record: return_record)
-
- expect(result).to be_failure
- expect(result.error.to_s).to eq(Spree.t('fulfillments.errors.label_purchase_failed'))
- end
-
- it 'ships through the provider of the outbound parcel' do
- allow(return_record).to receive(:provider).and_call_original
-
- expect(return_record.provider).to be_a(Spree::FulfillmentProvider::Base)
- end
- end
-end