Rpec_scaffold and nested resources

I’ve got a love-hate relationship with script/generate rspec_scaffold

If you are using non-nested controllers/resources it’s great. I love
the spec skeletons it generates.

But I find myself doing this, where Y is and existing set of
model/controller … representing a resource:

  1. script/generate rspec_scaffold x …

At this point rake spec passes.

  1. edit config/routes.rb and change it from:
    map.resources :ys
    map.resources :xs

to:
map.resources :ys do | y |
y.resources :xs
end

At this point rake spec fails on the routes and controller specs for
x, no big surprise. The controller needs to change as well.

This is followed by a manual editing session of BOTH the controller
and the specs, with lots of fairly tedious changes.

Of course most of this might be laid to the rails scaffold generator
not being able to generate nested resource controllers directly as a
prerequisite to rspec_scaffold, unless there’s something y’all know
that I don’t. (Well I’m sure that y’all know lots that I don’t but I
don’t know if it’s relevant to this). But the changes to the
controller are much easier than the changes to the specs.

I was starting to think about writing a plugin/tool to address this,
but I was wondering if anyone had any insight or had already started
down this path.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Dec 18, 2007 4:58 PM, Rick DeNatale [email protected] wrote:

I was starting to think about writing a plugin/tool to address this,
but I was wondering if anyone had any insight or had already started
down this path.

This is definitely something I’d like to see addressed, so if you come
up w/something that works I’ll commit it.

I don’t know if anyone is already working on it.

Someone has been working on it:

http://deaddeadgood.com/2008/10/8/scaffolding-nested-resources-in-rails
http://github.com/phorsfall/rspec_on_rails_nested_scaffold/tree/master

This works for me on rails 2.2.2 and the latest rspec-rails (1.1.11.1)