Additional params to should_be_restful

0 views
Skip to first unread message

bhauff

unread,
Jun 17, 2008, 9:22:37 AM6/17/08
to shoulda
Hi,

I have a scenario where I need to pass additional parameters to the
controller when using the should_be_restful macro. For example, I
have a Roles controller that interacts with the Roles model and the
User model (restful_authentication). I need to pass in the
params[:user_id] for the User.find in the various actions of the Roles
controller. Shoulda tells me "ActiveRecord::RecordNotFound: Couldn't
find User without an ID". I have tried adding this parameter to the
resource.create.params and resource.update.params, as well as the test
classes setup method and individual contexts setup method and it never
gets passed through correctly. I have noticed that the additional
params are usually a part of the params[:role][:user_id] rather than
one level up in the params[:user_id] where you also find
params[:action], params[:id], and params[:controller].

I have searched around through the rdoc's without any luck, and I may
be trying to do more than should_be_restful is really meant to do.
Any help would be greatly appreciated.

Thanks,

Brandon Hauff

Chris O'Sullivan

unread,
Jun 17, 2008, 9:31:53 AM6/17/08
to sho...@googlegroups.com
Hi Brandon,

Perhaps you could stub out User.find?

e.g. (using mocha)

setup do
  @user = User.new
  User.stubs(:find).returns @user
  # .. snip
end

That way you won't need to pass any extra params to should_be_restful

-Chris

2008/6/17 bhauff <bha...@gmail.com>:

Tammer Saleh

unread,
Jun 17, 2008, 10:11:43 AM6/17/08
to sho...@googlegroups.com
Hi Brandon,

Yeah, I think you've hit the limit of should_be_restful.

Cheers,
Tammer

bhauff

unread,
Jun 17, 2008, 10:54:19 AM6/17/08
to shoulda
Thanks Chris, I will try doing some stubbing.

On Jun 17, 8:31 am, "Chris O'Sullivan" <thechrisos...@gmail.com>
wrote:

bhauff

unread,
Jun 17, 2008, 10:55:37 AM6/17/08
to shoulda
Thanks Tammer. I have been enjoying using shoulda and the
should_be_restful macro.
Reply all
Reply to author
Forward
0 new messages