Was just wondering, in factorygirl, you can factory up a model and get
it's dependent relationships for free if you set up your factories.rb
with the relationships.
How do you do this in machinist?
ie.
class Theme < ActiveRecord::Base
validates_presence_of :name
end
class Website < ActiveRecord::Base
belongs_to :theme
validates_presence_of :theme
end
in factory girl:
Factory.define :theme do |f|
f.name { "foo" }
end
Factory.define :website do |f|
f.theme { Factory(:theme) }
end
>> Factory(:website).theme.name
>> "foo"
in machinist:
Theme.blueprint do
name { "foo" }
end
Website.blueprint do
end
>> Website.make.theme.name
ActiveRecord::RecordInvalid: Validation failed: Theme can't be blank
This is what I have been using for a blueprint workaround but it's not
as succinct as the factorygirl way:
>> Website.make(:theme => Theme.make).theme.name
>> "foo"
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.