Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Remove global Fabrication.manager reference in Defintion #313

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

bradgessler
Copy link

@bradgessler bradgessler commented May 23, 2019

Opening this PR to see if you're open to me removing more global references inside of Fabrication.

I have a weird use case where I need to use Fabrication both for testing/development in rails, but I also need a completely separate object generator in production that will live in app/factories. I'm hoping to isolate all of the global/singleton state into one class that lives outside of the Manager for the "normal" test/development use case.

The Manager can inject this into the Definition class since there's no
apparent public callers outside of the Fabrication gem that would use
this class.
@paulelliott
Copy link
Owner

Sure, I am open to talking about it. Can you explain in more detail why exactly the singleton here is an issue for your development and test case?

@bradgessler
Copy link
Author

Yeah!

I actually need to maintain two completely different sets of factories. The obvious set is for testing and development environments, which ‘Fabricator(:blah)’ handles well.

The problem is I don’t want the factories that will be used in my application code to have access to the test/development factories, so I need to create another instance of the manager to handle those factories.

From what I’ve seen so far in the code, most of the work involved in getting this out of a global dependency is the commits I’ve already done, then figuring out how to extract the file loader into another class that the manager can delegate to, and finally moving the ‘Factory(:blah)’ methods into a class, then delegating to an instance of that from the ‘Factory’ class/module

@paulelliott
Copy link
Owner

Would it not work for you to just override the fabricator path for production? Something like this:

Fabrication.configure do |config|
  config.fabricator_path = Rails.env.production? ? 'spec/fabricators' : 'app/fabricators'
end

@bradgessler
Copy link
Author

bradgessler commented May 23, 2019 via email

@paulelliott
Copy link
Owner

paulelliott commented May 23, 2019 via email

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants