Sha256: c10a94592f4463f3640d721c2fabc9ac08369280a06905e4811be702df361ecd

Contents?: true

Size: 1.8 KB

Versions: 20

Compression:

Stored size: 1.8 KB

Contents

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

    transient do
      code nil
    end
    before(:create) do |promotion, evaluator|
      if evaluator.code
        promotion.codes << build(:promotion_code, promotion: promotion, value: evaluator.code)
      end
    end

    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!(
          promotion: promotion,
          preferred_operator: 'gte',
          preferred_amount: evaluator.item_total_threshold_amount
        )
        promotion.rules << rule
        promotion.save!
      end
    end
    factory :promotion_with_item_total_rule, traits: [:with_item_total_rule]

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
solidus_core-1.1.4 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.7 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.6 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.3 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.5 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.4 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.2 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.3 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.1 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.0 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.0.pre2 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.0.pre1 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.1.0.beta1 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.2 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.1 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.0 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.0.rc2 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.0.rc1 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.0.pre3 lib/spree/testing_support/factories/promotion_factory.rb
solidus_core-1.0.0.pre2 lib/spree/testing_support/factories/promotion_factory.rb