File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,26 @@ factory.build('user').then(user => {
31
31
});
32
32
```
33
33
34
+ ## Defining Models
35
+
36
+ Define models that have a constructor that takes an object with the attributes needed to
37
+ instantiate an instance of the model.
38
+
39
+ For example:
40
+
41
+ ``` javascript
42
+ class User {
43
+ constructor (attrs = {}) {
44
+ this .attrs = Object .assign ({
45
+ username: attrs .username || ' George' ,
46
+ score: attrs .score || 27 ,
47
+ }, attrs);
48
+ }
49
+ }
50
+ ```
51
+
52
+ The factory methods will invoke this constructor during the construction of model objects.
53
+
34
54
## Defining Factories
35
55
36
56
Define factories using the ` factory.define() ` method.
Original file line number Diff line number Diff line change @@ -4,6 +4,24 @@ This tutorial introduces the capabilities of `factory-girl`. We'll start with a
4
4
factory for a hypothetical ` User ` model and gradually add to it. This tutorial may not
5
5
cover all aspects of ` factory-girl ` , but should serve as a good starting point.
6
6
7
+ ### The ` User ` Model
8
+
9
+ For these examples we'll assume we have a model like the following with a constructor
10
+ that takes one object with the attributes necessary to initialize the model class.
11
+
12
+ ``` javascript
13
+ class User {
14
+ constructor (attrs = {}) {
15
+ this .attrs = Object .assign ({
16
+ email
: attrs .
email || ' [email protected] ' ,
17
+ password: attrs .password || ' secure-password' ,
18
+ }, attrs);
19
+ }
20
+ }
21
+ ```
22
+
23
+ The factory methods will invoke this constructor during the construction of model objects.
24
+
7
25
### The ` User ` Factory
8
26
9
27
Let's start with a simple ` User ` factory, as we go on, we'll keep on modifying
You can’t perform that action at this time.
0 commit comments