OSDN Git Service

Regular updates
[twpd/master.git] / machinist.md
1 ---
2 title: Machinist
3 category: Ruby libraries
4 ---
5
6 ### Installing
7
8     # Gemfile
9     gem 'machinist', '>= 2.0.0.beta2', group: 'test'
10
11     # ~$ bundle
12     # ~$ rails generate machinist:install
13
14 ### Building objects
15
16     User.make
17
18     # `make` builds it, and `make!` builds+saves it
19     User.make!
20     User.make! name: "David"
21     User.make!(:admin)
22
23 ### Defining blueprints
24
25     User.blueprint do
26       name  { "User #{sn}" }
27       email { "user-#{sn}@example.com" }
28     end
29
30     User.blueprint(:admin) do
31       name  { "Admin User #{sn}" }
32       admin { true }
33     end
34
35 ### Associations
36
37     Post.blueprint do
38       author { User.make }
39
40       comments(3)    # Makes 3 comments (has_many / habtm)
41
42       author         # autodetect (Assumes there's User.blueprint)
43
44     end
45
46 ### References
47
48  * [https://github.com/notahat/machinist](https://github.com/notahat/machinist)