class FactoryGirlStepHelpers::HumanHashToAttributeHash::AssociationManager

Public Class Methods

new(human_hash_to_attributes_hash, key, value) click to toggle source
# File lib/factory_girl/step_definitions.rb, line 29
def initialize(human_hash_to_attributes_hash, key, value)
  @human_hash_to_attributes_hash = human_hash_to_attributes_hash
  @key   = key
  @value = value
end

Public Instance Methods

association() click to toggle source
# File lib/factory_girl/step_definitions.rb, line 35
def association
  @human_hash_to_attributes_hash.associations.detect {|association| association.name == @key }
end
association_instance() click to toggle source
# File lib/factory_girl/step_definitions.rb, line 39
def association_instance
  return unless association

  if attributes_hash = nested_attribute_hash
    factory.build_class.first(:conditions => attributes_hash.attributes(FindAttributes)) or
    FactoryGirl.create(association.factory, attributes_hash.attributes)
  end
end

Private Instance Methods

factory() click to toggle source
# File lib/factory_girl/step_definitions.rb, line 50
def factory
  FactoryGirl.factory_by_name(association.factory)
end
nested_attribute_hash() click to toggle source
# File lib/factory_girl/step_definitions.rb, line 54
def nested_attribute_hash
  attribute, value = @value.split(':', 2)
  return if value.blank?

  HumanHashToAttributeHash.new({ attribute => value }, factory.associations)
end