Skip to content

Instantly share code, notes, and snippets.

@rorcraft
rorcraft / gist:1036930
Created June 21, 2011 00:08
Factory_girl singleton monkey patch
# 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