Sha256: 62eca56bfdb6c9ecda3e303bc81a6a281e0cc1ae830c1ebc86955e3deb0807c5

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

FactoryBot.define do
  sequence(:random_float) { BigDecimal("#{rand(200)}.#{rand(99)}") }

  factory :base_variant, class: Spree::Variant do
    price           { 19.99 }
    cost_price      { 17.00 }
    sku             { generate(:sku) }
    weight          { generate(:random_float) }
    height          { generate(:random_float) }
    width           { generate(:random_float) }
    depth           { generate(:random_float) }
    is_master       { 0 }
    track_inventory { true }

    product       { |p| p.association(:base_product, stores: [create(:store)]) }
    option_values { [create(:option_value)] }

    # ensure stock item will be created for this variant
    before(:create) { create(:stock_location) unless Spree::StockLocation.any? }

    factory :variant do
      # on_hand 5
      product { |p| p.association(:product, stores: [create(:store)]) }
    end

    factory :master_variant do
      is_master { 1 }
    end

    factory :on_demand_variant do
      track_inventory { false }

      factory :on_demand_master_variant do
        is_master { 1 }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_core-4.3.3 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.4.1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.4.0 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.4.0.rc2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.4.0.rc1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.0 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.0.rc3 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.0.rc2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.3.0.rc1 lib/spree/testing_support/factories/variant_factory.rb