Sha256: 5755a8626b22aeadb3f788f0a0204ffeae82915007dd7f8aaba0a72af3e95039

Contents?: true

Size: 1.65 KB

Versions: 48

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/sequences'
require 'spree/testing_support/factories/shipping_category_factory'
require 'spree/testing_support/factories/stock_location_factory'
require 'spree/testing_support/factories/tax_category_factory'
require 'spree/testing_support/factories/product_option_type_factory'

FactoryBot.define do
  factory :base_product, class: 'Spree::Product' do
    sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
    description { "As seen on TV!" }
    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) if Spree::StockLocation.count == 0 }

    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

        factory :product_not_backorderable do
          after :create do |product|
            product.master.stock_items.first.update_column(:backorderable, false)
          end
        end
      end

      factory :product_with_option_types do
        after(:create) { |product| create(:product_option_type, product: product) }
      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/product_factory.rb
solidus_core-2.11.3 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.11.2 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.11.1 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.10.3 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.11.0 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.10.2 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.9.6 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.8.6 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.10.1 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.9.5 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.10.0 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.9.4 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.6.6 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.7.4 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.8.5 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.9.3 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.9.2 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.10.0.beta1 lib/spree/testing_support/factories/product_factory.rb
solidus_core-2.7.3 lib/spree/testing_support/factories/product_factory.rb