[rspec-users] (rspec2/rails3) spec'ing the details of a controller that is not purely *skinny* by design.

Frank J. Mattia frankjmattia at gmail.com
Thu Jul 8 12:17:31 EDT 2010

Looks like I didn't read the instructions before posting...
I'm hoping that the "moderator" is /dev/null - otherwise this might
come up as a repost.

I want my controller to set certain attributes on #create and #update
(mostly created_by, updated_by... etc.) -- implementing this is easy.
Testing it before implementing it has been nearly impossible for me.

As a side note: I have put this logic into the controller on purpose.
I do believe in the fat model/skinny controller paradigm but believe
that for this situation, it's the controllers responsibility for a
variety of reasons. Not the least of which being the controller has
access to the session and knows who's doing what to whom. I could just
put the current_user_id in a hidden field on the forms but I can't
help but think that would lead to tampering... Anyway.

My controller does something like this for create
@object = Object.new(params[:object])
@object.created_by = current_user
if @object.save... yadda yadda yadda...

I have my model spec testing for the presence of created_by but I feel
compelled to test that my controller is correctly setting current_user
on its appropriate actions. Does this seem reasonable? If so, what's
the proper way to test it? I tried testing first and though my
failings ended up with an implementation first but that's neither here
nor there.

Any insight?

More information about the rspec-users mailing list