-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
add multiple inheritance support with parents #132
Comments
Hey, This sounds like a pretty awesome feature; get me a pull request with some tests and I'll get it merged in! You're going to want to add it to Thanks! |
I started work in this branch (https://github.com/thoughtbot/factory_girl/tree/allow-for-multiple-parents), but I have two failures. It looks like if child factories are defined, their implied attributes are being copied immediately. In my tests, that means that once admin is defined as a factory, parent attributes (name in particular) are copied into it instead of lazily evaluated. This means that after the admin factory is evaluated, the parent's name attribute (John) is copied into it and is eventually applied to the factory that has three parents defined. This isn't expected and should be fixed before merging. |
Instead of allowing for multiple factories to be used as parents, which brings along the issue of the parents parent being applied in the incorrect order since each parent loads it, how about something like "mixins" which would just be sets of attributes that do not inherit a parent and could be defined globally or within a factory for scoping purposes - this would change the example in the parents_spec into something like below
|
@twalpole I like this a bit more. I think I'd lean more towards |
Sure, I can try an initial implementation this evening |
@joshuaclayton I have pushed an initial implementation into the attribute_groups branch in my fork https://github.com/twalpole/factory_girl/tree/attribute_groups . The specs are based off the specs from your WIP and are all passing correctly currently. I need to add more specs and implementation for global attribute groups, but feedback on the current code would be appreciated. One more thing I thought that might be nice would be add a :factory option to the attr_group instruction that would allow for creating a factory directly from the attr_group. In the code below this would then create 3 factories (user, admin, male_admin) - thoughts?
|
@joshuaclayton I submitted a pull request implementing this functionality |
Cool - I'll comment on the pull request, thanks! |
This was merged into master; the work is here: 40d08ee...9dcb209 |
example:
The text was updated successfully, but these errors were encountered: