Hi All,

I'm hoping someone can help me out here.

I'm building a suite of tests for my (reasonably large) Rails app. I'm using Rails 3.2 and I *was* using FactoryGirl, but I found that it wasn't able to build me the object graphs that I needed.

(Basically it doesn't have a feature to re-use existing objects that are created in the database in previous steps).

I've got a Model that references three other models, two of which reference one other Model each. I want to simply call FactoryGirl.create on the first model, and have it intelligently build the related objects... the only issue is some of those objects should not be re-created.

Essentially what I want is sets of remembered named objects that can be referred to each other in a factory, but FactoryGirl nor Machinist seem to do this at all. Machinist comes closest to what I want to do in that it lets you override the attributes (and associations), yet it seems borked in that Machinist 2's make! method doesn't seem to create the related objects in for Rails 3.2.

Can anyone help out here? I'm trying to use the path of least resistance to doing BDD (or at least putting it on after the fact) and I seem to be getting stuck at the start of my object graph in order to do some of the set up for my steps / tests.

Julian


--
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.

Search Discussions

  • Peter Vandenabeele at Feb 17, 2012 at 9:26 am

    On Fri, Feb 17, 2012 at 6:31 AM, Julian Leviston wrote:

    Hi All,

    I'm hoping someone can help me out here.

    I'm building a suite of tests for my (reasonably large) Rails app. I'm
    using Rails 3.2 and I *was* using FactoryGirl, but I found that it wasn't
    able to build me the object graphs that I needed.

    (Basically it doesn't have a feature to re-use existing objects that are
    created in the database in previous steps).

    I've got a Model that references three other models, two of which
    reference one other Model each. I want to simply call FactoryGirl.create on
    the first model, and have it intelligently build the related objects... the
    only issue is some of those objects should not be re-created.

    Essentially what I want is sets of remembered named objects that can be
    referred to each other in a factory, but FactoryGirl nor Machinist seem to
    do this at all. Machinist comes closest to what I want to do in that it
    lets you override the attributes (and associations), yet it seems borked in
    that Machinist 2's make! method doesn't seem to create the related objects
    in for Rails 3.2.

    Can anyone help out here? I'm trying to use the path of least resistance
    to doing BDD (or at least putting it on after the fact) and I seem to be
    getting stuck at the start of my object graph in order to do some of the
    set up for my steps / tests.
    Could you show the Factory you are using now and how that exactly it fails
    or what you
    cannot do?

    I presume the problem can be solved. I use a mix of FactoryGirl for
    creating short lived objects
    (mostly in memory, sometimes in the database) and some static data in the
    database where I
    find that more appropriate.

    HTH,

    Peter


    --
    *** Available for a new project ***

    Peter Vandenabeele
    http://twitter.com/peter_v
    http://rails.vandenabeele.com
    http://coderwall.com/peter_v

    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 17, '12 at 5:31a
activeFeb 17, '12 at 9:26a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase