module Workarea::Factories
Public Class Methods
add(mod)
click to toggle source
# File lib/workarea/testing/factories.rb, line 12 def self.add(mod) self.plugins << mod included_in.each { |c| plugins.each { |p| c.include p } } end
included(mod)
click to toggle source
# File lib/workarea/testing/factories.rb, line 17 def self.included(mod) included_in << mod plugins.each { |p| mod.send(:include, p) } end
require_factories()
click to toggle source
# File lib/workarea/testing/factories.rb, line 22 def self.require_factories core_factories = Workarea::Testing::Engine .root .join('lib', 'workarea', 'testing', 'factories', '**', '*.rb') Dir[core_factories].each do |factory_file| require factory_file end Workarea::Plugin.installed.each do |plugin| Dir[plugin.root.join('test', 'factories', '**', '*.rb')].each do |factory_file| require factory_file end end end
Public Instance Methods
create_admin_bookmark(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 135 def create_admin_bookmark(overrides = {}) attributes = factory_defaults(:admin_bookmark).merge(overrides) Workarea::User::AdminBookmark.create!(attributes) end
create_admin_visit(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 130 def create_admin_visit(overrides = {}) attributes = factory_defaults(:admin_visit).merge(overrides) Workarea::User::AdminVisit.create!(attributes) end
create_audit_log_entry(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 125 def create_audit_log_entry(overrides = {}) attributes = factory_defaults(:audit_log_entry).merge(overrides) Mongoid::AuditLog::Entry.create!(attributes) end
create_email_signup(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 63 def create_email_signup(overrides = {}) attributes = factory_defaults(:email_signup).merge(overrides) Email::Signup.create!(attributes).tap do Factories.email_signup_count += 1 end end
create_help_article(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 115 def create_help_article(overrides = {}) attributes = factory_defaults(:help_article).merge(overrides) Help::Article.create!(attributes) end
create_inventory(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 107 def create_inventory(overrides = {}) attributes = factory_defaults(:inventory).merge(overrides) Inventory::Sku.new(attributes).tap do |sku| sku.id = attributes[:id] if attributes[:id].present? sku.save! end end
create_release(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 58 def create_release(overrides = {}) attributes = factory_defaults(:release).merge(overrides) Release.create!(attributes) end
create_shipping(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 70 def create_shipping(overrides = {}) attributes = factory_defaults(:shipping).merge(overrides) Shipping.create!(attributes) end
create_shipping_service(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 75 def create_shipping_service(overrides = {}) attributes = factory_defaults(:shipping_service).merge(overrides) Shipping::Service.new(attributes.except(:rates)).tap do |service| if attributes[:rates].present? attributes[:rates].each do |attrs| service.rates.build(attrs) end end service.save! Factories.shipping_service_count += 1 end end
create_shipping_sku(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 120 def create_shipping_sku(overrides = {}) attributes = factory_defaults(:shipping_sku).merge(overrides) Shipping::Sku.create!(attributes) end
create_tax_category(overrides = {})
click to toggle source
# File lib/workarea/testing/factories.rb, line 90 def create_tax_category(overrides = {}) attributes = factory_defaults(:tax_category).merge(overrides) Tax::Category.new(attributes.except(:rates)).tap do |category| if attributes[:rates].present? attributes[:rates].each do |attrs| category.rates.build(attrs) end end category.save! category.rates.each(&:save!) Factories.tax_categories_count += 1 end end
create_tempfile(content, name: 'foo', extension: 'txt', encoding: nil)
click to toggle source
# File lib/workarea/testing/factories.rb, line 140 def create_tempfile(content, name: 'foo', extension: 'txt', encoding: nil) file = Tempfile.new([name, ".#{extension}"], encoding: encoding) file.write(content) file.tap(&:close) end
factory_defaults(factory)
click to toggle source
# File lib/workarea/testing/factories.rb, line 42 def factory_defaults(factory) default = factory_defaults_config.send(factory) default.respond_to?(:call) ? self.instance_eval(&default) : default end
factory_defaults_config()
click to toggle source
# File lib/workarea/testing/factories.rb, line 38 def factory_defaults_config Workarea.config.testing_factory_defaults end