Sha256: b670b18030e208e32bab7be67f7031e1a6dfca9deff234c3b3e7fba7f5b5d83f

Contents?: true

Size: 1.19 KB

Versions: 69

Compression:

Stored size: 1.19 KB

Contents

FactoryBot.define do
  factory :base_product, class: Spree::Product do
    sequence(:name)   { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
    description       { generate(:random_description) }
    price             { 19.99 }
    cost_price        { 17.00 }
    sku               { generate(:sku) }
    available_on      { 1.year.ago }
    deleted_at        { nil }
    shipping_category { |r| Spree::ShippingCategory.first || r.association(:shipping_category) }

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

    factory :custom_product do
      name  { 'Custom Product' }
      price { 17.99 }

      tax_category { |r| Spree::TaxCategory.first || r.association(:tax_category) }
    end

    factory :product do
      tax_category { |r| Spree::TaxCategory.first || r.association(:tax_category) }

      factory :product_in_stock do
        after :create do |product|
          product.master.stock_items.first.adjust_count_on_hand(10)
        end
      end

      factory :product_with_option_types do
        after(:create) { |product| create(:product_option_type, product: product) }
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
spree_core-4.1.3 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.2 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.1 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.0 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.0.rc3 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.0.rc2 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.1.0.rc1 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.10 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.3 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.9 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.2 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.8 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.1 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.7 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.0 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.0.rc3 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.6 lib/spree/testing_support/factories/product_factory.rb
spree_core-3.7.5 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.0.rc2 lib/spree/testing_support/factories/product_factory.rb
spree_core-4.0.0.rc1 lib/spree/testing_support/factories/product_factory.rb