Note: We are talking about Machinist 1 Show archive.org snapshot here, Machinist 2 may have solved this or might require a different approach.
Machinist allows named blueprints (e.g. User.blueprint(:admin)
) that inherit from the master blueprint (User.blueprint
).
If you also want to inherit from another blueprint (e.g. if "vip" should load "premium" and the master blueprint) you can do this:
User.blueprint(:vip) do
# Fields for the vip blueprint go here
instance_eval(&User.blueprint(:premium))
end
To do pretty things like...
User.blueprint(:vip) do
# Fields for the vip blueprint go here
inherit :premium
end
...put the attached code into spec/support/machinist_inherit.rb
and require 'spec/support/machinist_inherit'
in your blueprints.rb
. Note that it might not be sufficient to put the file into spec/support
and have the spec_helper.rb
require everything in that folder. Your blueprints.rb
might be required before machinist_inherit.rb
.
Note: Attributes that are already set will not be overwritten when defined again. Thus, put your inherit
calls after all other attribute definitions inside a blueprint.