Avram::Factory
Constants
Class methods
build_attributes
Sourcebuild_attributes
Sourcecreate
Sourcecreate
Sourcecreate_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
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
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
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
Instance methods
create
Sourceoperation
SourceReturns 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
Macros
setup_attribute_shortcuts(operation)
Sourcesetup_attributes(operation)
Sourcesetup_callbacks(model_name)
Source