-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transient attributes with fabrication
- Loading branch information
1 parent
b3b82b2
commit b568302
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
_posts/2013-09-16-transient-attributes-with-fabrication.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
layout: article_lite | ||
title: Transient Attributes with Fabrication | ||
description: Here I'll show you a brief example of how to use transient attributes with the Fabrication gem! | ||
permalink: /transient-attributes-with-fabrication.html | ||
--- | ||
|
||
<h1 class="title">{{ page.title }} | ||
{% include _twitter_share.html %} | ||
</h1> | ||
|
||
While writing a cucumber feature last week I found myself needing to assert on the count of a given associated model. The feature looked a bit like this (domain has been changed for clarity): | ||
{% gist 6588523 transient_feature.feature %} | ||
|
||
Unfortunately, we do not have the ability to tell the fabricator how many authors we'll need directly on the model, so the above feature won't work. To get it to work we can head on into the fabricator file for `Article`. We'll use `transient_attributes` to hold our `authors_count` temporarily, then we'll use it on an after create to create the proper number of authors. | ||
{% gist 6588551 transient_fabrciator.rb %} | ||
|
||
|
||
And there we go. | ||
|
||
## A few small notes | ||
|
||
* The step `Given the following articles with authors` is a *Fabrication* step. | ||
* To generate these run `rails generate fabrication:cucumber_steps` which creates several step definitions for interacting with fabricators. | ||
|
||
Thanks for reading. So sorry I've brought another blog example into this world. Forgive me. | ||
|
||
:) | ||
|
||
|