"can't convert Symbol into Integer" error with Rspec and Mongoid

I’m running into this error while trying to run a unit test on a
Mongoid database:

def show
id=params[:id]
@user=User.find(:first,id)
end

My test

before(:each) do
@user = Fabricate(:user)
sign_in @user
end

it “should be successful” do
get “show”, :id => @user
response.should be_success
end

And the error message

  1. UsersController GET ‘show’ for the logged in user should be
    successful
    Failure/Error: get “show”, :id => @user
    TypeError:
    can’t convert Symbol into Integer

    ./app/controllers/users_controller.rb:6:in `show’

    ./spec/controllers/users_controller_spec.rb:31:in `block (4

levels) in <top (required)>’

Does anyone know why this keeps happening and what I can do to fix
it?

Hi,

On Wed, Apr 20, 2011 at 05:32, planon [email protected] wrote:

before(:each) do

  1. UsersController GET ‘show’ for the logged in user should be
    successful
    Failure/Error: get “show”, :id => @user
    TypeError:
    can’t convert Symbol into Integer

./app/controllers/users_controller.rb:6:in `show’

./spec/controllers/users_controller_spec.rb:31:in `block (4

levels) in <top (required)>’

Try adding to_param in your spec:

get “show”, :id => @user.to_param

What’s happening is the “show” action receives the entire user object
in params[:id] instead of just an id.

Mike

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs