Module: Workarea::Factories
- Included in:
- IntegrationTest, MailerTest, PerformanceTest, SystemTest, TestCase, ViewTest
- Defined in:
- lib/workarea/testing/factories.rb,
lib/workarea/testing/factories/user.rb,
lib/workarea/testing/factories/order.rb,
lib/workarea/testing/factories/search.rb,
lib/workarea/testing/factories/catalog.rb,
lib/workarea/testing/factories/comment.rb,
lib/workarea/testing/factories/content.rb,
lib/workarea/testing/factories/metrics.rb,
lib/workarea/testing/factories/payment.rb,
lib/workarea/testing/factories/pricing.rb,
lib/workarea/testing/factories/segment.rb,
lib/workarea/testing/factories/insights.rb,
lib/workarea/testing/factories/data_file.rb,
lib/workarea/testing/factories/navigation.rb,
lib/workarea/testing/factories/bulk_action.rb,
lib/workarea/testing/factories/fulfillment.rb,
lib/workarea/testing/factories/recommendation.rb,
lib/workarea/testing/factories/performance/catalog.rb
Defined Under Namespace
Modules: BulkAction, Catalog, Comment, Content, DataFile, Fulfillment, Insights, Metrics, Navigation, Order, Payment, Performance, Pricing, Recommendation, Search, Segment, User
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.add(mod) ⇒ Object
12
13
14
15
|
# 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) ⇒ Object
17
18
19
20
|
# 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 ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# 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
|
Instance Method Details
#create_admin_bookmark(overrides = {}) ⇒ Object
135
136
137
138
|
# 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 = {}) ⇒ Object
130
131
132
133
|
# 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 = {}) ⇒ Object
125
126
127
128
|
# 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 = {}) ⇒ Object
63
64
65
66
67
68
|
# 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 = {}) ⇒ Object
115
116
117
118
|
# 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 = {}) ⇒ Object
107
108
109
110
111
112
113
|
# 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 = {}) ⇒ Object
58
59
60
61
|
# 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 = {}) ⇒ Object
70
71
72
73
|
# 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 = {}) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# 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 = {}) ⇒ Object
120
121
122
123
|
# 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 = {}) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# 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) ⇒ Object
140
141
142
143
144
|
# 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) ⇒ Object
42
43
44
45
|
# 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 ⇒ Object
38
39
40
|
# File 'lib/workarea/testing/factories.rb', line 38
def factory_defaults_config
Workarea.config.testing_factory_defaults
end
|