Q:

How to fix this RSpec error with Mongoid? "can't convert Symbol into Integer"

I'm writing tests for my controller. They are very simple, but this error has kept popping up. This is my controller
  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)>'

A:

your controller is where the mistake is.  The find method automatically only returns the first result (it is equivalent in code to User.where(:id => params[:id]).first).  Try removing the :first symbol and simply pass in id (User.find(id))

