# File lib/factory_girl/step_definitions.rb, line 2 def convert_association_string_to_instance(factory_name, assignment) attribute, value = assignment.split(':', 2) return if value.blank? attributes = convert_human_hash_to_attribute_hash(attribute => value.strip) factory = Factory.factory_by_name(factory_name) model_class = factory.build_class model_class.find(:first, :conditions => attributes) or Factory(factory_name, attributes) end
# File lib/factory_girl/step_definitions.rb, line 12 def convert_human_hash_to_attribute_hash(human_hash, associations = []) human_hash.inject({}) do |attribute_hash, (human_key, value)| key = human_key.downcase.gsub(' ', '_').to_sym if association = associations.detect {|association| association.name == key } value = convert_association_string_to_instance(association.factory, value) end attribute_hash.merge(key => value) end end
Generated with the Darkfish Rdoc Generator 2.