July 2017
Intermediate to advanced
284 pages
6h 45m
English
You can also create several entities together with a mutual list of attributes. Let’s say we want to create a few users, all sharing the same country_id attribute. We could use the having macro, like this:
| | ~~~ |
| | Forge.having country_id: usa_id do |
| | user = Forge.user |
| | admin = Forge.admin |
| | end |
| | ~~~ |
Now, both user and admin will have a country_id equal to usa_id. This advantage is small here, but will grow significantly with the number of attributes and entities that you need to manage. For example, in our tests, we may have dozens of questions and choices, all which have the same survey_id and company_id.
What if we need to create some other type of entity, like, say, an Elixir struct?
Read now
Unlock full access