Class: FactoryGirl::Proxy

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/factory_girl/proxy.rb,
lib/factory_girl/proxy/stub.rb,
lib/factory_girl/proxy/build.rb,
lib/factory_girl/proxy/create.rb,
lib/factory_girl/proxy/attributes_for.rb

Overview

:nodoc:

Direct Known Subclasses

AttributesFor, Build, Stub

Defined Under Namespace

Classes: AttributesFor, Build, Create, Stub

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ensure_strategy_exists!(strategy) ⇒ Object



51
52
53
54
55
# File 'lib/factory_girl/proxy.rb', line 51

def self.ensure_strategy_exists!(strategy)
  unless Proxy.const_defined? strategy.to_s.camelize
    raise ArgumentError, "Unknown strategy: #{strategy}"
  end
end

Instance Method Details

#association(name, overrides = {}) ⇒ Object

Generates an association using the current build strategy.

Arguments:

name: (Symbol)
  The name of the factory that should be used to generate this
  association.
attributes: (Hash)
  A hash of attributes that should be overridden for this association.

Returns:

The generated association for the current build strategy. Note that
associations are not generated for the attributes_for strategy. Returns
nil in this case.

Example:

factory :user do
  # ...
end

factory :post do
  # ...
  author { |post| post.association(:user, :name => 'Joe') }
end

# Builds (but doesn't save) a Post and a User
FactoryGirl.build(:post)

# Builds and saves a User, builds a Post, assigns the User to the
# author association, and saves the Post.
FactoryGirl.create(:post)


44
45
# File 'lib/factory_girl/proxy.rb', line 44

def association(name, overrides = {})
end

#result(attribute_assigner, to_create) ⇒ Object

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/factory_girl/proxy.rb', line 47

def result(attribute_assigner, to_create)
  raise NotImplementedError, "Strategies must return a result"
end