# How to write test case for DataBase search

**URL:** <https://www.ruby-forum.com/t/how-to-write-test-case-for-database-search/125325>\
**Category:** Rails\
**Created:** [January 8, 2008, 8:50am UTC](https://www.ruby-forum.com/t/how-to-write-test-case-for-database-search/125325 "2008-01-08T08:50:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [January 8, 2008, 8:50am UTC](https://www.ruby-forum.com/t/how-to-write-test-case-for-database-search/125325/1 "2008-01-08T08:50:33Z")

</div>

Hi All

i have written codes to do a database search in my appication using the  
mysql fully text search. it works properly.

bt now i have a problem in writing test case for it. so can some body  
pls help me how to write testing codes for this database searching  
function.

Thanks  
Nadeesha

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [January 9, 2008, 3:05am UTC](https://www.ruby-forum.com/t/how-to-write-test-case-for-database-search/125325/2 "2008-01-09T03:05:24Z")

</div>

If you have built an application using scaffold then you can easily  
modify  
database search criteria. Just modify the first line in the controller  
script

> @myController = myController.find :all

to something like

> @mController = myController.find :all, :name =\> “Controller Name”

This is Ruby for SELECT \* FROM my\_controllers WHERE name=‘Controller  
Name’

> 

If you are new to RoR then you should look at scaffolding to get you up  
and  
going with your database quickly.

Look at this [http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator](http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator)

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [January 9, 2008, 11:34am UTC](https://www.ruby-forum.com/t/how-to-write-test-case-for-database-search/125325/3 "2008-01-09T11:34:47Z")

</div>

hi Matt

Thanks for the tips. bt the case is i need to write the test case for  
the functionality in my controller. this controller is written only to  
do DB search only. so i need to write a test case codes for it.

def test\_public\_search\_with\_data  
get :public\_search, {}, {:query =\> “help”}  
assert\_response 200  
end

some what like this . bt the case is this is not working propely. so i  
want to know whether the my approach is correct or is their is another  
way for this.

Thanks  
Nadeesha

Matt Moloney wrote:

> If you have built an application using scaffold then you can easily  
> modify  
> database search criteria. Just modify the first line in the controller  
> script
> 
> > @myController = myController.find :all
> 
> to something like
> 
> > @mController = myController.find :all, :name =\> “Controller Name”
> 
> This is Ruby for SELECT \* FROM my\_controllers WHERE name=‘Controller  
> Name’
> 
> > 
> 
> If you are new to RoR then you should look at scaffolding to get you up  
> and  
> going with your database quickly.
> 
> Look at this [http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator](http://wiki.rubyonrails.org/rails/pages/ScaffoldGenerator)
