Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not require FactoryBot preface before create

I am using FactoryBot in my seeds.rb to populate my database. I have to call FactoryBot. before I call build or create. Is there a way I can not have to do that? Also, should I even be using FactoryBot for seeding, or is it just for testing?

Note: FactoryBot was previously called FactoryGirl

like image 924
ThomYorkkke Avatar asked Dec 30 '25 15:12

ThomYorkkke


1 Answers

Including FactoryBot::Syntax::Methods into your seeds.rb file will allow you to call build or create without the FactoryBot prefix:

include FactoryBot::Syntax::Methods

As to whether it's a good idea, I can see how it's an appealing option but it seems to me that you'd be maintaining factories for two completely different purposes. Keeping them in sync as your application changes, or separating your test factories from your seed factories, seems problematic to me.

Note: FactoryBot was previously called FactoryGirl

like image 162
keyzee Avatar answered Jan 01 '26 07:01

keyzee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!