Rails' find_or_initialize_by method accepts an optional block, but that block is only executed when an existing record is not found by the provided attributes.| kevinjmurphy.com
Tests will sometimes require us to bend the truth and modify the state of the world in order to have repeatable, consistent results and feedback. Learn how to build your own method using a block to temporarily change what's true in an application with this article.| Kevin Murphy