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:
- Trying to get it to work on Rails 2 uncovered some problems that were apparently there for a while, meaning they didn’t work well even with Rails 1.2.6 (or maybe 1.2.5). We were trying to figure out what the hell it was developed on so that the test suite ran. Maybe 1.2.3. Anyway, it’s generating stuff well now.
- New ways of creating generators!
- Klass.generator_for :attr do Time.now end # |prev| block argument not required
- Klass.generator_for :attr, value # if you want the same literal value every time
- Klass.generator_for :attr => value
- It now follows inheritance, which is especially nice for STI. To take the examples from the specs, assume a Widget class and a SubWidget class that inherits from Widget.
Widget.generator_for :foo, 'blah'
SubWidget.generate.foo # => 'blah'
SubWidget.generator_for :foo, 'blip'
SubWidget.generate.foo # => 'blip'
That’s all for now.
April 8th, 2008 at 02:50 AM
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:
But, I found I needed to do this instead:
I will continue to explore and try things out, but wanted to see if you could clarify issues related to associations. Thanks.
April 11th, 2008 at 02:34 PM
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:
http://codeintensity.blogspot.com/2008/04/shoulda-and-objectdaddy-sitting-in-tree.html
April 14th, 2008 at 07:54 PM
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.
November 20th, 2008 at 12:55 AM
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.
January 19th, 2009 at 11:10 AM
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!
January 19th, 2009 at 11:21 AM
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.
May 17th, 2009 at 04:07 PM
Blog added to my favorites! :-)
May 17th, 2009 at 04:10 PM
Blog added to my favorites! :-)