Sha256: a598f6cdd35f4c069a04ff8429e4c670b08e5446f2901095b55d79af7cf34a41

Contents?: true

Size: 1.33 KB

Versions: 56

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factory_bot'
Spree::TestingSupport::FactoryBot.when_cherry_picked do
  Spree::TestingSupport::FactoryBot.deprecate_cherry_picking

  require 'spree/testing_support/sequences'
  require 'spree/testing_support/factories/option_value_factory'
  require 'spree/testing_support/factories/option_type_factory'
  require 'spree/testing_support/factories/product_factory'
end

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) }
    is_master { 0 }
    track_inventory { true }

    product { |p| p.association(:base_product) }

    # ensure stock item will be created for this variant
    before(:create) { create(:stock_location) if Spree::StockLocation.count == 0 }

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

    factory :master_variant do
      is_master { 1 }
      before(:create){ |variant| variant.product.master = variant }
      product { build(:base_product) }
    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

56 entries across 56 versions & 1 rubygems

Version Path
solidus_core-3.4.6 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.5 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.4 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.3.4 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.9 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.8 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.3.3 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.3 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.2 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.7 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.3.2 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.1 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.4.0 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.3.1 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.6 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.1.9 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.3.0 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.5 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.4 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-3.2.3 lib/spree/testing_support/factories/variant_factory.rb