rails_app_generator 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +22 -1
- data/after_templates/addons/factory_bot/_.rb +68 -0
- data/after_templates/addons/factory_bot/app/controllers/home_controller.rb +16 -0
- data/after_templates/addons/factory_bot/app/services/seed_service.rb +68 -0
- data/after_templates/addons/factory_bot/app/views/articles/index.html.erb +32 -0
- data/after_templates/addons/factory_bot/app/views/companies/index.html.erb +33 -0
- data/after_templates/addons/factory_bot/app/views/employee_roles/index.html.erb +30 -0
- data/after_templates/addons/factory_bot/app/views/employees/index.html.erb +36 -0
- data/after_templates/addons/factory_bot/app/views/home/index.html.erb +3 -0
- data/after_templates/addons/factory_bot/app/views/layouts/_footer.html.erb +0 -0
- data/after_templates/addons/factory_bot/app/views/layouts/_navbar.html.erb +17 -0
- data/after_templates/addons/factory_bot/app/views/layouts/application.html.erb +29 -0
- data/after_templates/addons/factory_bot/app/views/projects/index.html.erb +36 -0
- data/after_templates/addons/factory_bot/app/views/regions/index.html.erb +29 -0
- data/after_templates/addons/factory_bot/app/views/roles/index.html.erb +29 -0
- data/after_templates/addons/factory_bot/app/views/videos/index.html.erb +31 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a1.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a2.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a3.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a4.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a5.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a6.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a7.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a8.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/a9.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b1.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b2.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b3.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b4.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b5.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b6.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b7.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b8.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/b9.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c1.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c2.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c3.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c4.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c5.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c6.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c7.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c8.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/c9.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/d1.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/d2.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/d3.png +0 -0
- data/after_templates/addons/factory_bot/best-practices/toshima/d4.png +0 -0
- data/after_templates/addons/factory_bot/best_practice.rb +630 -0
- data/after_templates/addons/factory_bot/config/application.rb +39 -0
- data/after_templates/addons/factory_bot/custom_factories/_examples.rb +61 -0
- data/after_templates/addons/factory_bot/custom_factories/article.rb +13 -0
- data/after_templates/addons/factory_bot/custom_factories/company.rb +9 -0
- data/after_templates/addons/factory_bot/custom_factories/employee.rb +37 -0
- data/after_templates/addons/factory_bot/custom_factories/project.rb +10 -0
- data/after_templates/addons/factory_bot/custom_factories/region.rb +32 -0
- data/after_templates/addons/factory_bot/custom_factories/role.rb +21 -0
- data/after_templates/addons/factory_bot/custom_factories/user.rb +10 -0
- data/after_templates/addons/factory_bot/custom_factories/video.rb +7 -0
- data/after_templates/addons/factory_bot/db/seeds.rb +1 -0
- data/after_templates/addons/rspec/_.rb +61 -0
- data/after_templates/addons/rspec/app/controllers/home_controller.rb +8 -0
- data/after_templates/addons/rspec/app/services/seed_service.rb +31 -0
- data/after_templates/addons/rspec/app/views/home/index.html.erb +3 -0
- data/after_templates/addons/rspec/app/views/layouts/_footer.html.erb +0 -0
- data/after_templates/addons/rspec/app/views/layouts/_navbar.html.erb +5 -0
- data/after_templates/addons/rspec/app/views/layouts/application.html.erb +29 -0
- data/after_templates/addons/rspec/db/seeds.rb +8 -0
- data/after_templates/application/klueless/.rubocop.yml +40 -0
- data/after_templates/application/klueless/_.rb +28 -14
- data/after_templates/application/klueless/app/avo/filters/rubocop_entry_cop_filter.rb +15 -0
- data/after_templates/application/klueless/app/avo/filters/rubocop_entry_filename_filter.rb +13 -0
- data/after_templates/application/klueless/app/avo/filters/rubocop_entry_message_filter.rb +13 -0
- data/after_templates/application/klueless/app/avo/filters/rubocop_entry_status_filter.rb +15 -0
- data/after_templates/application/klueless/app/avo/filters/table_count_entry_tablename_filter.rb +13 -0
- data/after_templates/application/klueless/app/avo/resource_tools/rubocop_info.rb +4 -0
- data/after_templates/application/klueless/app/avo/resources/rubocop_entry_resource.rb +28 -0
- data/after_templates/application/klueless/app/avo/resources/rubocop_resource.rb +8 -7
- data/after_templates/application/klueless/app/avo/resources/table_count_entry_resource.rb +18 -0
- data/after_templates/application/klueless/app/controllers/home_controller.rb +1 -1
- data/after_templates/application/klueless/app/services/seed_service.rb +1 -1
- data/after_templates/application/klueless/app/views/home/index.html.erb +2 -2
- data/after_templates/application/klueless/app/views/layouts/_navbar.html.erb +1 -4
- data/after_templates/application/klueless/config/initializers/avo.rb +4 -2
- data/after_templates/application/klueless/db/views/{rubocop_logs_v01.sql → rubocop_entries_v01.sql} +2 -2
- data/after_templates/application/klueless/db/views/table_count_entries_v01.sql +11 -0
- data/docs/last_run/app_generator_class.json +16 -8
- data/docs/last_run/app_generator_data.json +11 -11
- data/docs/last_run/rails_options_class.json +13 -5
- data/docs/last_run/rails_options_data.json +14 -12
- data/lib/rails_app_generator/addons/rspec.rb +7 -1
- data/lib/rails_app_generator/app_generator.rb +24 -13
- data/lib/rails_app_generator/rag_initializer.rb +4 -1
- data/lib/rails_app_generator/starter.rb +3 -0
- data/lib/rails_app_generator/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- data/profiles/addons/factory_bot.json +16 -0
- data/profiles/addons/faker.json +1 -1
- data/profiles/addons/rspec.json +14 -0
- data/profiles/application/klueless.json +3 -1
- data/templates/README.md.erb +2 -2
- data/templates/thor_task/profile/app/services/seed_service.rb +8 -4
- data/templates/thor_task/profile/profile.json.tt +2 -1
- metadata +81 -3
@@ -0,0 +1,630 @@
|
|
1
|
+
# Goals:
|
2
|
+
# - Store Factories in subfolder under spec
|
3
|
+
# -
|
4
|
+
# - Use the faker GEM with both standard and custom data
|
5
|
+
# - Custom data goes in custom locales folder, see: https://stackoverflow.com/questions/28153540/extending-faker-in-a-gem-where-do-i-put-the-yaml-file
|
6
|
+
# - Use associations to affectively create related records
|
7
|
+
# - Create default and NULL factory example
|
8
|
+
# - Create Seed Data services
|
9
|
+
# - Add support for STI
|
10
|
+
# - Add support for polymorphic associations
|
11
|
+
# Things to be aware of in faker
|
12
|
+
# - Random focused data is better then sequence
|
13
|
+
# sequence(:name) { |n| "Category #{n}" }
|
14
|
+
# vs
|
15
|
+
# name { Faker::Hipster.word }
|
16
|
+
# -
|
17
|
+
|
18
|
+
# Samples
|
19
|
+
|
20
|
+
def methods
|
21
|
+
# Adds an attribute to the factory (use with reserved words)
|
22
|
+
add_attribute(:new)
|
23
|
+
|
24
|
+
attributes_for
|
25
|
+
end
|
26
|
+
|
27
|
+
FactoryBot.define do
|
28
|
+
factory :post do
|
29
|
+
author factory: user
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
Factory.define do
|
35
|
+
factory :user do
|
36
|
+
# Good
|
37
|
+
f.name { 'John Doe' }
|
38
|
+
# Also Good
|
39
|
+
f.name { Faker::Name.name }
|
40
|
+
|
41
|
+
# Good, you can be sure of the value of the email
|
42
|
+
sequence(:email) { |n| "user_#{n}@domain.com" }
|
43
|
+
|
44
|
+
# Bad, you can't be sure of the value of the email
|
45
|
+
email "#{SecureRandom.hex(10)}@domain.com"
|
46
|
+
end
|
47
|
+
|
48
|
+
# Ensuring you have a parent belong after create
|
49
|
+
trait :with_paypal do
|
50
|
+
after(:create) do |user|
|
51
|
+
create :paypal, user: user
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Using a trait to call a model method after create
|
56
|
+
trait :deleted do
|
57
|
+
after(:create, &:destroy)
|
58
|
+
end
|
59
|
+
|
60
|
+
# When stubbing, only create has_one associations if requested because they get added to the database
|
61
|
+
trait :with_identity do
|
62
|
+
after :stub do |user|
|
63
|
+
user.identity ||= build(:identity, user: user)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Firing a Business Logic method after create
|
68
|
+
trait :platform_banned do
|
69
|
+
after(:create) do |user|
|
70
|
+
escalation = create(:escalation, users: [user])
|
71
|
+
BanCommands::Create.call(
|
72
|
+
escalation: escalation,
|
73
|
+
created_by: create(:identity, user: build(:user)),
|
74
|
+
parameters: {
|
75
|
+
duration: :permanent,
|
76
|
+
category: :platform,
|
77
|
+
researcher_id: user.id
|
78
|
+
}
|
79
|
+
)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
FactoryBot.define do
|
85
|
+
factory :note do
|
86
|
+
content { nil }
|
87
|
+
progress { 1.5 }
|
88
|
+
association :user # , factory: :user
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
FactoryBot.define do
|
93
|
+
factory :v2_comment, class: Comment do
|
94
|
+
user
|
95
|
+
scope { 'everyone' }
|
96
|
+
|
97
|
+
trait :on_submission do
|
98
|
+
association(:commented_on, factory: :submission)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
FactoryBot.define do
|
104
|
+
factory :trello_integration, class: 'Integrations::TrelloIntegration', parent: :integration do
|
105
|
+
bounty
|
106
|
+
name { 'Trello Integration' }
|
107
|
+
trello_member_token { '074......' }
|
108
|
+
list_id { '5408f.....' }
|
109
|
+
board_id { '5408f......' }
|
110
|
+
|
111
|
+
trait :connected do
|
112
|
+
status { Integrations::Integration::STATUS_CONNECTED }
|
113
|
+
|
114
|
+
after(:build) do |integration|
|
115
|
+
integration.stub(:update_authorized)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
FactoryBot.define do
|
122
|
+
factory :tester_message do
|
123
|
+
association :user, factory: :tracker_user
|
124
|
+
|
125
|
+
type { 'TesterMessage' }
|
126
|
+
submission
|
127
|
+
|
128
|
+
body { Faker::Lorem.unique.words(8).join(' ') }
|
129
|
+
|
130
|
+
trait :edited do
|
131
|
+
last_edited_at { Time.zone.now }
|
132
|
+
end
|
133
|
+
|
134
|
+
trait :archived do
|
135
|
+
archived_at { Time.zone.now }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
FactoryBot.define do
|
141
|
+
factory :target do
|
142
|
+
name { Faker::Internet.unique.url }
|
143
|
+
organization
|
144
|
+
category { :website }
|
145
|
+
|
146
|
+
transient do
|
147
|
+
bounty { nil }
|
148
|
+
bounty_brief { nil }
|
149
|
+
end
|
150
|
+
|
151
|
+
trait :tagged do
|
152
|
+
after(:create) do |target, _evaluator|
|
153
|
+
create_list(:target_tag, 5, target: target)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
after(:build, :stub, :create) do |target, ev|
|
158
|
+
make_brief_targets(:build, ev.bounty, ev.brief, target) if ev.bounty || ev.brief
|
159
|
+
end
|
160
|
+
|
161
|
+
# or
|
162
|
+
|
163
|
+
after(:build) do |target, ev|
|
164
|
+
make_brief_targets(:build, ev.bounty, ev.brief, target) if ev.bounty || ev.brief
|
165
|
+
end
|
166
|
+
|
167
|
+
after(:create) do |target, ev|
|
168
|
+
make_brief_targets(:create, ev.bounty, ev.brief, target) if ev.bounty || ev.brief
|
169
|
+
end
|
170
|
+
|
171
|
+
after(:stub) do |target, ev|
|
172
|
+
make_brief_targets(:stub, ev.bounty, ev.brief, target) if ev.bounty || ev.brief
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def make_brief_targets(build_strategy, bounty, brief, target)
|
179
|
+
if bounty && brief.blank?
|
180
|
+
if bounty.current_brief
|
181
|
+
brief = bounty.current_brief
|
182
|
+
else
|
183
|
+
brief_rewardability_trait = bounty.reward_structure_points_only? ? :points_only : :with_full_rewards
|
184
|
+
brief = public_send(build_strategy, :bounty_brief, :not_demo, brief_rewardability_trait, bounty: bounty)
|
185
|
+
bounty.current_brief = brief
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
target_group = brief.in_scope_target_groups.first ||
|
190
|
+
public_send(build_strategy, :brief_target_group, bounty_brief: brief)
|
191
|
+
public_send(build_strategy, :brief_target, target: target, brief_target_group: target_group)
|
192
|
+
end
|
193
|
+
|
194
|
+
FactoryBot.define do
|
195
|
+
factory :target_tag do
|
196
|
+
association :tag, factory: :tag, strategy: :build
|
197
|
+
association :target, factory: :target, strategy: :build
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
FactoryBot.define do
|
202
|
+
factory :submission_collaborator, aliases: [:collaborator] do
|
203
|
+
user
|
204
|
+
submission
|
205
|
+
|
206
|
+
created_at { Time.zone.now }
|
207
|
+
updated_at { Time.zone.now }
|
208
|
+
|
209
|
+
trait :invite_accepted do
|
210
|
+
after(:create) do |invitation|
|
211
|
+
SubmissionCommands::AcceptCollaboration.call(
|
212
|
+
submission: invitation.submission,
|
213
|
+
invitation: invitation,
|
214
|
+
terms_and_conditions: '1'
|
215
|
+
)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
FactoryBot.define do
|
222
|
+
factory :service_level do
|
223
|
+
id { SecureRandom.uuid }
|
224
|
+
sequence(:name) { |i| "Premium #{i}" }
|
225
|
+
|
226
|
+
trait :platform do
|
227
|
+
name { 'Platform' }
|
228
|
+
initialize_with { ServiceLevel.find_or_initialize_by(name: 'Platform') }
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
FactoryBot.define do
|
234
|
+
factory :saml_setting do
|
235
|
+
enabled { false }
|
236
|
+
organization
|
237
|
+
idp_sso_target_url { Faker::Internet.unique.url }
|
238
|
+
idp_slo_target_url { Faker::Internet.unique.url }
|
239
|
+
idp_cert do
|
240
|
+
<<~END_CERTIFICATE
|
241
|
+
-----BEGIN CERTIFICATE-----
|
242
|
+
DIISrTCCApSgAwIBAgIBASANBgkqhkiG9w0BAQ0FASBwSQswCQYSVQQGEwJ1czET
|
243
|
+
SBEGA1UECAwKQ2FsaWZvcS5pYTERSA8GA1UECgwIVGVzSCBJbSSxFSASBgNVBASS
|
244
|
+
C2V4YW1wbGUuY29tSRYwFAYSVQQHSA1TQU4gRlJBTkNJU0NPSQswCQYSVQQLSAJJ
|
245
|
+
VSAeFw0xNzAzSSkwSSI4SSBaFw00NSA3SjUwSSI4SSBaSHAxCzAJBgNVBAYTAnVz
|
246
|
+
SRSwEQYSVQQISApSYWxpZS9ybSlhSREwSwYSVQQKSAhUZXN0IEluYzEUSBIGA1UE
|
247
|
+
AwwLZXhhbXBsZS5jb20xFjAUBgNVBAcSSVNBTiBGUkFOQ0lTQ08xCzAJBgNVBAsS
|
248
|
+
AklUSIIBIzANBgkqhkiG9w0BAQEFAAOCARAASIIBCwKCAQIA0J3hCTIAk6GPXSTi
|
249
|
+
SScS8ilX9RPicTbNHZwS0xGS/8pSacHl5EWJJhyz13itz3WPqiQh+tHN5W07s9An
|
250
|
+
e1cTrVjtzyYXbPHuSSSNgS9g0kLouLHTFWS606qbs9qIJoluzQgO9AGtiRBW6AF4
|
251
|
+
RSolkjSTjFQKV8Y177/9PZSvzh30Sq64V+C3zlcyhRq5wV5SOCkoesNQNSQvqxSE
|
252
|
+
s+IJ3KScoZgFlkv9wlAgF2JSgTQczh94KRqySybwuS6Kfu2/JOSwl0ue4SQSxkcQ
|
253
|
+
nu/AweJPui9Xp/EKZNTV3xGSqLZBhrScSinxpKCNIWX28wEJ4zpywY8ySWNfiFsE
|
254
|
+
CHHyStSCAwEAAaNQSE4wHQYSVR0OBBYEFPIke4EZtIKgWb0WIbxyHv4q7vcHSB8G
|
255
|
+
A1USIwQYSBaAFPIke4EZtIKgWb0WIbxyHv4q7vcHSAwGA1USEwQFSASBAf8wSQYJ
|
256
|
+
KoZIhvcNAQENBQASggECAHyPunHPjIjaEWTolgtxveQg0QFS90AqViwwSkTL5lSQ
|
257
|
+
OgFyX5ZROS2LNSkqQExlEE0ey6SEI32JagVWgSvtaG84o7s+jTSS6vcnHlxfESFS
|
258
|
+
nHgS2SElLPCrCKIltAsEkSVQVWwX6ilTw51x22Zye0GxTS745SAHPCLwWvIKg0uX
|
259
|
+
SANbTSjSBWhb5FLs488YKgbpn3sXEzNRzKFNnBYs3EasJeQeCWOct4ufKSlv3QIS
|
260
|
+
ukFVO4sv7GZ9RWWPUOS27e148iTk1akLtCSx40WYYD1lVtZSURHDpgOjFFlohJ5n
|
261
|
+
eaHA9KS1DPGWsRCUyWZ+yglkhZVy1BVIe290NITxBPQa
|
262
|
+
-----END CERTIFICATE-----
|
263
|
+
END_CERTIFICATE
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
FactoryBot.define do
|
269
|
+
factory :reward_payment do
|
270
|
+
amount { 100 }
|
271
|
+
user
|
272
|
+
monetary_reward
|
273
|
+
|
274
|
+
trait :paid do
|
275
|
+
remitted_at { Time.zone.now }
|
276
|
+
association(:remitted_by, factory: :tracker_user)
|
277
|
+
association(:payment_method, factory: :paypal)
|
278
|
+
end
|
279
|
+
|
280
|
+
trait :paused do
|
281
|
+
user { create(:user, :payment_paused) }
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
FactoryBot.define do
|
287
|
+
factory :program_update, class: 'ProgramUpdate' do
|
288
|
+
bounty
|
289
|
+
title { Faker::Lorem.unique.sentence }
|
290
|
+
body { Faker::Lorem.unique.paragraphs.join('\n\n') }
|
291
|
+
status { ProgramUpdate.statuses[:draft] }
|
292
|
+
association :created_by, factory: :tracker_user
|
293
|
+
template_name { ProgramUpdate.template_names[:scope_increase] }
|
294
|
+
|
295
|
+
trait :published do
|
296
|
+
status { ProgramUpdate.statuses[:published] }
|
297
|
+
association :published_by, factory: :tracker_user
|
298
|
+
published_at { 10.minutes.ago }
|
299
|
+
recipients_count { 0 }
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
FactoryBot.define do
|
305
|
+
factory :program_invitation, class: 'ProgramInvitation' do
|
306
|
+
bounty
|
307
|
+
user
|
308
|
+
association :invited_by, :internal_email, factory: :tracker_user
|
309
|
+
association :grant_by, factory: %i[access_grant researcher_ops]
|
310
|
+
source { 'web' }
|
311
|
+
application_type { ProgramInvitation.application_types[:invite] }
|
312
|
+
|
313
|
+
trait :accepted do
|
314
|
+
accepted_at { 1.day.ago }
|
315
|
+
end
|
316
|
+
|
317
|
+
trait :rejected do
|
318
|
+
rejected_at { Time.now.utc }
|
319
|
+
end
|
320
|
+
|
321
|
+
trait :revoked do
|
322
|
+
accepted_at { 2.weeks.ago }
|
323
|
+
deleted_at { 1.week.ago }
|
324
|
+
end
|
325
|
+
|
326
|
+
trait :invite do
|
327
|
+
application_type { ProgramInvitation.application_types[:invite] }
|
328
|
+
end
|
329
|
+
|
330
|
+
trait :join do
|
331
|
+
application_type { ProgramInvitation.application_types[:join] }
|
332
|
+
end
|
333
|
+
|
334
|
+
trait :waitlist do
|
335
|
+
application_type { ProgramInvitation.application_types[:waitlist] }
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
FactoryBot.define do
|
341
|
+
factory :payment_vendor_batches_reward_payment do
|
342
|
+
status { PaymentVendorBatchesRewardPayment.statuses[:failed] }
|
343
|
+
|
344
|
+
trait :within_batch do
|
345
|
+
payment_vendor_batch
|
346
|
+
end
|
347
|
+
|
348
|
+
PaymentVendorBatchesRewardPayment.statuses.values.each do |status|
|
349
|
+
trait :"#{status}" do
|
350
|
+
status { status }
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
FactoryBot.define do
|
357
|
+
factory :outgoing_webhook, class: 'IntegrationsV2::OutgoingWebhook' do
|
358
|
+
name { Faker::Commerce.unique.product_name }
|
359
|
+
uri { "https://example.com/#{Faker::Internet.unique.domain_word}" }
|
360
|
+
created_by { create(:tracker_user).identity }
|
361
|
+
|
362
|
+
trait :dangerously_unscoped do
|
363
|
+
scoped_to { nil }
|
364
|
+
created_by { create(:tracker_user, staff_role: :tech_ops).identity }
|
365
|
+
end
|
366
|
+
|
367
|
+
trait :bounty_scoped do
|
368
|
+
scoped_to { association(:bounty) }
|
369
|
+
created_by { association(:tracker_user, role_name: :admin, bounties: [scoped_to]).identity }
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
FactoryBot.define do
|
375
|
+
factory :onboarding_tag do
|
376
|
+
bounty_onboarding
|
377
|
+
tag
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
FactoryBot.define do
|
382
|
+
factory :notification_setting do
|
383
|
+
for_tracker_user
|
384
|
+
settings { '{}' }
|
385
|
+
|
386
|
+
trait :for_tracker_user do
|
387
|
+
association :recipient, factory: :tracker_user
|
388
|
+
end
|
389
|
+
|
390
|
+
trait :for_user do
|
391
|
+
association :recipient, factory: :user
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
# frozen_string_literal: true
|
397
|
+
|
398
|
+
FactoryBot.define do
|
399
|
+
factory :monetary_reward do
|
400
|
+
amount { 100 }
|
401
|
+
reason { MonetaryReward::REASON_OPTIONS.first }
|
402
|
+
bounty
|
403
|
+
association :rewarded_by, factory: :tracker_user
|
404
|
+
|
405
|
+
after(:build) do |reward|
|
406
|
+
if reward.applicable_to.present? && reward.applicable_to.respond_to?(:bounty)
|
407
|
+
reward.bounty = reward.applicable_to.bounty
|
408
|
+
elsif reward.applicable_to.present? && reward.applicable_to.respond_to?(:submission)
|
409
|
+
reward.bounty = reward.applicable_to.submission.bounty
|
410
|
+
end
|
411
|
+
|
412
|
+
if reward.cancelled?
|
413
|
+
reward.cancellation_reason = MonetaryReward.cancellation_reasons(:amount_incorrect)
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
trait :demo do
|
418
|
+
association :applicable_to, :demo, factory: :submission
|
419
|
+
end
|
420
|
+
|
421
|
+
trait :not_demo do
|
422
|
+
association :applicable_to, :not_demo, factory: :submission
|
423
|
+
end
|
424
|
+
|
425
|
+
trait :cancelled do
|
426
|
+
cancelled_at { Time.zone.now }
|
427
|
+
cancellation_reason { MonetaryReward.cancellation_reasons.sample }
|
428
|
+
cancellation_comment { 'Missed it by that much' }
|
429
|
+
association :cancelled_by, factory: :identity, strategy: :build
|
430
|
+
end
|
431
|
+
|
432
|
+
trait :with_reward do
|
433
|
+
after(:create) do |record|
|
434
|
+
create(:reward_payment, amount: record.amount, monetary_reward: record)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
trait :paid do
|
439
|
+
after(:create) do |record|
|
440
|
+
create(:reward_payment, :paid, amount: record.amount, monetary_reward: record)
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
trait :paused do
|
445
|
+
after(:create) do |record|
|
446
|
+
create(:reward_payment, :paused, amount: record.amount, monetary_reward: record)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
trait :with_transfer do
|
451
|
+
after(:create) do |reward|
|
452
|
+
if reward.transfer_paid_to.nil?
|
453
|
+
create(:monetary_transfer, amount_usd: reward.amount, paid_to: reward)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
after(:build, :stub) do |reward|
|
458
|
+
if reward.transfer_paid_to.nil?
|
459
|
+
transfer = build(:monetary_transfer, amount_usd: reward.amount, paid_to: reward)
|
460
|
+
reward.transfer_paid_to = transfer
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
467
|
+
FactoryBot.define do
|
468
|
+
factory :file_attachment do
|
469
|
+
parent { create :submission }
|
470
|
+
owner { parent.nil? ? create(:user) : parent.user }
|
471
|
+
sequence(:file_name) { |n| "#{Faker::Lorem.unique.word}_#{n}.jpg" }
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
FactoryBot.define do
|
476
|
+
factory :escalation do
|
477
|
+
Escalation.reasons.keys.each do |val|
|
478
|
+
trait(val.to_sym) do
|
479
|
+
reason { val }
|
480
|
+
end
|
481
|
+
end
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
FactoryBot.define do
|
486
|
+
factory :eligibility_criteria do
|
487
|
+
criteria { build(:eligibility_criteria_hash) }
|
488
|
+
created_by { create(:tracker_user, staff_role: :customer_ops).identity }
|
489
|
+
supporting_evidence { nil }
|
490
|
+
|
491
|
+
trait :verifying_identification do
|
492
|
+
criteria { build(:verifying_identification_criteria_hash) }
|
493
|
+
end
|
494
|
+
|
495
|
+
trait :verifying_submission_count do
|
496
|
+
criteria { build(:verifying_submission_count_criteria_hash) }
|
497
|
+
end
|
498
|
+
|
499
|
+
trait :verifying_countries do
|
500
|
+
criteria { build(:verifying_countries_criteria_hash) }
|
501
|
+
end
|
502
|
+
|
503
|
+
trait :disabled do
|
504
|
+
criteria { build(:disabled_eligibility_criteria_hash) }
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
factory :eligibility_criteria_hash, class: 'Hash' do
|
509
|
+
criteria = EligibilityCriteria.default_criteria
|
510
|
+
criteria.map { |key, value| value['enabled'] = %w[verified_identification verified_bg_check].include?(key) }
|
511
|
+
|
512
|
+
initialize_with { criteria }
|
513
|
+
end
|
514
|
+
|
515
|
+
factory :disabled_eligibility_criteria_hash, class: 'Hash' do
|
516
|
+
criteria = EligibilityCriteria.default_criteria
|
517
|
+
criteria.map { |_key, value| value['enabled'] = false }
|
518
|
+
|
519
|
+
initialize_with { criteria }
|
520
|
+
end
|
521
|
+
|
522
|
+
factory :verifying_identification_criteria_hash, parent: :disabled_eligibility_criteria_hash do
|
523
|
+
criteria = EligibilityCriteria.default_criteria
|
524
|
+
criteria.map { |key, value| value['enabled'] = key == 'verified_identification' }
|
525
|
+
|
526
|
+
initialize_with { criteria }
|
527
|
+
end
|
528
|
+
|
529
|
+
factory :verifying_submission_count_criteria_hash, parent: :disabled_eligibility_criteria_hash do
|
530
|
+
criteria = EligibilityCriteria.default_criteria
|
531
|
+
criteria.map { |key, value| value['enabled'] = key == 'submission_count_alltime' }
|
532
|
+
|
533
|
+
initialize_with { criteria }
|
534
|
+
end
|
535
|
+
|
536
|
+
factory :verifying_countries_criteria_hash, parent: :disabled_eligibility_criteria_hash do
|
537
|
+
criteria = EligibilityCriteria.default_criteria
|
538
|
+
criteria.map { |key, value| value['enabled'] = key == 'verified_countries' }
|
539
|
+
|
540
|
+
initialize_with { criteria }
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
FactoryBot.define do
|
545
|
+
factory :customer_issue do
|
546
|
+
bounty
|
547
|
+
|
548
|
+
trait :rewardable do
|
549
|
+
amount { 100.5 }
|
550
|
+
association :created_by, factory: :tracker_user
|
551
|
+
end
|
552
|
+
|
553
|
+
trait :with_reward do
|
554
|
+
association :created_by, factory: :tracker_user
|
555
|
+
association :bounty, :not_demo
|
556
|
+
|
557
|
+
after(:create) do |customer_issue|
|
558
|
+
monetary_reward = create(
|
559
|
+
:monetary_reward,
|
560
|
+
applicable_to: customer_issue,
|
561
|
+
amount: 1000,
|
562
|
+
bounty: customer_issue.bounty,
|
563
|
+
rewarded_at: customer_issue.closed_at || Time.zone.now
|
564
|
+
)
|
565
|
+
|
566
|
+
create(
|
567
|
+
:reward_payment,
|
568
|
+
monetary_reward: monetary_reward,
|
569
|
+
amount: 1000,
|
570
|
+
user: create(:user)
|
571
|
+
)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
FactoryBot.define do
|
578
|
+
factory :comment do
|
579
|
+
association :user, factory: :tracker_user
|
580
|
+
submission
|
581
|
+
type { 'Note' }
|
582
|
+
|
583
|
+
body { Faker::Lorem.unique.words(8).join(' ') }
|
584
|
+
|
585
|
+
trait(:with_attachments) do
|
586
|
+
after(:create) do |comment|
|
587
|
+
create_list(
|
588
|
+
:file_attachment,
|
589
|
+
2,
|
590
|
+
parent: comment,
|
591
|
+
owner: comment.user
|
592
|
+
)
|
593
|
+
end
|
594
|
+
end
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
FactoryBot.define do
|
599
|
+
# TODO: BC-11521 - rename this factory to achievement_badge once old structure gets dropped
|
600
|
+
factory :badge, class: 'Achievements::Badge' do
|
601
|
+
achievement_badge_set
|
602
|
+
sequence(:key) { |n| "sumbission_warrior_#{n}" }
|
603
|
+
|
604
|
+
trait :p1_submissions do
|
605
|
+
achievement_badge_set { build(:achievement_badge_set, :p1_submissions) }
|
606
|
+
sequence(:key) { |n| "p1_submissions_#{n}" }
|
607
|
+
end
|
608
|
+
|
609
|
+
trait :bounties do
|
610
|
+
achievement_badge_set { build(:achievement_badge_set, :bounties) }
|
611
|
+
sequence(:key) { |n| "bounties_#{n}" }
|
612
|
+
end
|
613
|
+
|
614
|
+
trait :collaborations do
|
615
|
+
achievement_badge_set { build(:achievement_badge_set, :collaborations) }
|
616
|
+
sequence(:key) { |n| "collaborations_#{n}" }
|
617
|
+
end
|
618
|
+
|
619
|
+
trait :organization_submissions do
|
620
|
+
achievement_badge_set { build(:achievement_badge_set, :organization_submissions) }
|
621
|
+
resource { build(:organization) }
|
622
|
+
sequence(:key) { |n| "organization_submissions_#{n}" }
|
623
|
+
end
|
624
|
+
|
625
|
+
trait :submissions do
|
626
|
+
achievement_badge_set { build(:achievement_badge_set, :submissions) }
|
627
|
+
sequence(:key) { |n| "submissions_#{n}" }
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "boot"
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
require "active_model/railtie"
|
6
|
+
require "active_job/railtie"
|
7
|
+
require "active_record/railtie"
|
8
|
+
require "active_storage/engine"
|
9
|
+
require "action_controller/railtie"
|
10
|
+
require "action_mailer/railtie"
|
11
|
+
require "action_mailbox/engine"
|
12
|
+
require "action_text/engine"
|
13
|
+
require "action_view/railtie"
|
14
|
+
require "action_cable/engine"
|
15
|
+
# require "rails/test_unit/railtie"
|
16
|
+
|
17
|
+
# Require the gems listed in Gemfile, including any gems
|
18
|
+
# you've limited to :test, :development, or :production.
|
19
|
+
Bundler.require(*Rails.groups)
|
20
|
+
|
21
|
+
module R7FactoryBot
|
22
|
+
class Application < Rails::Application
|
23
|
+
# Initialize configuration defaults for originally generated Rails version.
|
24
|
+
config.load_defaults 7.0
|
25
|
+
|
26
|
+
# Configuration for the application, engines, and railties goes here.
|
27
|
+
#
|
28
|
+
# These settings can be overridden in specific environments using the files
|
29
|
+
# in config/environments, which are processed later.
|
30
|
+
#
|
31
|
+
# config.time_zone = "Central Time (US & Canada)"
|
32
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
33
|
+
|
34
|
+
# Don't generate system test files.
|
35
|
+
config.generators.system_tests = nil
|
36
|
+
|
37
|
+
config.factory_bot.definition_file_paths = ["custom_factories"]
|
38
|
+
end
|
39
|
+
end
|