Skip to content

Commit

Permalink
Make Promotion factory adjustment trait more flexible
Browse files Browse the repository at this point in the history
Currently, we do not have a factory for Promotion Actions, and so this
trait is used instead. Add more flexibility on the action and calculator
class used is useful for when making new Promotion Actions.
  • Loading branch information
RyanofWoods committed Oct 20, 2022
1 parent d54172b commit ad9c0fa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/lib/spree/testing_support/factories/promotion_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
trait :with_line_item_adjustment do
transient do
adjustment_rate { 10 }
calculator_class { Spree::Calculator::FlatRate }
promotion_action_class { Spree::Promotion::Actions::CreateItemAdjustments }
end

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

Expand Down

0 comments on commit ad9c0fa

Please sign in to comment.