1. Intro
  2. 1. Build strategies
  3. 2. FactoryBot.find_definitions
  4. 3. FactoryBot.define
  5. 4. factory
  6. 5. add_attribute
  7. 6. association
  8. 7. sequence
  9. 8. trait
  10. 9. method_missing
  11. 10. traits_for_enum
  12. 11. skip_create, to_create, and initialize_with
  13. 12. transient
  14. 13. Hooks
  15. 14. FactoryBot.modify
  16. 15. FactoryBot.lint
  17. 16. FactoryBot.register_strategy
  18. 17. Setup
    1. 17.1. Using Without Bundler
    2. 17.2. Rails Preloaders and RSpec
  19. 18. Defining factories
    1. 18.1. Factory name and attributes
    2. 18.2. Specifying the class explicitly
    3. 18.3. Definition file paths
    4. 18.4. Hash attributes
    5. 18.5. Best practices
    6. 18.6. Static Attributes (deprecated)
  20. 19. Using factories
    1. 19.1. Build strategies
    2. 19.2. Building or Creating Multiple Records
    3. 19.3. Attribute overrides
  21. 20. Aliases
  22. 21. Dependent Attributes
  23. 22. Transient Attributes
    1. 22.1. With other attributes
    2. 22.2. With attributes_for
    3. 22.3. With callbacks
    4. 22.4. With associations
  24. 23. Method Name / Reserved Word Attributes
  25. 24. Inheritance
    1. 24.1. Nested factories
    2. 24.2. Assigning parent explicitly
    3. 24.3. Best practices
  26. 25. Associations
    1. 25.1. Implicit definition
    2. 25.2. Explicit definition
    3. 25.3. Inline definition
    4. 25.4. Specifying the factory
    5. 25.5. Overriding attributes
    6. 25.6. Association overrides
    7. 25.7. Build strategies
  27. 26. Sequences
    1. 26.1. Global sequences
    2. 26.2. With dynamic attributes
    3. 26.3. As implicit attributes
    4. 26.4. Inline sequences
    5. 26.5. Initial value
    6. 26.6. Without a block
    7. 26.7. Aliases
    8. 26.8. Rewinding
    9. 26.9. Uniqueness
  28. 27. Traits
    1. 27.1. As implicit attributes
    2. 27.2. Using traits
    3. 27.3. Enum traits
    4. 27.4. Attribute precedence
    5. 27.5. In child factories
    6. 27.6. As mixins
    7. 27.7. With associations
    8. 27.8. Traits within traits
    9. 27.9. With transient attributes
  29. 28. Callbacks
    1. 28.1. Multiple callbacks
    2. 28.2. Global callbacks
    3. 28.3. Symbol#to_proc
  30. 29. Modifying factories
  31. 30. Linting Factories
  32. 31. Custom Construction
  33. 32. Custom Strategies
  34. 33. Custom Callbacks
  35. 34. Custom Methods to Persist Objects
  36. 35. ActiveSupport Instrumentation
  37. 36. has_many associations
  38. 37. has_and_belongs_to_many associations
  39. 38. Polymorphic associations
  40. 39. Interconnected associations

factory_bot

Using factories