-
-
Save renius/9af62ff8d68a932a8895 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module FactoryGirl | |
module Syntax | |
module Methods | |
def find_or_create(name, attributes = {}, &block) | |
attributes = FactoryGirl.attributes_for(name).merge(attributes) | |
result = | |
FactoryGirl. | |
factory_by_name(name). | |
build_class. | |
find_by(attributes, &block) | |
result || FactoryGirl.create(name, attributes, &block) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for putting up this gist!
This helped me a lot. I've put this code inside
spec/rails_helper.rb
. I am a factory_girl noob, and I am sure there is a better place to put this code.Where can I put this code?
Thanks in advance!