planon
2011-Apr-19 21:32 UTC
[rspec-users] "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?
Mike Mazur
2011-Apr-19 23:16 UTC
[rspec-users] "can''t convert Symbol into Integer" error with Rspec and Mongoid
Hi, On Wed, Apr 20, 2011 at 05:32, planon <spocksplanet at gmail.com> wrote:> 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)>''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