module Workarea::Factories::Catalog
Public Class Methods
product_image_file()
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 61 def self.product_image_file IO.read(product_image_file_path) end
product_image_file_path()
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 57 def self.product_image_file_path Testing::Engine.root.join('lib', 'workarea', 'testing', 'product_image.jpg') end
Public Instance Methods
create_category(overrides = {})
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 6 def create_category(overrides = {}) attributes = factory_defaults(:category).merge(overrides) Workarea::Catalog::Category.create!(attributes) end
create_product(overrides = {})
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 11 def create_product(overrides = {}) attributes = factory_defaults(:product).merge(overrides) Workarea::Catalog::Product.new(attributes.except(:variants)).tap do |product| product.id = attributes[:id] if attributes[:id].present? if attributes[:variants].present? attributes[:variants].each do |attrs| pricing_attrs = [ :regular, :sale, :msrp, :on_sale, :tax_code, :discountable ] sku = Workarea::Pricing::Sku.find_or_create_by(id: attrs[:sku]) sku.attributes = attrs.slice( :on_sale, :tax_code, :discountable ) sku.prices.build(attrs.slice(:regular, :sale, :msrp)) sku.save! variant_attrs = attrs.except(*pricing_attrs) product.variants.build(variant_attrs) end end product.save! end end
create_product_placeholder_image(overrides = {})
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 42 def create_product_placeholder_image(overrides = {}) attributes = factory_defaults(:product_placeholder_image) Workarea::Catalog::ProductPlaceholderImage.create!( attributes.merge(overrides) ) end
product_image_file()
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 53 def product_image_file Factories::Catalog.product_image_file end
product_image_file_path()
click to toggle source
# File lib/workarea/testing/factories/catalog.rb, line 49 def product_image_file_path Factories::Catalog.product_image_file_path end