Object Daddy updates

February 19th, 2008 by ymendel 8 comments »

Man, that’s not a lot of scrollbar, good

Object Daddy has had a little bit of work done recently:

Widget.generator_for :foo, 'blah'
SubWidget.generate.foo # => 'blah'
SubWidget.generator_for :foo, 'blip'
SubWidget.generate.foo # => 'blip'

That’s all for now.

8 Responses to “Object Daddy updates”

  1. Chris Says:

    First, thanks for Object Daddy, it’s great! I’ve just started using it, but have two issues/questions:

    1) The docs say, “a call to User.generate will also make a call to Login.generate so that User#login is present, and therefore valid.” but in my use this doesn’t seem to hold true. I’ve needed to specify generate_for methods on objects for their associations.

    2) It seems that I need to save generated associated objects (relates to #1), in the generator for those associations. I would have thought it would follow Rails conventions where when you make the assignment it saves both objects, but I might be unclear on how all that works? For example, I originally had a generator that looked like:

    generator_for :organization => Organization.generate

    But, I found I needed to do this instead:

    generator_for :organization do
      org = Organization.generate

    I will continue to explore and try things out, but wanted to see if you could clarify issues related to associations. Thanks.

  2. Chris Says:

    Ramped up my use of object_daddy. I also found I wanted to make a slight change, so I’ve setup my own Git of object_daddy. Anyway, I’ve written up a blog entry stating my love of object_daddy, how it’s allowed me to almost completely elliminate fixtures, as well as how I love it in conjunction with Shoulda:


  3. Rick Bradley Says:

    Chris—thanks for the great writeup and the vote of confidence! Object_daddy is headed to github in the uber-near future, so maybe the forking and merging will get a little easier.

  4. Piers Cawley Says:

    Crumbs! Why did it take me so long to find out about ObjectDaddy?

    I shall be looking at ripping out my hand rolled specs/exemplars.rb in favour of this.

    It’s amazing how long ‘temporary’ can last isn’t it? I’ve been thinking “I should make it easier to define exemplars” since about the second generator I wrote. I wrote the original article on them because I was stalled on coming up with a good way of making them more generic and thought the technique was worth at least publishing as a pattern.

    So, thanks for doing my homework for me.

  5. Yossef Says:

    I had a response to Piers here, and it was a nice one. It said some stuff about how we were inspired by his exemplars.

    Then, in a fit of overzealous moderation, I deleted it. Woops!

  6. Yossef Says:

    Thanks to Rick’s searching and Google’s cache, the comment is back!

    It’s possible we should’ve mentioned this to you a while ago. I can’t remember if it’s mentioned in either the README or the first blog post that at least some of the inspiration came from you1 (note the use of ‘exemplar’), but just know that you had a part in fathering the daddy.

    [1] That’s a lot of reading, and I’m tired.

  7. My maps Says:

    Blog added to my favorites! :-)

  8. My maps Says:

    Blog added to my favorites! :-)

Leave a Reply