Re: RSpec passing object as a param in a controller_spec

30 views
Skip to first unread message

Myron Marston

unread,
Feb 6, 2013, 10:05:31 AM2/6/13
to rspec
On Feb 6, 6:06 am, Dromga <drom...@gmail.com> wrote:
> I have a users_controller_spec.rb with this:
>
> describe "POST create" do
>   describe "with valid params" do
>     let(:user) { create(:user) }
>
>     it "assigns a newly created user as @user" do
>       post :create, user: user
>       assigns(:user).should be_a(User)
>       assigns(:user).should be_persisted
>     end
>   end
>
>  ...
> end
>
> Debuggin I found that the controller receive the next params
>
> (rdb:1) pp params{"user"=>"1", "controller"=>"users", "action"=>"create"}
>
> Why "user" => "1" ?, why is not passing the user object properly ?

You can't pass ruby object references over HTTP. I'm guessing
`user.to_param` returns '1'. ActionPack uses `to_param` in many places
when constructing URLs, or getting an HTTP representation of an
object.

Myron

Dromga

unread,
Feb 6, 2013, 11:36:59 AM2/6/13
to rs...@googlegroups.com
I didn't know about that, i've sorted it out, thanks!
Reply all
Reply to author
Forward
0 new messages