Schematic mixins
This feature would introduce a new primitive, the Fabricator.mixin
. It would allow you to declare a fieldset that is not associated with any given class. You could then use that in inheritence lists in other fabricators.
Declaration would look like this and support all the things you could do in a normal fabricator schematic.
Fabricator.mixin(:name_fields) do
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
full_name { |attrs| [attrs[:first_name], attrs[:last_name]].join(' ') }
end
You could then leverage these in any other fabricator regardless of the emitted object.
Fabricator(:user, mixins: :name_fields) do
# more fields specific to the User model
end
Fabricate(:customer, mixins: :name_fields) do
# also could work when generating
end
This could also just leverage the from
attribute. The benefit of that is it would allow you to apply mixins anywhere along the dependency chain. If done as a separate field they would apply after the from
attribute is applied.