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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090408/ef99ac57/attachment-0001.html>
On Apr 8, 2009, at 11:09 AM, Andrea Jahn wrote:> > 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 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" => {}} > 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> > 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 > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090408/2829a516/attachment.html>
Hi, 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 error: "undefined method `scope='' for #<Searchlogic::Cache::PlPlanningSearch:0x6aa14cc>". But now I found out, that this error has another reason. The put :update does not call the update action, it calls the index action. I will post another email for that problem to the user group. Thanks Andrea *Von:* "Scott Taylor" <scott at railsnewbie.com> *Gesendet:* 08.04.09 17:46:31 *An:* rspec-users <RSPEC-USERS at RUBYFORGE.ORG> *Betreff:* Re: [rspec-users] possible to stub params hash ? On Apr 8, 2009, at 11:09 AM, Andrea Jahn wrote: 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 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" => {}} 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 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 [https://produkte.web.de/webde_sms/sms] _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org [mailto:rspec-users at rubyforge.org] http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________rspec-users mailing listrspec-users at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users GRATIS f?r alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter *http://movieflat.web.de* [http://movieflat.web.de] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090409/17ed2fab/attachment-0001.html>
The stub for params was the reason, that put :update has called the index action. Now I pass the params directly in and it works fine: put :update, :pl_planning => {"title" => "Project 1"} Scott, thanks a lot for the tip !!! Andrea *Von:* "Andrea Jahn" <anja-email1 at web.de> *Gesendet:* 09.04.09 16:03:53 *An:* rspec-users <RSPEC-USERS at RUBYFORGE.ORG> *Betreff:* Re: [rspec-users] possible to stub params hash ? Hi, 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 error: "undefined method `scope='' for #<Searchlogic::Cache::PlPlanningSearch:0x6aa14cc>". But now I found out, that this error has another reason. The put :update does not call the update action, it calls the index action. I will post another email for that problem to the user group. Thanks Andrea *Von:* "Scott Taylor" <scott at railsnewbie.com> *Gesendet:* 08.04.09 17:46:31 *An:* rspec-users *Betreff:* Re: [rspec-users] possible to stub params hash ? On Apr 8, 2009, at 11:09 AM, Andrea Jahn wrote: 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 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" => {}} 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 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 [https://produkte.web.de/webde_sms/sms] _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org [mailto:rspec-users at rubyforge.org] http://rubyforge.org/mailman/listinfo/rspec-users _______________________________________________rspec-users mailing listrspec-users at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users GRATIS f?r alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter *http://movieflat.web.de* [http://movieflat.web.de/] _______________________________________________rspec-users mailing listrspec-users at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users GRATIS f?r alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter *http://movieflat.web.de* [http://movieflat.web.de] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090409/ef2aa8df/attachment.html>