-
-
Save abinoam/4ab40317ef9d1424d808 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::Syntax::Methods | |
def find_or_create(name, attributes = {}, &block) | |
factory = FactoryGirl.factory_by_name(name) | |
clazz = factory.build_class | |
factory_attributes = FactoryGirl.attributes_for(name) | |
attributes = factory_attributes.merge(attributes) | |
clazz.find_or_create_by(attributes, &block) | |
end | |
end |
Thanks for this -
One thing I noticed, is that line #9
isn't actually using FactoryGirl
to create the object.
I've made some adjustments here: https://gist.github.com/thewatts/dcc91ef40b144aff42ae
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This last revision makes it: