Re: possible to stub params hash?


I tried to stub the params method of the Controller because
I got the error " You have a nil object when you didn’t expect it!"
for the access to params[:pl_planning][“item_model_version_id”]
in the update action.

I thought, that the stubbing is not working because of the following
“undefined method `scope=’ for

But now I found out, that this error has another reason.
The put :update does not call the update action, it calls the index
I will post another email for that problem to the user group.


Von: “Scott T.” [email protected]
Gesendet: 08.04.09 17:46:31
An: rspec-users [email protected]
Betreff: Re: [rspec-users] possible to stub params hash ?

On Apr 8, 2009, at 11:09 AM, Andrea J. wrote:


I added one line in my controller to extend the params hash. But now I
get errors
in my controller spec.


def update
@pl_planning = PlPlanning.find(params[:id])

the item model version (select box) depends on other select boxes and

can be empty

then it is not in the params hash and the attribute would not be

updated and validated
–> params[:pl_planning][“item_model_version_id”] ||= “”

update planning attributes

@pl_planning.attributes = params[:pl_planning]

Controller Spec error:

You have a nil object when you didn’t expect it!
You might have expected an i nstance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

What do I have to add in my spec for that ?

I tried:

params = {“pl_planning” => {}}

But then I get the following error:

undefined method `scope=’ for
Usually you are will fare better if you pass the params directly in:
get :foo, :param1 => “something”
Why are you stubbing params?

Thanks in advance

Verschicken Sie SMS direkt vom Postfach aus - in alle deutschen und
ausländische Netze zum gleichen Preis!


rspec-users mailing list
[email protected] [mailto:[email protected]]
_______________________________________________rspec-users mailing
[email protected]://

GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter

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