Sha256: 953477c422d2d447fa1970fc00fe00f27197e5faefc778c504cadb5a60712573

Contents?: true

Size: 1.16 KB

Versions: 48

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

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'

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

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.11.3 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.11.2 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.11.1 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.10.3 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.11.0 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.10.2 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.9.6 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.8.6 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.10.1 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.9.5 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.10.0 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.9.4 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.6.6 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.7.4 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.8.5 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.9.3 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.9.2 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.10.0.beta1 lib/spree/testing_support/factories/variant_factory.rb
solidus_core-2.7.3 lib/spree/testing_support/factories/variant_factory.rb