faker_maker 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.gitignore +4 -0
- data/.rubocop.yml +1 -0
- data/Gemfile +2 -0
- data/MIGRATION_NOTES.md +47 -0
- data/TODO.md +16 -0
- data/faker_maker.gemspec +1 -1
- data/hack/nested.rb +21 -0
- data/lib/faker_maker/attribute.rb +10 -1
- data/lib/faker_maker/base.rb +2 -2
- data/lib/faker_maker/definition_proxy.rb +2 -2
- data/lib/faker_maker/factory.rb +122 -34
- data/lib/faker_maker/version.rb +1 -1
- data/usefakermaker.com/pages/about/index.md +20 -0
- data/usefakermaker.com.site/.gitignore +2 -0
- data/usefakermaker.com.site/site/assets/favicons/android-chrome-192x192.png +0 -0
- data/usefakermaker.com.site/site/assets/favicons/android-chrome-512x512.png +0 -0
- data/usefakermaker.com.site/site/assets/favicons/apple-touch-icon.png +0 -0
- data/usefakermaker.com.site/site/assets/favicons/favicon-16x16.png +0 -0
- data/usefakermaker.com.site/site/assets/favicons/favicon-32x32.png +0 -0
- data/usefakermaker.com.site/site/assets/favicons/favicon.ico +0 -0
- data/usefakermaker.com.site/site/assets/favicons/site.webmanifest +19 -0
- data/usefakermaker.com.site/site/assets/robots.txt +2 -0
- data/usefakermaker.com.site/site/assets/styles.css +351 -0
- data/{usefakermaker.com/docs/contributing/index.md → usefakermaker.com.site/site/src/docs/contributing/index.page.md} +1 -5
- data/{usefakermaker.com/docs/installing/index.md → usefakermaker.com.site/site/src/docs/installing/index.page.md} +1 -5
- data/{usefakermaker.com/docs/usage/arrays/index.md → usefakermaker.com.site/site/src/docs/usage/arrays/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/building-instances/index.md → usefakermaker.com.site/site/src/docs/usage/building-instances/index.page.md} +6 -7
- data/{usefakermaker.com/docs/usage/chaos/index.md → usefakermaker.com.site/site/src/docs/usage/chaos/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/destroying-factories/index.md → usefakermaker.com.site/site/src/docs/usage/destroying-factories/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/embedding-factories/index.md → usefakermaker.com.site/site/src/docs/usage/embedding-factories/index.page.md} +41 -7
- data/{usefakermaker.com/docs/usage/getting-started/index.md → usefakermaker.com.site/site/src/docs/usage/getting-started/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/history-logging/index.md → usefakermaker.com.site/site/src/docs/usage/history-logging/index.page.md} +1 -6
- data/{usefakermaker.com/docs/usage/inheritance/index.md → usefakermaker.com.site/site/src/docs/usage/inheritance/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/json-field-names/index.md → usefakermaker.com.site/site/src/docs/usage/json-field-names/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/lifecycle-hooks/index.md → usefakermaker.com.site/site/src/docs/usage/lifecycle-hooks/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/managing-dependencies/index.md → usefakermaker.com.site/site/src/docs/usage/managing-dependencies/index.page.md} +1 -4
- data/{usefakermaker.com/docs/usage/omitting-fields/index.md → usefakermaker.com.site/site/src/docs/usage/omitting-fields/index.page.md} +1 -4
- data/{usefakermaker.com/pages/index.markdown → usefakermaker.com.site/site/src/index.page.md} +9 -19
- data/usefakermaker.com.site/site/templates/_nav.html.erb +27 -0
- data/usefakermaker.com.site/site/templates/layout.html.erb +46 -0
- data/usefakermaker.com.site/site/templates/page.html.erb +3 -0
- metadata +39 -51
- data/usefakermaker.com/.gitignore +0 -5
- data/usefakermaker.com/404.html +0 -25
- data/usefakermaker.com/Gemfile +0 -39
- data/usefakermaker.com/README.md +0 -5
- data/usefakermaker.com/_config.yml +0 -299
- data/usefakermaker.com/_config.yml.orig +0 -55
- data/usefakermaker.com/_data/navigation.yml +0 -51
- data/usefakermaker.com/_data/ui-text.yml +0 -2132
- data/usefakermaker.com/_site/assets/css/main.css +0 -6
- data/usefakermaker.com/_site/assets/css/main.css.map +0 -1
- data/usefakermaker.com/_site/assets/js/_main.js +0 -230
- data/usefakermaker.com/_site/assets/js/lunr/lunr-en.js +0 -69
- data/usefakermaker.com/_site/assets/js/lunr/lunr-gr.js +0 -522
- data/usefakermaker.com/_site/assets/js/lunr/lunr-store.js +0 -1
- data/usefakermaker.com/_site/assets/js/lunr/lunr.js +0 -3475
- data/usefakermaker.com/_site/assets/js/lunr/lunr.min.js +0 -6
- data/usefakermaker.com/_site/assets/js/main.min.js +0 -7
- data/usefakermaker.com/_site/assets/js/main.min.js.map +0 -1
- data/usefakermaker.com/_site/assets/js/plugins/gumshoe.js +0 -484
- data/usefakermaker.com/_site/assets/js/plugins/jquery.ba-throttle-debounce.js +0 -252
- data/usefakermaker.com/_site/assets/js/plugins/jquery.fitvids.js +0 -82
- data/usefakermaker.com/_site/assets/js/plugins/jquery.greedy-navigation.js +0 -128
- data/usefakermaker.com/_site/assets/js/plugins/jquery.magnific-popup.js +0 -1860
- data/usefakermaker.com/_site/assets/js/plugins/smooth-scroll.js +0 -650
- data/usefakermaker.com/_site/assets/js/vendor/jquery/jquery-3.6.0.js +0 -10881
- data/usefakermaker.com/_site/feed.xml +0 -1
- data/usefakermaker.com/_site/robots.txt +0 -1
- data/usefakermaker.com/_site/sitemap.xml +0 -3
- data/usefakermaker.com/about.markdown +0 -18
- /data/{usefakermaker.com → usefakermaker.com.site/site}/assets/images/pug.png +0 -0
- /data/{usefakermaker.com → usefakermaker.com.site/site}/assets/images/unipug.svg +0 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
3
|
+
--font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
4
|
+
|
|
5
|
+
--color-bg: #ffffff;
|
|
6
|
+
--color-text: #1a202c;
|
|
7
|
+
--color-primary: #3182ce;
|
|
8
|
+
--color-primary-hover: #2c5282;
|
|
9
|
+
--color-sidebar-bg: #f7fafc;
|
|
10
|
+
--color-border: #e2e8f0;
|
|
11
|
+
--color-code-bg: #edf2f7;
|
|
12
|
+
|
|
13
|
+
--spacing-unit: 1rem;
|
|
14
|
+
--sidebar-width: 280px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@media (prefers-color-scheme: dark) {
|
|
18
|
+
:root {
|
|
19
|
+
--color-bg: #1a202c;
|
|
20
|
+
--color-text: #e2e8f0;
|
|
21
|
+
--color-primary: #63b3ed;
|
|
22
|
+
--color-primary-hover: #4299e1;
|
|
23
|
+
--color-sidebar-bg: #2d3748;
|
|
24
|
+
--color-border: #4a5568;
|
|
25
|
+
--color-code-bg: #2d3748;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
* {
|
|
30
|
+
box-sizing: border-box;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body {
|
|
34
|
+
margin: 0;
|
|
35
|
+
font-family: var(--font-sans);
|
|
36
|
+
color: var(--color-text);
|
|
37
|
+
background-color: var(--color-bg);
|
|
38
|
+
line-height: 1.6;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.layout {
|
|
42
|
+
display: flex;
|
|
43
|
+
min-height: 100vh;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.sidebar {
|
|
47
|
+
width: var(--sidebar-width);
|
|
48
|
+
background: var(--color-sidebar-bg);
|
|
49
|
+
border-right: 1px solid var(--color-border);
|
|
50
|
+
padding: 2rem;
|
|
51
|
+
overflow-y: auto;
|
|
52
|
+
position: sticky;
|
|
53
|
+
top: 0;
|
|
54
|
+
height: 100vh;
|
|
55
|
+
flex-shrink: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.page-container {
|
|
59
|
+
flex: 1;
|
|
60
|
+
display: flex;
|
|
61
|
+
flex-direction: column;
|
|
62
|
+
min-height: 100vh;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.main-content {
|
|
66
|
+
flex: 1;
|
|
67
|
+
padding: 2rem 4rem;
|
|
68
|
+
max-width: 1000px;
|
|
69
|
+
width: 100%;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.site-footer {
|
|
73
|
+
padding: 2rem 4rem;
|
|
74
|
+
border-top: 1px solid var(--color-border);
|
|
75
|
+
margin-top: 4rem;
|
|
76
|
+
display: flex;
|
|
77
|
+
justify-content: space-between;
|
|
78
|
+
align-items: center;
|
|
79
|
+
font-size: 0.9rem;
|
|
80
|
+
color: var(--color-text);
|
|
81
|
+
opacity: 0.7;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.site-footer p {
|
|
85
|
+
margin: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.site-footer a {
|
|
89
|
+
color: inherit;
|
|
90
|
+
font-weight: 500;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Typography */
|
|
94
|
+
h1 {
|
|
95
|
+
font-size: 2.5rem;
|
|
96
|
+
margin-bottom: 1rem;
|
|
97
|
+
line-height: 1.2;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
h2 {
|
|
101
|
+
font-size: 1.75rem;
|
|
102
|
+
margin-top: 2.5rem;
|
|
103
|
+
margin-bottom: 1rem;
|
|
104
|
+
padding-bottom: 0.5rem;
|
|
105
|
+
border-bottom: 1px solid var(--color-border);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
h3 {
|
|
109
|
+
font-size: 1.25rem;
|
|
110
|
+
margin-top: 2rem;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
a {
|
|
114
|
+
color: var(--color-primary);
|
|
115
|
+
text-decoration: none;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
a:hover {
|
|
119
|
+
text-decoration: underline;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/* Navigation */
|
|
123
|
+
.nav-section {
|
|
124
|
+
margin-bottom: 2rem;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.nav-title {
|
|
128
|
+
font-weight: bold;
|
|
129
|
+
text-transform: uppercase;
|
|
130
|
+
font-size: 0.85rem;
|
|
131
|
+
color: var(--color-text);
|
|
132
|
+
letter-spacing: 0.05em;
|
|
133
|
+
margin-bottom: 0.5rem;
|
|
134
|
+
opacity: 0.7;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.nav-links {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
gap: 0.5rem;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.nav-link {
|
|
144
|
+
color: var(--color-text);
|
|
145
|
+
font-size: 0.95rem;
|
|
146
|
+
opacity: 0.8;
|
|
147
|
+
transition: opacity 0.2s;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.nav-link:hover {
|
|
151
|
+
opacity: 1;
|
|
152
|
+
color: var(--color-primary);
|
|
153
|
+
text-decoration: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.logo {
|
|
157
|
+
font-size: 1.5rem;
|
|
158
|
+
font-weight: bold;
|
|
159
|
+
display: block;
|
|
160
|
+
margin-bottom: 2rem;
|
|
161
|
+
color: var(--color-text);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* Code Blocks */
|
|
165
|
+
pre {
|
|
166
|
+
background: var(--color-code-bg);
|
|
167
|
+
padding: 1rem;
|
|
168
|
+
border-radius: 0.5rem;
|
|
169
|
+
overflow-x: auto;
|
|
170
|
+
font-family: var(--font-mono);
|
|
171
|
+
font-size: 0.9em;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
code {
|
|
175
|
+
font-family: var(--font-mono);
|
|
176
|
+
background: var(--color-code-bg);
|
|
177
|
+
padding: 0.2em 0.4em;
|
|
178
|
+
border-radius: 0.25rem;
|
|
179
|
+
font-size: 0.85em;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pre code {
|
|
183
|
+
background: transparent;
|
|
184
|
+
padding: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* Components */
|
|
188
|
+
.btn {
|
|
189
|
+
display: inline-block;
|
|
190
|
+
background: var(--color-primary);
|
|
191
|
+
color: white;
|
|
192
|
+
padding: 0.75rem 1.5rem;
|
|
193
|
+
border-radius: 0.375rem;
|
|
194
|
+
font-weight: 600;
|
|
195
|
+
transition: background-color 0.2s;
|
|
196
|
+
text-decoration: none !important;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.btn:hover {
|
|
200
|
+
background: var(--color-primary-hover);
|
|
201
|
+
color: white;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.hero {
|
|
205
|
+
text-align: center;
|
|
206
|
+
padding: 4rem 2rem;
|
|
207
|
+
background: var(--color-sidebar-bg);
|
|
208
|
+
border-radius: 1rem;
|
|
209
|
+
margin-bottom: 2rem;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.hero h2 {
|
|
213
|
+
border-bottom: none;
|
|
214
|
+
font-size: 2rem;
|
|
215
|
+
margin-top: 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* Mobile Navigation */
|
|
219
|
+
.menu-toggle {
|
|
220
|
+
display: none;
|
|
221
|
+
position: fixed;
|
|
222
|
+
bottom: 1.5rem;
|
|
223
|
+
right: 1.5rem;
|
|
224
|
+
width: 3.5rem;
|
|
225
|
+
height: 3.5rem;
|
|
226
|
+
border-radius: 50%;
|
|
227
|
+
background: var(--color-primary);
|
|
228
|
+
border: none;
|
|
229
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
230
|
+
cursor: pointer;
|
|
231
|
+
z-index: 100;
|
|
232
|
+
padding: 0;
|
|
233
|
+
align-items: center;
|
|
234
|
+
justify-content: center;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.hamburger {
|
|
238
|
+
width: 24px;
|
|
239
|
+
height: 2px;
|
|
240
|
+
background: white;
|
|
241
|
+
position: relative;
|
|
242
|
+
transition: all 0.3s;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.hamburger::before,
|
|
246
|
+
.hamburger::after {
|
|
247
|
+
content: '';
|
|
248
|
+
position: absolute;
|
|
249
|
+
width: 24px;
|
|
250
|
+
height: 2px;
|
|
251
|
+
background: white;
|
|
252
|
+
left: 0;
|
|
253
|
+
transition: all 0.3s;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.hamburger::before {
|
|
257
|
+
top: -8px;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.hamburger::after {
|
|
261
|
+
top: 8px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.sidebar-open .hamburger {
|
|
265
|
+
background: transparent;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.sidebar-open .hamburger::before {
|
|
269
|
+
top: 0;
|
|
270
|
+
transform: rotate(45deg);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.sidebar-open .hamburger::after {
|
|
274
|
+
top: 0;
|
|
275
|
+
transform: rotate(-45deg);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.sidebar-overlay {
|
|
279
|
+
position: fixed;
|
|
280
|
+
top: 0;
|
|
281
|
+
left: 0;
|
|
282
|
+
right: 0;
|
|
283
|
+
bottom: 0;
|
|
284
|
+
background: rgba(0, 0, 0, 0.5);
|
|
285
|
+
z-index: 40;
|
|
286
|
+
display: none;
|
|
287
|
+
opacity: 0;
|
|
288
|
+
transition: opacity 0.3s;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.sidebar-open .sidebar-overlay {
|
|
292
|
+
display: block;
|
|
293
|
+
opacity: 1;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/* Responsive */
|
|
297
|
+
@media (max-width: 768px) {
|
|
298
|
+
.menu-toggle {
|
|
299
|
+
display: flex;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.layout {
|
|
303
|
+
display: block;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.sidebar {
|
|
307
|
+
position: fixed;
|
|
308
|
+
top: 0;
|
|
309
|
+
left: 0;
|
|
310
|
+
bottom: 0;
|
|
311
|
+
width: 280px;
|
|
312
|
+
z-index: 50;
|
|
313
|
+
transform: translateX(-100%);
|
|
314
|
+
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
315
|
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.sidebar-open .sidebar {
|
|
319
|
+
transform: translateX(0);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.sidebar-open {
|
|
323
|
+
overflow: hidden;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/* Update main-content selector usage if needed or ensure page-container behaves on mobile */
|
|
327
|
+
.page-container {
|
|
328
|
+
width: 100%;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.main-content {
|
|
332
|
+
padding: 1.5rem;
|
|
333
|
+
width: 100%;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
.site-footer {
|
|
337
|
+
padding: 1.5rem;
|
|
338
|
+
flex-direction: column;
|
|
339
|
+
gap: 1rem;
|
|
340
|
+
text-align: center;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* Adjust typography for mobile */
|
|
344
|
+
h1 {
|
|
345
|
+
font-size: 2rem;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.logo {
|
|
349
|
+
margin-bottom: 2rem;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
layout: single
|
|
3
|
-
title: Building Instances
|
|
4
|
-
---
|
|
1
|
+
# Building Instances
|
|
5
2
|
|
|
6
3
|
Instances are Plain Ol' Ruby Objects and the attributes are attached with getters and setters with their values assigned to the value return from their block at build time.
|
|
7
4
|
|
|
@@ -13,10 +10,10 @@ result = FakerMaker[:basket].build
|
|
|
13
10
|
|
|
14
11
|
will generate a new instance using the Basket factory. Because an actual class is defined (since v3.0.0 Classes generated by FakerMaker are in the `FakerMaker::Factory` namespace), you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes.
|
|
15
12
|
|
|
16
|
-
It's possible to override attributes at build-time, either by passing values as a hash:
|
|
13
|
+
It's possible to override attributes at build-time, either by passing values as a hash (preferred):
|
|
17
14
|
|
|
18
15
|
```ruby
|
|
19
|
-
result = FakerMaker[:item].build( name: 'Electric Blanket' )
|
|
16
|
+
result = FakerMaker[:item].build( attributes: { name: 'Electric Blanket' } )
|
|
20
17
|
```
|
|
21
18
|
|
|
22
19
|
or by passing in a block:
|
|
@@ -36,7 +33,7 @@ end
|
|
|
36
33
|
if you're crazy enough to want to do both styles during creation, the values in the block will be preserved, e.g.
|
|
37
34
|
|
|
38
35
|
```ruby
|
|
39
|
-
result = FakerMaker[:item].build( name: 'Electric Blanket' ) do |i|
|
|
36
|
+
result = FakerMaker[:item].build( attributes: { name: 'Electric Blanket' } ) do |i|
|
|
40
37
|
i.name = 'Electric Sheep'
|
|
41
38
|
end
|
|
42
39
|
```
|
|
@@ -58,3 +55,5 @@ As another convenience, `FakerMaker` is also assigned to the variable `FM` to it
|
|
|
58
55
|
```ruby
|
|
59
56
|
result = FM[:basket].build
|
|
60
57
|
```
|
|
58
|
+
|
|
59
|
+
**For more complex instance building with embedded factories, see [Embedding Factories](docs/usage/embedding-factories/).**
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
layout: single
|
|
3
|
-
title: Embedding Factories
|
|
4
|
-
---
|
|
1
|
+
# Embedding Factories
|
|
5
2
|
|
|
6
3
|
To use factories with factories, the following pattern is recommended:
|
|
7
4
|
|
|
@@ -31,11 +28,11 @@ FakerMaker.factory :item do
|
|
|
31
28
|
end
|
|
32
29
|
|
|
33
30
|
FakerMaker.factory :basket do
|
|
34
|
-
items( has: 10, factory: [:item, :
|
|
31
|
+
items( has: 10, factory: [:item, :coupon] ) # either `item` or `coupon` will be randomly selected for each member
|
|
35
32
|
end
|
|
36
33
|
```
|
|
37
34
|
|
|
38
|
-
In this example, through 10 iterations,
|
|
35
|
+
In this example, through 10 iterations, a random choice of `item` and `discount` factories will be called to build their objects.
|
|
39
36
|
|
|
40
37
|
Blocks can still be provided and the referenced factory built object will be passed to the block:
|
|
41
38
|
|
|
@@ -49,11 +46,48 @@ FakerMaker.factory :basket do
|
|
|
49
46
|
items( has: 10, factory: :item ) { |item| item.price = 10.99 ; item}
|
|
50
47
|
end
|
|
51
48
|
```
|
|
49
|
+
|
|
50
|
+
## Overriding values for nested factories in the enclosing factory
|
|
51
|
+
|
|
52
52
|
**Important:** the value for the attribute will be the value returned from the block. If you want to modify the contents of the referenced factory's object, don't forget to return it at the end of the block (as above).
|
|
53
53
|
|
|
54
|
+
## Overriding values for nested factories during build
|
|
55
|
+
|
|
56
|
+
If we look carefully at this factory
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
FakerMaker.factory :inventory do
|
|
60
|
+
item( factory: :item )
|
|
61
|
+
quantity { 10 }
|
|
62
|
+
end
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This will build a object of the form (in its `as_json` guise):
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
{item: {name: "toothpaste", price: 0.99}, quantity: 10}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When it comes to overriding values at build time, a hash can be passed to set the nested values:
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
FM[:inventory].build( attributes: { item: { name: 'floor cleaner' } } )
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When you allow Faker Maker to make a choice of factory by giving it an array:
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
FakerMaker.factory :inventory do
|
|
81
|
+
item( factory: [:item, :coupon] )
|
|
82
|
+
quantity { 10 }
|
|
83
|
+
end
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
...either the `item` or `coupon` fields could be added to each build of the `inventory` factory. Faker Maker will ignore any fields for the non-chosen factory if they are paseed in the overrides hash. This means that a `NoSuchAttribute` error will not be raised.
|
|
87
|
+
|
|
54
88
|
## Alternative method
|
|
55
89
|
|
|
56
|
-
There is an alternative style which might be of use
|
|
90
|
+
There is an alternative style which might be of use, **but** you have less control using build-time overrides for values (you can't set nested values). *This is no longer a recommended pattern*.
|
|
57
91
|
|
|
58
92
|
```ruby
|
|
59
93
|
FakerMaker.factory :item do
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
layout: single
|
|
3
|
-
title: JSON Field Names
|
|
4
|
-
---
|
|
1
|
+
# JSON Field Names
|
|
5
2
|
|
|
6
3
|
JavaScript likes to use camelCase, Ruby's idiom is to use snake_case. This can make make manipulating factory-built objects in ruby ugly. To avoid this, you can call your fields one thing and ask the JSON outputter to rename the field when generating JSON.
|
|
7
4
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
layout: single
|
|
3
|
-
title: Managing Dependencies
|
|
4
|
-
---
|
|
1
|
+
# Managing Dependencies
|
|
5
2
|
|
|
6
3
|
Factory definition files are Plain Ol' Ruby. If you depend on another factory because you either extend from it or use it just add a `require` or (depending on your load path) `require_relative` to the top of your file.
|
data/{usefakermaker.com/pages/index.markdown → usefakermaker.com.site/site/src/index.page.md}
RENAMED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
# Feel free to add content and custom Front Matter to this file.
|
|
3
|
-
# To modify the layout, see https://jekyllrb.com/docs/themes/#overriding-theme-defaults
|
|
1
|
+
# FakerMaker
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
title: Factories over fixtures
|
|
14
|
-
excerpt: FakerMaker is a simple factory builder so you can throw away your fixtures and generate test data instead.
|
|
15
|
-
url: "/docs/installing/"
|
|
16
|
-
btn_label: "Get Started"
|
|
17
|
-
btn_class: "btn btn--success"
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
{% include feature_row type="center" %}
|
|
3
|
+
<div class="hero">
|
|
4
|
+
<img src="/images/unipug.svg" alt="An illustration of cute pug dog pretending to be a unicorn by wearing a costume" style="max-width: 200px; display: block; margin: 0 auto 2rem;">
|
|
5
|
+
<h2>Factories over fixtures</h2>
|
|
6
|
+
<p>FakerMaker is a simple factory builder so you can throw away your fixtures and generate test data instead.</p>
|
|
7
|
+
<p style="text-align: center;">
|
|
8
|
+
<a href="/docs/installing" class="btn">Get Started</a>
|
|
9
|
+
</p>
|
|
10
|
+
</div>
|
|
21
11
|
|
|
22
12
|
Sometimes you need generate data; something testers need to do a lot. Often, a bunch of fixtures will be built by hand, carefully maintained and curated, until the API or schema or something changes and all the fixtures need to be pruned before the tests pass again. This drives testers into building fixtures which individually cover lots of acceptance critera just so that they can drive down the number of them they have to maintain until the fixtures don’t resemble anything like realistic criteria.
|
|
23
13
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<nav>
|
|
2
|
+
<div class="nav-section">
|
|
3
|
+
<div class="nav-title">Getting Started</div>
|
|
4
|
+
<div class="nav-links">
|
|
5
|
+
<a href="/docs/installing" class="nav-link">Installing</a>
|
|
6
|
+
<a href="/docs/contributing" class="nav-link">Contributing</a>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<div class="nav-section">
|
|
11
|
+
<div class="nav-title">Usage</div>
|
|
12
|
+
<div class="nav-links">
|
|
13
|
+
<a href="/docs/usage/getting-started" class="nav-link">Getting started</a>
|
|
14
|
+
<a href="/docs/usage/building-instances" class="nav-link">Building instances</a>
|
|
15
|
+
<a href="/docs/usage/arrays" class="nav-link">Arrays</a>
|
|
16
|
+
<a href="/docs/usage/omitting-fields" class="nav-link">Omitting fields</a>
|
|
17
|
+
<a href="/docs/usage/json-field-names" class="nav-link">JSON field names</a>
|
|
18
|
+
<a href="/docs/usage/inheritance" class="nav-link">Inheritance</a>
|
|
19
|
+
<a href="/docs/usage/embedding-factories" class="nav-link">Embedding factories</a>
|
|
20
|
+
<a href="/docs/usage/chaos" class="nav-link">Chaos</a>
|
|
21
|
+
<a href="/docs/usage/lifecycle-hooks" class="nav-link">Lifecycle hooks</a>
|
|
22
|
+
<a href="/docs/usage/destroying-factories" class="nav-link">Destroying factories</a>
|
|
23
|
+
<a href="/docs/usage/managing-dependencies" class="nav-link">Managing dependencies</a>
|
|
24
|
+
<a href="/docs/usage/history-logging" class="nav-link">History logging</a>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</nav>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title><%= title %> - FakerMaker</title>
|
|
7
|
+
<link rel="stylesheet" href="/styles.css">
|
|
8
|
+
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
|
|
9
|
+
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
|
|
10
|
+
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
|
|
11
|
+
<link rel="manifest" href="/favicons/site.webmanifest">
|
|
12
|
+
<link rel="shortcut icon" href="/favicons/favicon.ico">
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div class="layout">
|
|
16
|
+
<button class="menu-toggle" aria-label="Toggle navigation">
|
|
17
|
+
<span class="hamburger"></span>
|
|
18
|
+
</button>
|
|
19
|
+
<aside class="sidebar">
|
|
20
|
+
<a href="/" class="logo">FakerMaker</a>
|
|
21
|
+
<%= render 'nav' %>
|
|
22
|
+
</aside>
|
|
23
|
+
<div class="page-container">
|
|
24
|
+
<main class="main-content">
|
|
25
|
+
<%= content %>
|
|
26
|
+
</main>
|
|
27
|
+
<footer class="site-footer">
|
|
28
|
+
<p>© 2026 FakerMaker</p>
|
|
29
|
+
<p>
|
|
30
|
+
<a href="https://github.com/BillyRuffian/faker_maker">GitHub</a> •
|
|
31
|
+
<a href="https://usejackdaw.com">Documentation by Jackdaw</a>
|
|
32
|
+
</p>
|
|
33
|
+
</footer>
|
|
34
|
+
</div>
|
|
35
|
+
<div class="sidebar-overlay"></div>
|
|
36
|
+
</div>
|
|
37
|
+
<script>
|
|
38
|
+
document.querySelector('.menu-toggle').addEventListener('click', function() {
|
|
39
|
+
document.body.classList.toggle('sidebar-open');
|
|
40
|
+
});
|
|
41
|
+
document.querySelector('.sidebar-overlay').addEventListener('click', function() {
|
|
42
|
+
document.body.classList.remove('sidebar-open');
|
|
43
|
+
});
|
|
44
|
+
</script>
|
|
45
|
+
</body>
|
|
46
|
+
</html>
|