Sha256: b68f15834274f2545e18bb310d1095dc4616f223dd09fe7ab347e8c9cd580d57

Contents?: true

Size: 1.67 KB

Versions: 62

Compression:

Stored size: 1.67 KB

Contents

FactoryGirl.define do
  factory :promotion, class: Spree::Promotion do
    name 'Promo'

    trait :with_line_item_adjustment do
      transient do
        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
    end
    factory :promotion_with_item_adjustment, traits: [:with_line_item_adjustment]

    trait :with_order_adjustment do
      transient do
        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
    end
    factory :promotion_with_order_adjustment, traits: [:with_order_adjustment]

    trait :with_item_total_rule do
      transient do
        item_total_threshold_amount 10
      end

      after(:create) do |promotion, evaluator|
        rule = Spree::Promotion::Rules::ItemTotal.create!(
          preferred_operator_min: 'gte',
          preferred_operator_max: 'lte',
          preferred_amount_min: evaluator.item_total_threshold_amount,
          preferred_amount_max: evaluator.item_total_threshold_amount + 100
        )
        promotion.rules << rule
        promotion.save!
      end
    end
    factory :promotion_with_item_total_rule, traits: [:with_item_total_rule]

  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
spree_core-3.1.14 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.13 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.4 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.2.7 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.12 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.3 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.2.6 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.11 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.10 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.2 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.2.5 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.9 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.1 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.2.4 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.8 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.0 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.0.rc4 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.3.0.rc3 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.1.7 lib/spree/testing_support/factories/promotion_factory.rb
spree_core-3.2.3 lib/spree/testing_support/factories/promotion_factory.rb