Machinist blueprints: Do not set associations without blocks

Posted Almost 10 years ago. Visible to the public.

TL;DR In blueprints, always wrap associations in blocks.

# Broken
Task.blueprint(:vacation) do
  project Project.make(:vacation)
  hours 8
  accounting_method 'none'
end
# Correct
Task.blueprint(:vacation) do
  project { Project.make(:vacation) }
  hours 8
  accounting_method 'none'
end

Without the block, Project.make will only run once when the blueprint is parsed (usually when RSpec is loaded), which is not what you want.

Dominik Schöler
Last edit
Over 5 years ago
Dominik Schöler
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2014-07-29 14:55)