Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to access derived fixture names #45

Open
thewoolleyman opened this issue Dec 24, 2016 · 1 comment
Open

allow users to access derived fixture names #45

thewoolleyman opened this issue Dec 24, 2016 · 1 comment

Comments

@thewoolleyman
Copy link
Collaborator

Either somehow directly expose the generated name as soon as the record is created, or expose the logic to generate names.

This will allow users to use the fixture name to store hash of created instances by name, and reference them to provide as associated objects when creating subsequent fixtures which have a dependency on them, without having to manually assign a local variable to track the instance, or manually assign a name or naming block when the built-in automatic naming would work fine.

E.g.:

users = [Factory(:user, :name => "david")]
models[:user] = users.map{|u| fbuilder.fixture_name_for(u)}
Factory(:purchase, user: models[:user][:david])
@ibrahima
Copy link

I realize this is an old issue, but I agree that this would be super helpful, especially when trying to break things up into separate files as mentioned in https://github.com/rdy/fixture_builder#more-complete-config-example. I think in the meantime, one approach might be to set up a wrapper method that creates named fixtures and then stores them in a Hash, but I don't think that handles the automatic naming stuff unfortunately :(. It feels like at some level FixtureBuilder knows all the names of things at some point, but it might not compute them until after the factory method call ends so in the meantime you might end up needing to store references to objects some other way anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants