I am using factory girl to build the following objects: user and
blog. A user has one blog. A blog belongs to a user.
When I do the following
Factory.define :user do |u|
u.association :blog
end
I get this error: Mysql::Error: Column ''user_id'' cannot be
null: . I
suspect that is because factory tries to build a blog before it saves
the associated user object. I am getting around this problem by
creating the associated blog in the steps file:
Given /^"([^\"]*)" is a screen name of a user$/ do
|user_screen_name|
user = User.find_by_screen_name(user_screen_name)
if user.nil?
user = Factory.create(:user, :screen_name => user_screen_name)
Factory.create(:blog, :user_id => user.id)
end
end
This works but I don''t think it''s very elegant. What do you
think?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.