# Functional test, pls help!

**URL:** <https://www.ruby-forum.com/t/functional-test-pls-help/58061>\
**Category:** Rails\
**Created:** [April 18, 2006, 3:38am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061 "2006-04-18T03:38:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 3:38am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/1 "2006-04-18T03:38:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 10:31am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/2 "2006-04-18T10:31:16Z")

</div>

bao lee wrote:

> @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?

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 10:41am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/3 "2006-04-18T10:41:55Z")

</div>

Alex Y. wrote:

> bao lee wrote:
> 
> > @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…

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 10:46am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/4 "2006-04-18T10:46:47Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 11:29am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/5 "2006-04-18T11:29:55Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 11:37am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/6 "2006-04-18T11:37:21Z")

</div>

Alex Y. 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!!

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 19, 2006, 4:12am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/7 "2006-04-19T04:12:39Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![burninglegion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3bc359/32.png) [@burninglegion](https://www.ruby-forum.com/u/burninglegion)\
**Post date:** [April 18, 2006, 11:07am UTC](https://www.ruby-forum.com/t/functional-test-pls-help/58061/8 "2006-04-18T11:07:21Z")

</div>

Alex Y. 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
