/
products.rb
144 lines (129 loc) · 4.13 KB
/
products.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
FactoryGirl.define do
factory :product do
sequence(:name) { |n| "Product #{n}" }
sequence(:identifier) { |n| "product-#{n}" }
sequence(:cpe) { |n| "cpe:/o:product:#{n}" }
sequence(:shortname) { |n| "Product #{n}" }
sequence(:friendly_name) { |n| "Product #{n}" }
sequence(:product_class) { |n| n.to_s.ljust(5, 'A') }
free false
product_type :base
sequence(:description) { FFaker::Lorem.sentence }
release_type ''
version 42
arch 'x86_64'
release_stage 'released'
transient do
base_products []
root_product nil
recommended false
migration_kind :online
predecessors [ ]
end
after :create do |product, evaluator|
evaluator.base_products.each do |base_product|
product.product_extensions_associations << ProductsExtensionsAssociation.create(
product: base_product,
root_product: evaluator.root_product || base_product,
recommended: evaluator.recommended
)
end
evaluator.predecessors.each do |predecessor|
ProductPredecessorAssociation.create(product_id: product.id,
predecessor_id: predecessor.id, kind: evaluator.migration_kind)
end
end
trait :extension do
product_type 'extension'
end
trait :module do
product_type 'module'
free true
end
trait :with_extensions do
after :create do |product, _evaluator|
5.times do
create(:product, :extension, base_products: [product])
end
end
end
trait :with_mirrored_extensions do
after :create do |product, _evaluator|
5.times do
create(:product, :extension, :with_mirrored_repositories, base_products: [product])
end
end
end
trait :with_recommended_extensions do
after :create do |product, _evaluator|
5.times do
create(:product, :extension, :with_not_mirrored_repositories, base_products: [product], recommended: true)
end
end
end
trait :with_enabled_recommended_extensions do
after :create do |product, _evaluator|
5.times do
create(:product, :extension, :with_mirrored_repositories, base_products: [product], recommended: true)
end
end
end
trait :with_modules do
after :create do |product, _evaluator|
5.times do
mod = create :module
product.extensions << mod
end
end
end
trait :cloned do
transient do
from nil
end
after :build do |product, evaluator|
if evaluator.from
product.identifier = evaluator.from.identifier
product.arch = evaluator.from.arch
product.product_class = evaluator.from.product_class
product.product_type = evaluator.from.product_type
else
fail "Trait `cloned` won't work until you provide a `from: something` parameter. And you didn't."
end
end
end
trait :with_mirrored_repositories do
after :create do |product, _evaluator|
unless Service.find_by(product_id: product.id)
FactoryGirl.create(:service, :with_repositories, product: product, mirroring_enabled: true)
end
end
end
trait :with_not_mirrored_repositories do
after :create do |product, _evaluator|
unless Service.find_by(product_id: product.id)
FactoryGirl.create(:service, :with_repositories, product: product, mirroring_enabled: false)
end
end
end
trait :with_packages do
with_repositories
after :create do |product, _evaluator|
5.times { create :package, patch: nil, repository: product.repositories.first }
end
end
trait :activated do
transient do
system nil
end
after :create do |product, evaluator|
if evaluator.system
unless evaluator.system.activations.map(&:product).flatten.include?(product)
evaluator.system.activations << FactoryGirl.create(:activation, system: evaluator.system, service: product.service)
end
else
fail 'activated requires a system'
end
end
end
end
end