forked from thoughtbot/factory_bot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New default syntax for using defined factories
- Loading branch information
Showing
13 changed files
with
139 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
module FactoryGirl | |||
module Syntax | |||
module Methods | |||
# Generates and returns a Hash of attributes from this factory. Attributes | |||
# can be individually overridden by passing in a Hash of attribute => value | |||
# pairs. | |||
# | |||
# Arguments: | |||
# * name: +Symbol+ or +String+ | |||
# The name of the factory that should be used. | |||
# * overrides: +Hash+ | |||
# Attributes to overwrite for this set. | |||
# | |||
# Returns: +Hash+ | |||
# A set of attributes that can be used to build an instance of the class | |||
# this factory generates. | |||
def attributes_for(name, overrides = {}) | |||
FactoryGirl.factory_by_name(name).run(Proxy::AttributesFor, overrides) | |||
end | |||
|
|||
# Generates and returns an instance from this factory. Attributes can be | |||
# individually overridden by passing in a Hash of attribute => value pairs. | |||
# | |||
# Arguments: | |||
# * name: +Symbol+ or +String+ | |||
# The name of the factory that should be used. | |||
# * overrides: +Hash+ | |||
# Attributes to overwrite for this instance. | |||
# | |||
# Returns: +Object+ | |||
# An instance of the class this factory generates, with generated attributes | |||
# assigned. | |||
def build(name, overrides = {}) | |||
FactoryGirl.factory_by_name(name).run(Proxy::Build, overrides) | |||
end | |||
|
|||
# Generates, saves, and returns an instance from this factory. Attributes can | |||
# be individually overridden by passing in a Hash of attribute => value | |||
# pairs. | |||
# | |||
# Instances are saved using the +save!+ method, so ActiveRecord models will | |||
# raise ActiveRecord::RecordInvalid exceptions for invalid attribute sets. | |||
# | |||
# Arguments: | |||
# * name: +Symbol+ or +String+ | |||
# The name of the factory that should be used. | |||
# * overrides: +Hash+ | |||
# Attributes to overwrite for this instance. | |||
# | |||
# Returns: +Object+ | |||
# A saved instance of the class this factory generates, with generated | |||
# attributes assigned. | |||
def create(name, overrides = {}) | |||
FactoryGirl.factory_by_name(name).run(Proxy::Create, overrides) | |||
end | |||
|
|||
# Generates and returns an object with all attributes from this factory | |||
# stubbed out. Attributes can be individually overridden by passing in a Hash | |||
# of attribute => value pairs. | |||
# | |||
# Arguments: | |||
# * name: +Symbol+ or +String+ | |||
# The name of the factory that should be used. | |||
# * overrides: +Hash+ | |||
# Attributes to overwrite for this instance. | |||
# | |||
# Returns: +Object+ | |||
# An object with generated attributes stubbed out. | |||
def build_stubbed(name, overrides = {}) | |||
FactoryGirl.factory_by_name(name).run(Proxy::Stub, overrides) | |||
end | |||
|
|||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.