Parent

FactoryGirl::Factory

Public Instance Methods

associations() click to toggle source
# File lib/factory_girl/factory.rb, line 54
def associations
  attributes.select {|attribute| attribute.association? }
end
compile() click to toggle source
# File lib/factory_girl/factory.rb, line 87
def compile
  parent.defined_traits.each {|trait| define_trait(trait) }
  parent.compile
  @definition.compile
end
factory_name() click to toggle source
# File lib/factory_girl/factory.rb, line 23
def factory_name
  $stderr.puts "DEPRECATION WARNING: factory.factory_name is deprecated; use factory.name instead."
  name
end
human_names() click to toggle source
# File lib/factory_girl/factory.rb, line 50
def human_names
  names.map {|name| name.to_s.humanize.downcase }
end
names() click to toggle source

Names for this factory, including aliases.

Example:

factory :user, :aliases => [:author] do
  # ...
end

FactoryGirl.create(:author).class
# => User

Because an attribute defined without a value or block will build an association with the same name, this allows associations to be defined without factories, such as:

factory :user, :aliases => [:author] do
  # ...
end

factory :post do
  author
end

FactoryGirl.create(:post).author.class
# => User
# File lib/factory_girl/factory.rb, line 83
def names
  [name] + @aliases
end
with_traits(traits) click to toggle source
# File lib/factory_girl/factory.rb, line 93
def with_traits(traits)
  self.clone.tap do |factory_with_traits|
    factory_with_traits.inherit_traits traits
  end
end

Protected Instance Methods

attributes() click to toggle source
# File lib/factory_girl/factory.rb, line 105
def attributes
  compile
  AttributeList.new(@name).tap do |list|
    traits.each do |trait|
      list.apply_attributes(trait.attributes)
    end

    list.apply_attributes(@definition.attributes)
    list.apply_attributes(parent.attributes)
  end
end
callbacks() click to toggle source
# File lib/factory_girl/factory.rb, line 117
def callbacks
  [parent.callbacks, traits.map(&:callbacks).reverse, @definition.callbacks].flatten
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.