Module: FactoryGirl::Syntax::Generate::ActiveRecord::ClassMethods

Defined in:
lib/factory_girl/syntax/generate.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#generate(overrides = {}) {|instance| ... } ⇒ Object

Yields:

  • (instance)


44
45
46
47
48
49
50
# File 'lib/factory_girl/syntax/generate.rb', line 44

def generate(overrides = {}, &block)
  factory = FactoryGirl.factory_by_name(name.underscore)
  instance = factory.run(Proxy::Build, overrides)
  instance.save
  yield(instance) if block_given?
  instance
end

#generate!(overrides = {}) {|instance| ... } ⇒ Object

Yields:

  • (instance)


52
53
54
55
56
57
# File 'lib/factory_girl/syntax/generate.rb', line 52

def generate!(overrides = {}, &block)
  factory = FactoryGirl.factory_by_name(name.underscore)
  instance = factory.run(Proxy::Create, overrides)
  yield(instance) if block_given?
  instance
end

#spawn(overrides = {}) {|instance| ... } ⇒ Object

Yields:

  • (instance)


59
60
61
62
63
64
# File 'lib/factory_girl/syntax/generate.rb', line 59

def spawn(overrides = {}, &block)
  factory = FactoryGirl.factory_by_name(name.underscore)
  instance = factory.run(Proxy::Build, overrides)
  yield(instance) if block_given?
  instance
end