{"id":20866684,"url":"https://github.com/tristandunn/factory_manager","last_synced_at":"2025-10-22T21:43:10.109Z","repository":{"id":42501387,"uuid":"425113173","full_name":"tristandunn/factory_manager","owner":"tristandunn","description":"A manager for factory_bot to simplify creating nested factories.","archived":false,"fork":false,"pushed_at":"2025-05-11T15:00:37.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T03:16:53.485Z","etag":null,"topics":["factory","factory-bot","rspec","rspec-rails","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/factory_manager","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tristandunn.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.markdown","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"docs/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-11-05T23:47:45.000Z","updated_at":"2025-05-11T15:00:40.000Z","dependencies_parsed_at":"2023-02-14T05:10:14.742Z","dependency_job_id":"2edb9d34-4c7f-4f12-8c49-0bb10df98549","html_url":"https://github.com/tristandunn/factory_manager","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"43f38261a53cdfc7461610622a117f74bed5036a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandunn%2Ffactory_manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandunn%2Ffactory_manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandunn%2Ffactory_manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tristandunn%2Ffactory_manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tristandunn","download_url":"https://codeload.github.com/tristandunn/factory_manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253863171,"owners_count":21975596,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["factory","factory-bot","rspec","rspec-rails","ruby","ruby-on-rails"],"created_at":"2024-11-18T05:58:50.330Z","updated_at":"2025-10-22T21:43:10.031Z","avatar_url":"https://github.com/tristandunn.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# factory_manager [![Build Status](https://github.com/tristandunn/factory_manager/workflows/CI/badge.svg)](https://github.com/tristandunn/factory_manager/actions?query=workflow%3ACI)\n\nA factory manager of factory bots.\n\n#### Why?\n\nCreating a deeply nested set of records for seeding or testing can be difficult.\nfactory_manager creates a DSL based on available [factory_bot][] factories,\nallowing deeply nested records to be created easily.\n\n## Examples\n\n### Single-use\n\nProvide a block to `build` or `create` to generate the factories within the\nblock.\n\nCreate a forum, with a single category, a first post for the category, post with\na sequence generated title, an administrative user, and one-hundred approved\nposts by the administrator. Then create a featured category with a single post.\n\n```ruby\nresult = FactoryManager.create do |locals|\n  forum do\n    category(name: \"News\") do\n      post(title: \"First!\")\n      post(title: generate(:title))\n\n      locals.administrator = user(:admin)\n\n      post(100, :approved, user: locals.administrator)\n    end\n\n    featured_category do\n      post\n    end\n  end\nend\n\nresult.administrator\n# =\u003e User(id: 1, name: \"DHH\", admin: true)\nresult.administrator.posts.count\n# =\u003e 100\nresult.administrator.forum.categories.first.posts.count\n# =\u003e 102\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eView the factories for the example.\u003c/summary\u003e\n\n```ruby\nFactoryBot.defined do\n  factory :forum do\n    name { \"Ruby on Rails\" }\n  end\n\n  factory :category do\n    association :forum\n\n    name { \"Announcements\" }\n\n    factory :featured_category do\n      featured { true }\n    end\n  end\n\n  factory :user do\n    association :forum\n\n    name { \"DHH\" }\n\n    trait :admin do\n      admin { true }\n    end\n  end\n\n  factory :post do\n    association :category\n    association :user\n\n    title { \"How to install Ruby.\" }\n\n    trait :approved do\n      approved { true }\n    end\n  end\n\n  sequence(:title) { \"Title ##{rand}\" }\nend\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eView the example with inline comments.\u003c/summary\u003e\n\n```ruby\n# Starts a manager that will create records. Alternatively use\n# +FactoryManager.build+ to build records.\nresult = FactoryManager.create do |locals|\n  # Creates a +Forum+ record using the default attributes from the factory.\n  forum do\n    # Creates a +Category+ record with the default attributes but overrides the\n    # name. The +category.forum+ association will automatically be set to the\n    # +Forum+ record created above.\n    category(name: \"News\") do\n      # Create a +Post+ record with a custom title, automatically setting the\n      # +post.category+ association to the news category created above.\n      post(title: \"First!\")\n\n      # Create a +Post+ record with a sequence generated title, also automatically\n      # setting the # +post.category+ association to the news category created above.\n      post(title: generate(:title))\n\n      # Create a +User+ record using the +:admin+ trait. The +user.forum+\n      # association will automatically be set to the +Forum+ created above but\n      # a category will not be assigned. The +locals.administrator+ assignment\n      # will result in the user being available on the +result+ object.\n      locals.administrator = user(:admin)\n\n      # Create one-hundred +Post+ records using the +:approved+ trait setting\n      # the +post.user+ association to the administrator user created above and\n      # the +post.category+ to the news category created above.\n      post(100, :approved, user: locals.administrator)\n\n      # Create a +Category+ using the +featured_category+ factory and it\n      # automatically knows the parent factory is a +category+ to correctly\n      # associate child records, such as the single post created in it.\n      featured_category do\n        post\n      end\n    end\n  end\nend\n```\n\u003c/details\u003e\n\n### Multi-use\n\nProvide a name and block to `register` to register a manager, allowing you to\nprovide the name to `build` and `create` to generate the factories within the\nregistered block multiple times. Think of it as a factory of factories.\n\n```ruby\nFactoryManager.register(:lumbergh) do |locals|\n  locals.user = user do\n    tps_report(2, :incomplete)\n  end\nend\n\npeter = FactoryManager.create(:lumbergh).user\nsamir = FactoryManager.create(:lumbergh).user\n\npeter.id == samir.id\n# =\u003e false\npeter.tps_reports == samir.tps_reports\n# =\u003e false\npeter.tps_reports.count == samir.tps_reports.count\n# =\u003e true\n```\n\n## License\n\nfactory_manager uses the MIT license. See LICENSE for more details.\n\n[factory_bot]: https://github.com/thoughtbot/factory_bot\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristandunn%2Ffactory_manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftristandunn%2Ffactory_manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftristandunn%2Ffactory_manager/lists"}