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
# I put this as spec/support/factory_girl_singleton.rb | |
# this get required from spec_helper.rb | |
# creates a class variable for factories that should be only created once | |
class Factory | |
@@singletons = {} | |
def self.singleton(factory_key) | |
begin | |
@@singletons[factory_key] = Factory.create factory_key | |
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique | |
end |