Class: Gonzales::Factories

Inherits:
Object
  • Object
show all
Defined in:
lib/gonzales/factories.rb

Overview

Gonzales::Factories

Facitity to instantiate factories in database during db:test:prepare

Class Method Summary collapse

Class Method Details

.load {|_self| ... } ⇒ Object

Yields a block to define speedy statements, then saves a collection of references to a temporary file

Yields:

  • (_self)

Yield Parameters:



51
52
53
54
55
56
# File 'lib/gonzales/factories.rb', line 51

def self.load(&block)
  Collection.clear_cache
  ::FactoryGirl.reload
  yield self
  Collection.save
end

.speedy(factory_or_alias_name, *args) ⇒ Object

Save a factory based record to the test database before executing tests

Arguments

* alias_name - optional alias name (can be used to reference factory or associations later)
* factory_name - the name of the factory (use to reference factory or associations later if alias is not given)
* options - a hash to be passed to FactoryGirl when creating the record

Examples

Gonzales::Factories.load do |go|
  go.speedy :address
  go.speedy :organization
  go.speedy :john, :person, :name => 'John'
end


43
44
45
46
47
48
# File 'lib/gonzales/factories.rb', line 43

def self.speedy(factory_or_alias_name, *args)
  alias_name = factory_or_alias_name
  options = args.extract_options!
  factory_name = args.first || alias_name
  Collection.add alias_name, Factory.create(factory_name, options)
end