-
-
Save renius/9af62ff8d68a932a8895 to your computer and use it in GitHub Desktop.
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
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
a fork which works with enums as well https://gist.github.com/coorasse/c9034a484eaf32fa6556