Skip to content

Instantly share code, notes, and snippets.

View maunovaha's full-sized avatar

Mauno Vähä maunovaha

View GitHub Profile
module FactoryGirl
module Syntax
module Methods
def find_or_create(name, *attributes, &block)
attributes = FactoryGirl.attributes_for(name, *attributes)
klass = FactoryGirl.factory_by_name(name).build_class
enums = klass.defined_enums
find_attributes = attributes.clone
find_attributes.keys.each do |key|
find_attributes[key] = enums[key.to_s][find_attributes[key]] if enums.has_key?(key.to_s)