factory_bot icon indicating copy to clipboard operation
factory_bot copied to clipboard

Rough draft of Namespaced Factories

Open zspencer opened this issue 4 years ago • 6 comments

See: https://github.com/thoughtbot/factory_bot/issues/199

I have a number of clients who use FactoryBot and are working through the difficult challene of decomposing a large monolith into either domain-driven namespaces; or small gems/engines that are "plugged into" a larger monolith.

In most cases, we've been able to get away with keeping the factories bundled with their extracted modules and using distinct names.

However there's also been a bit of copy-pasting of factory code back into the monolith in cases where the names really do need to be shared.

This is an attempt to bring @joshuaclayton's example of namespacing into the core FactoryBot DSL.

If you'd prefer I packaged this as it's own gem, I'd be happy to do so; but I'd be stoked to see this in the core FactoryBot package!

zspencer avatar Nov 24 '20 01:11 zspencer

@entcheva I'm an unrelated third party, but is there any progress on this? I looks like this PR is waiting on ThoughtBot's response.

elliotcm avatar May 29 '22 10:05 elliotcm

@elliotcm - I've been using this in production for about a year and a half now. It's not perfect; but I'd be down to publish it as a standalone gem sometime this week if you'd like.

zspencer avatar May 29 '22 17:05 zspencer

@elliotcm - I've been using this in production for about a year and a half now. It's not perfect; but I'd be down to publish it as a standalone gem sometime this week if you'd like.

@zspencer That'd be great! Thanks.

elliotcm avatar May 29 '22 18:05 elliotcm

@elliotcm - https://github.com/zinc-collective/factory_bot_namespaced_factories Here ya go! I just pulled it out of the production application I've been using it in since 2020. We mostly relied on our relatively comprehensive test suite to actually test the gem; but if you want to add better docs / specs / etc. I'd be happy to take patches!

zspencer avatar May 30 '22 22:05 zspencer

@zspencer AGPL? Wouldn't that license prevent me from using this in a closed-source business application?

gap777 avatar Sep 14 '22 17:09 gap777

@gap777 - My understanding is that AGPL is safe to use in proprietary applications; so long as you're not distributing it as part of your production deployment. That said, I believe Sidekiq uses the LGPL so maybe I am mixed up.

zspencer avatar Sep 16 '22 23:09 zspencer