class

Avram::Factory

Inherits Reference < Object

Constants

SEQUENCES = {} of String => Int32

Class methods

build_attributes
Source
build_attributes
Source
create
Source
create
Source
create_many(number : Int32)

Returns an array with number instances of the model from the Factory.

Usage:

tags = TagFactory.create_many(2)
typeof(tags) # => Array(Tag)
tags.size    # => 2
Source
create_many(number : Int32, &)

Similar to create_many(n), but accepts a block which yields the factory instance.

All factories receive the same argument values.

Usage:

TagFactory.create_many(2) do |factory|
  # set both factories name to "test"
  factory.name("test")
end
Source
create_pair

Returns an array with 2 instances of the model from the Factory.

Usage:

tags = TagFactory.create_pair
typeof(tags) # => Array(Tag)
tags.size    # => 2
Source
create_pair

Similar to create_pair, but accepts a block which yields the factory instance.

Both factories receive the same argument values.

Usage:

TagFactory.create_pair do |factory|
  # set both factories name to "test"
  factory.name("test")
end
Source

Instance methods

create
Source
operation
Source
sequence(value : String) : String

Returns a value with a number to use for unique values.

Usage:

class UserFactory < Avram::Factory
  def initialize
    username sequence("username")            # => username-1, username-2, etc.
    email "#{sequence("email")}@example.com" # => email-1@example.com, email-2@example.com, etc.
  end
end
Source

Macros

setup_attribute_shortcuts(operation)
Source
setup_attributes(operation)
Source
setup_callbacks(model_name)
Source