Hi guys, recently encountered this funny problem which i really dunno wat happen... I have been trying on it for the past few days and just doesnt work.Hope you guys can give me some enlightenment. Problem: The functional test doesnt seems to be able to recognise one of my model, and when i run the test, it keeps giving me the error of"You have nil object when you don''t expect it". I tried rake clone_structure_to_test but it still dont work. Checked my controllers code but it has a code that says : @countryinfo = Country.find(:first,:conditions=>["name = ?",@params[''country'']]) I dunno why the functional test just couldn''t seems to recognise this statement and so i gives me error that i am using a nil object in the view templates. Here is the actual error given : ActionView::TemplateError: You have a nil object when you didn''t expect it! The error occured while evaluating nil.two_letter_code . . 143: <input type="hidden" name="country" value="<%= @coun tryinfo.two_letter_code . . /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/base.rb:268:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/base.rb:268:in `compile_and_render_template'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/base.rb:244:in `render_template'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_view/base.rb:205:in `render_file'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb: 655:in `render_file'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb: 595:in `render_with_no_layout'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/layout.r b:220:in `render_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:53:in `render'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:53:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:53:in `render'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb: 854:in `perform_action_without_filters'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters. rb:332:in `perform_action_without_benchmark'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:69:in `measure'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmar king.rb:69:in `perform_action_without_rescue'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.r b:82:in `perform_action'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb: 369:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb: 369:in `process_without_session_management_support'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_ management.rb:116:in `process_without_test'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/test_pro cess.rb:16:in `process'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/test_pro cess.rb:300:in `process'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/test_pro cess.rb:307:in `post'' signup_controller_test.rb:26:in `test_zipdial_correct_flow'' /usr/lib/ruby/1.8/test/unit/testcase.rb:70:in `__send__'' /usr/lib/ruby/1.8/test/unit/testcase.rb:70:in `run'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:32:in `run'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:31:in `each'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:31:in `run'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:32:in `run'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:31:in `each'' /usr/lib/ruby/1.8/test/unit/testsuite.rb:31:in `run'' /usr/lib/ruby/1.8/test/unit/ui/testrunnermediator.rb:44:in `run_suite'' /usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:65:in `start_mediator'' /usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start'' /usr/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:27:in `run'' /usr/lib/ruby/1.8/test/unit/autorunner.rb:200:in `run'' /usr/lib/ruby/1.8/test/unit/autorunner.rb:13:in `run'' /usr/lib/ruby/1.8/test/unit.rb:285 /usr/lib/ruby/1.8/test/unit.rb:283 -- Posted via http://www.ruby-forum.com/.
bao lee wrote: <snip>> @countryinfo = Country.find(:first,:conditions=>["name = > ?",@params[''country'']]) > > I dunno why the functional test just couldn''t seems to recognise this > statement and so i gives me error that i am using a nil object in the > view templates.Have you loaded the countries fixtures? -- Alex
Alex Young wrote:> bao lee wrote: > <snip> >> @countryinfo = Country.find(:first,:conditions=>["name = >> ?",@params[''country'']]) >> >> I dunno why the functional test just couldn''t seems to recognise this >> statement and so i gives me error that i am using a nil object in the >> view templates. > Have you loaded the countries fixtures?erm.... do i need to do it?? tot it will go to the database itself to get it? hmm... -- Posted via http://www.ruby-forum.com/.
bao lee wrote:> Alex Young wrote: >> bao lee wrote: >> <snip> >>> @countryinfo = Country.find(:first,:conditions=>["name = >>> ?",@params[''country'']]) >>> >>> I dunno why the functional test just couldn''t seems to recognise this >>> statement and so i gives me error that i am using a nil object in the >>> view templates. >> Have you loaded the countries fixtures? > > erm.... do i need to do it?? tot it will go to the database itself to > get it? hmm...In order for the fixtures to be loaded into the database in the first place, there needs to be a ''fixtures :countries'' line in your test case (that''s assuming your fixtures file is called ''countries.yml'', which would be the default for an ActiveRecord class called Country). -- Alex
Alex Young wrote:> bao lee wrote: >> >> erm.... do i need to do it?? tot it will go to the database itself to >> get it? hmm... > In order for the fixtures to be loaded into the database in the first > place, there needs to be a ''fixtures :countries'' line in your test case > (that''s assuming your fixtures file is called ''countries.yml'', which > would be the default for an ActiveRecord class called Country).oh you are talking about that one... sure i have that, i tot you meant the data inside the countries database.... sorry for my mis-understanding... so it just output the error whenever it reachs the ''post'' stage, not even run the assert statement after it... here is the snippet of my controller code: class SignupControllerTest < Test::Unit::TestCase fixtures :countries def setup @controller = SignupController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new end # Replace this with your real tests. def test_zipdial_correct_flow get :default assert_response :success post :confirmation, { :name => ''burninglegion'', :country => "SG" } ,session assert_response :success end end -- Posted via http://www.ruby-forum.com/.
bao lee wrote:> here is the snippet of my controller code: > > class SignupControllerTest < Test::Unit::TestCase > fixtures :countries > > def setup > @controller = SignupController.new > @request = ActionController::TestRequest.new > @response = ActionController::TestResponse.new > end > > # Replace this with your real tests. > > def test_zipdial_correct_flow > get :default > assert_response :success > > post :confirmation, { :name => ''burninglegion'', :country => "SG" } > ,session > assert_response :success > end > endAssuming you''ve got a country named ''SG'' in your fixtures, try changing your controller code from @params[''country''] to params[:country]. You''re passing a symbol rather than a string as the key in the post params, but looking for a string in your controller. I think that should do it... -- Alex
Alex Young wrote:> bao lee wrote: >> >> end > Assuming you''ve got a country named ''SG'' in your fixtures, try changing > your controller code from @params[''country''] to params[:country]. > You''re passing a symbol rather than a string as the key in the post > params, but looking for a string in your controller. I think that > should do it...I tried it, and it still gives the same error.... it just seems that the functional test is not able to search for this model class (although it works normally if i do manual testing eg. click through the website myself) things i have done : create fixtures, change self.instantanized.fixtures to true in test_helper.rb checked that i have included "fixtures :countries" in the controller anything more i can do?? thanks man, alex.... your reply is fast!! -- Posted via http://www.ruby-forum.com/.
bao lee wrote: YEAH!!!! i solved the error!.... it seems that the error is due to the fixtures not having the correct data and RoR doesnt seems to care to tell you that it cannot locate in the fixtures. After adding the appropriate data in fixtures and rerun, it works! Special thanks to alex young for pointing it out.. thanks thanks.... -- Posted via http://www.ruby-forum.com/.