Ruby on Rails Friday, September 3, 2010

On Fri, Sep 3, 2010 at 8:38 AM, Rick R <rickcr@gmail.com> wrote:
> On Fri, Sep 3, 2010 at 6:07 AM, Satsou Sa <lists@ruby-forum.com> wrote:
>
>> I had tried to write those factories:
>>
>>  Factory.define :article do |f|
>>    f.title "Hello, world"
>>  end
>>
>>  Factory.define :comment do |f|
>>    f.content "Awesome!"
>>    f.association :article
>>  end
>
> I'm still pretty newb, so I could be way off here, but I think you
> need to define the factory that represents the association?
>
> Factory.define :comment do |f|
>  f.content "Awesome!"
>  f.association :article, :factory => :article
> end
>

It's also a bit confusing because your naming your factories the same
as the property name. It might be more clear if you set them with more
'real' names like

Factory.define :hello_world_article, :class => Article do |f|
f.title "Hello, world"
end

Factory.define :awesome_comment, :class => Comment do |f|
f.content "Awesome!"
f.association :article, :factory => :hello_world_article
end

--
Rick R

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment