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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Act on the review of the workflow conversions
Damian Legawiece69359522f98
diff --git a/spree/api/spec/controllers/spree/api/v3/resource_controller_spec.rb b/spree/api/spec/controllers/spree/api/v3/resource_controller_spec.rbindex 337c59e605..5059e6f071 100644--- a/spree/api/spec/controllers/spree/api/v3/resource_controller_spec.rb+++ b/spree/api/spec/controllers/spree/api/v3/resource_controller_spec.rb@@ -78,17 +78,15 @@ RSpec.describe Spree::Api::V3::ResourceController, type: :controller doend# build_resource builds through the owner's association so a record carries- # its tenancy from where it was built. The association is found by asking- # the reflections which one points at the model, not by inflecting its name.- describe 'store association resolution' do+ # its tenancy from where it was built. The association is found by asking the+ # reflections which one points at the model, not by inflecting its name.+ #+ # Drives the controller's own method rather than a copy of it, so a+ # regression in the production logic fails these examples.+ describe '#store_association' dodef resolve(model_class)- reflections = Spree::Store.reflect_on_all_associations(:has_many).select do |reflection|- !reflection.nested? && (reflection.klass == model_class rescue false)- end- return reflections.first&.name if reflections.one?-- conventional = model_class.model_name.element.pluralize.to_sym- reflections.find { |reflection| reflection.name == conventional }&.name+ allow(controller).to receive(:model_class).and_return(model_class)+ controller.send(:store_association)endit 'resolves a model whose association is the plural of its name' dodiff --git a/spree/core/app/jobs/spree/imports/process_job.rb b/spree/core/app/jobs/spree/imports/process_job.rbindex 801954ddf6..864a2830e2 100644--- a/spree/core/app/jobs/spree/imports/process_job.rb+++ b/spree/core/app/jobs/spree/imports/process_job.rb@@ -25,7 +25,13 @@ module Spreeunless skip_row_creationstep :begin_processing do- Spree.import_start_processing_workflow.call(import: @import) if @import.status != 'processing'+ if @import.status != 'processing'+ result = Spree.import_start_processing_workflow.call(import: @import)+ # Row creation must not start from an import the workflow+ # refused to move; raising fails the job rather than building+ # rows against a status that never advanced.+ raise ActiveRecord::RecordInvalid, @import if result.failure?+ endendstep :create_rows, start: 1# A permanent CSV failure marked the import failed inside the stepdiff --git a/spree/core/app/services/spree/sample_data/import_runner.rb b/spree/core/app/services/spree/sample_data/import_runner.rbindex 2a14840d7d..42a396201a 100644--- a/spree/core/app/services/spree/sample_data/import_runner.rb+++ b/spree/core/app/services/spree/sample_data/import_runner.rb@@ -25,8 +25,11 @@ module Spreeinline: inline, skip_events: skip_events)- Spree.import_start_mapping_workflow.call(import: import)- Spree.import_complete_mapping_workflow.call(import: import)+ mapping = Spree.import_start_mapping_workflow.call(import: import)+ return failure(import, mapping.error) if mapping.failure?++ completed = Spree.import_complete_mapping_workflow.call(import: import)+ return failure(import, completed.error) if completed.failure?success(import.reload)enddiff --git a/spree/core/app/workflows/spree/gift_cards/cancel.rb b/spree/core/app/workflows/spree/gift_cards/cancel.rbindex cababe8234..3962223aaf 100644--- a/spree/core/app/workflows/spree/gift_cards/cancel.rb+++ b/spree/core/app/workflows/spree/gift_cards/cancel.rb@@ -27,9 +27,12 @@ module Spreedef ensure_cancellablefailure(gift_card, :gift_card_already_canceled) if gift_card.canceled?- return if gift_card.status == 'active'+ failure(gift_card, :gift_card_already_redeemed) unless gift_card.status == 'active'- failure(gift_card, :gift_card_already_redeemed)+ # A card drawn against by Spree::GiftCards::Apply keeps the active+ # status until the order that spent it completes, so status alone+ # would let a card funding a live checkout be cancelled underneath it.+ failure(gift_card, :gift_card_already_redeemed) unless gift_card.amount_used.zero?enddef mark_canceleddiff --git a/spree/core/app/workflows/spree/imports/start_mapping.rb b/spree/core/app/workflows/spree/imports/start_mapping.rbindex 526b55c770..993d6dc153 100644--- a/spree/core/app/workflows/spree/imports/start_mapping.rb+++ b/spree/core/app/workflows/spree/imports/start_mapping.rb@@ -5,6 +5,10 @@ module Spree## Reading the file is where a malformed CSV shows up, so the caller sees# the parse error from here rather than from a later step.+ #+ # Deliberately not guarded on `pending`: mappings are extended as columns+ # are discovered — the product importer re-runs this to pick up custom+ # field columns — and `find_or_create_by!` makes a second pass additive.class StartMapping < Spree::Workflowhooks :validate, :after_start_mappingdiff --git a/spree/core/spec/workflows/spree/gift_cards/cancel_spec.rb b/spree/core/spec/workflows/spree/gift_cards/cancel_spec.rbindex cb8c706272..2d8428fdf1 100644--- a/spree/core/spec/workflows/spree/gift_cards/cancel_spec.rb+++ b/spree/core/spec/workflows/spree/gift_cards/cancel_spec.rb@@ -26,6 +26,17 @@ RSpec.describe Spree::GiftCards::Cancel doendend+ # Apply draws the balance down but leaves the status active until the order+ # completes, so a card funding a live checkout must not be cancellable.+ context 'when the card has been drawn against but not yet redeemed' do+ before { gift_card.update!(amount_used: 20) }++ it 'refuses' do+ expect(subject).not_to be_success+ expect(gift_card.reload.status).to eq('active')+ end+ end+context 'when already canceled' dobefore { gift_card.update!(status: 'canceled') }