Please enable JavaScript.
Coggle requires JavaScript to display documents.
Factory Bot - Coggle Diagram
Factory Bot
-
មាន ៤ strategries: build, create, attributes_for, build_stubbed
- build: return an instance NOT SAVE
- create: return a SAVED instance
- build_stubbed: return an object and SET all attributes
- attributes_for:
Attribute Overrides
build(:post, title: "new title")
Aliases
easy to re-use
factory :user, aliases: [:author, :commenter] do
...
end
factory :post do
# or association :author, factory: :user
author
end
factory :comment do
# or association :commenter, factory: :user
commenter
end
Dependent Attribute
Base on other attributes, to create
another dynamic attribute
-
Transient Attribute
- ONLY available inside factory definition
- Use to build complex logic
-