Rails controller specs and private helper methods

Hello guys,

Been a while since last time I worked with Rails so is taking me a
while get back to full speed.

For a specific scenario I’m facing right now, I required to implement
a generic REST controller that accept any kind of resource and provide
a @collection or @record to work with.

I take from the route requirements the name of the resource
(params[‘resource_name’]) and then constantize it.

Since I keep doing that for several actions, I found cumbersome and
cryptic have this in my actions:

def index
@collection = params[‘resource_name’].camelize.constantize.find(…)
end

You get the idea: something very ugly and something that will break if
I don’t be careful enough.

So I tried to extract it to it’s own method (resource_class), but
wrapping my brain to spec it is taking me a while.

At this point, I don’t like the feeling that resource_class is being
stubbed or expected in some actions, but not actually executed.

This is the pastie:

http://pastie.org/247678

Do you guys think that will be best to put the resource_class stub
inside the actions and create another context to deal with those
internals?

Thanks in advance for your suggestions.

Luis L.
AREA 17

Human beings, who are almost unique in having the ability to learn from
the experience of others, are also remarkable for their apparent
disinclination to do so.
Douglas Adams

On Tue, Aug 5, 2008 at 9:09 AM, Luis L. [email protected]
wrote:

Do you guys think that will be best to put the resource_class stub
inside the actions and create another context to deal with those
internals?

I would. In fact, if it were really necessary to treat a generic
resource as a model, I’d consider wrapping it inside a model class and
spec’ing it out as a model.


Have Fun,
Steve E.
Deep Salt Team