Class: FactoryGirlStepHelpers::HumanHashToAttributeHash::AssociationManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_girl/step_definitions.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(human_hash_to_attributes_hash, key, value) ⇒ AssociationManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AssociationManager.



32
33
34
35
36
# File 'lib/factory_girl/step_definitions.rb', line 32

def initialize(human_hash_to_attributes_hash, key, value)
  @human_hash_to_attributes_hash = human_hash_to_attributes_hash
  @key   = key
  @value = value
end

Instance Method Details

#associationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/factory_girl/step_definitions.rb', line 38

def association
  @human_hash_to_attributes_hash.associations.detect {|association| association.name == @key }
end

#association_instanceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
49
# File 'lib/factory_girl/step_definitions.rb', line 42

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