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
Fix failing specs for PromotionDuplicator
Damian Kaczmarczyk19ebe42e9a84
diff --git a/backend/spec/controllers/spree/admin/promotions_controller_spec.rb b/backend/spec/controllers/spree/admin/promotions_controller_spec.rbindex 7b8e9824d3..b3b3afd171 100644--- a/backend/spec/controllers/spree/admin/promotions_controller_spec.rb+++ b/backend/spec/controllers/spree/admin/promotions_controller_spec.rb@@ -55,8 +55,8 @@ describe Spree::Admin::PromotionsController, type: :controller dosubjectnew_promo = Spree::Promotion.lastexpect(new_promo.name).to eq 'New name1'- expect(new_promo.code).to eq 'code1_new'- expect(new_promo.path).to eq 'path1_new'+ expect(new_promo.code).to match(/code1_[a-zA-Z]{4}/)+ expect(new_promo.path).to match(/path1_[a-zA-Z]{4}/)endend@@ -68,7 +68,11 @@ describe Spree::Admin::PromotionsController, type: :controller dolet!(:promotion3) { create(:promotion, name: 'Name3', code: 'code3', path: '') }before do- create(:promotion, name: 'Name4', code: 'code4', path: '_new') # promotion 4+ promotion_duplicator_mock = Spree::PromotionHandler::PromotionDuplicator.new(promotion3, random_string: "ABCD")+ allow(Spree::PromotionHandler::PromotionDuplicator).to receive(:new).+ with(promotion3).and_return(promotion_duplicator_mock)++ create(:promotion, name: 'Name4', code: 'code4', path: '_ABCD') # promotion 4endit 'doesnt create a copy of promotion' dodiff --git a/core/app/models/spree/promotion_handler/promotion_duplicator.rb b/core/app/models/spree/promotion_handler/promotion_duplicator.rbindex e57140a173..f6d45b8858 100644--- a/core/app/models/spree/promotion_handler/promotion_duplicator.rb+++ b/core/app/models/spree/promotion_handler/promotion_duplicator.rb@@ -1,16 +1,16 @@module Spreemodule PromotionHandlerclass PromotionDuplicator- def initialize(promotion)+ def initialize(promotion, random_string: nil)@promotion = promotion+ @random_string = random_string || generate_random_string(4)enddef duplicate@new_promotion = @promotion.dup- random_string = generate_random_string(4)- @new_promotion.path = "#{@promotion.path}_#{random_string}"+ @new_promotion.path = "#{@promotion.path}_#{@random_string}"@new_promotion.name = "New #{@promotion.name}"- @new_promotion.code = "#{@promotion.code}_#{random_string}"+ @new_promotion.code = "#{@promotion.code}_#{@random_string}"ActiveRecord::Base.transaction do@new_promotion.save