Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flexible with_adjustable_action trait to Promotion factory #4682

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions core/lib/spree/testing_support/factories/promotion_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
end

trait :with_action do
after(:create) do |promotion, _evaluator|
promotion.actions << Spree::Promotion::Actions::CreateAdjustment.new
transient do
promotion_action_class { Spree::Promotion::Actions::CreateAdjustment }
end

after(:create) do |promotion, evaluator|
promotion.actions << evaluator.promotion_action_class.new
end
end

Expand All @@ -48,11 +52,8 @@
adjustment_rate { 10 }
end

after(:create) do |promotion, evaluator|
calculator = Spree::Calculator::FlatRate.new
calculator.preferred_amount = evaluator.adjustment_rate
Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promotion)
end
with_adjustable_action
preferred_amount { adjustment_rate }
end

factory :promotion_with_item_adjustment, traits: [:with_line_item_adjustment]
Expand All @@ -68,14 +69,11 @@
weighted_order_adjustment_amount { 10 }
end

after(:create) do |promotion, evaluator|
calculator = Spree::Calculator::FlatRate.new
calculator.preferred_amount = evaluator.weighted_order_adjustment_amount
action = Spree::Promotion::Actions::CreateAdjustment.create!(calculator: calculator)
promotion.actions << action
promotion.save!
end
with_adjustable_action
preferred_amount { weighted_order_adjustment_amount }
promotion_action_class { Spree::Promotion::Actions::CreateAdjustment }
end

factory :promotion_with_order_adjustment, traits: [:with_order_adjustment]

trait :with_item_total_rule do
Expand Down