Sha256: 1edc0d9df6e0fcc4d769c2a4ed6e012658e73906d10cbd020c3b3dfb9df0ae68

Contents?: true

Size: 1.3 KB

Versions: 16

Compression:

Stored size: 1.3 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? }

    after(:create) do |variant|
      Spree::StockLocation.all.each { |stock_location| stock_location.propagate_variant(variant) }
    end

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

      factory :with_image_variant do
        images { create_list(:image, 1) }
      end
    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

16 entries across 16 versions & 1 rubygems

Version Path
spree_core-4.10.1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.10.0 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.9.0 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.8.3 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.8.2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.7.3 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.6 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.5 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.7.2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.7.1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.4 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.7.0 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.3 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.2 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.1 lib/spree/testing_support/factories/variant_factory.rb
spree_core-4.6.0 lib/spree/testing_support/factories/variant_factory.rb