Forum: RSpec possible to stub params hash ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Andrea J. (Guest)
on 2009-04-08 19:11
(Received via mailing list)
Hi,

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

Controller

 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 instance 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" => {}}
 controller.stub!(:params).and_return(params)

But then I get the following error:

undefined method `scope=' for
#<Searchlogic::Cache::PlPlanningSearch:0x6aa14cc>


Thanks in advance
Andrea





Verschicken Sie SMS direkt vom Postfach aus - in alle deutschen und
viele
ausländische Netze zum gleichen Preis!
https://produkte.web.de/webde_sms/sms
Scott T. (Guest)
on 2009-04-08 19:46
(Received via mailing list)
On Apr 8, 2009, at 11:09 AM, Andrea J. wrote:

>     @pl_planning = PlPlanning.find(params[:id])
>
> I tried:
>
>     params = {"pl_planning" => {}}
>     controller.stub!(:params).and_return(params)
>
> But then I get the following error:
>
> undefined method `scope=' for #<Searchlogic::Cache::PlPlanningSearch:
> 0x6aa14cc>
>

Usually you are will fare better if you pass the params directly in:

get :foo, :param1 => "something"

Why are you stubbing params?

Scott
This topic is locked and can not be replied to.