diff --git a/backend/spec/controllers/spree/admin/promotions_controller_spec.rb b/backend/spec/controllers/spree/admin/promotions_controller_spec.rb index 59825eabd6a..a381288bd76 100644 --- a/backend/spec/controllers/spree/admin/promotions_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/promotions_controller_spec.rb @@ -5,9 +5,11 @@ describe Spree::Admin::PromotionsController, type: :controller do stub_authorization! - let!(:promotion1) { create(:promotion, name: "name1", code: "code1", path: "path1") } - let!(:promotion2) { create(:promotion, name: "name2", code: "code2", path: "path2") } - let!(:promotion3) { create(:promotion, name: "name2", code: "code3", path: "path3", expires_at: Date.yesterday) } + let!(:promotion1) { create(:promotion, :with_action, name: "name1", code: "code1", path: "path1") } + let!(:promotion2) { create(:promotion, :with_action, name: "name2", code: "code2", path: "path2") } + let!(:promotion3) do + create(:promotion, :with_action, name: "name2", code: "code3", path: "path3", expires_at: Date.yesterday) + end let!(:category) { create :promotion_category } describe "#show" do diff --git a/core/lib/spree/testing_support/factories/promotion_factory.rb b/core/lib/spree/testing_support/factories/promotion_factory.rb index 31b7d9e837b..fe76fff67bb 100644 --- a/core/lib/spree/testing_support/factories/promotion_factory.rb +++ b/core/lib/spree/testing_support/factories/promotion_factory.rb @@ -16,6 +16,12 @@ end end + trait :with_action do + after(:create) do |promotion, _evaluator| + promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new + end + end + trait :with_line_item_adjustment do transient do adjustment_rate { 10 } diff --git a/core/spec/models/spree/product_spec.rb b/core/spec/models/spree/product_spec.rb index 89d452b5b1b..4888084b7e6 100644 --- a/core/spec/models/spree/product_spec.rb +++ b/core/spec/models/spree/product_spec.rb @@ -456,18 +456,13 @@ class Extension < Spree::Base # Regression test for https://github.com/spree/spree/issues/4416 context "#possible_promotions" do - let!(:promotion) do - create(:promotion, advertise: true, starts_at: 1.day.ago) - end + let!(:promotion) { create(:promotion, :with_action, advertise: true, starts_at: 1.day.ago) } let!(:rule) do Spree::Promotion::Rules::Product.create( promotion: promotion, products: [product] ) end - before do - promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new - end it "lists the promotion as a possible promotion" do expect(product.possible_promotions).to include(promotion)