# UnitTest Problem

**URL:** <https://www.ruby-forum.com/t/unittest-problem/72586>\
**Category:** Rails\
**Created:** [October 18, 2006, 10:31am UTC](https://www.ruby-forum.com/t/unittest-problem/72586 "2006-10-18T10:31:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 18, 2006, 10:31am UTC](https://www.ruby-forum.com/t/unittest-problem/72586/1 "2006-10-18T10:31:03Z")

</div>

I enter three integers with the aid of a form into the database (I  
believe it is :post). In the controller, I make some calculations with  
the numbers and save this in the database. The method in the controller  
is called “create\_index”

How can I test the calculation ? Is that a unit or functional test ?  
Because I would like to test the calcualtion, if the results are  
correctly saved in the database.

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 18, 2006, 1:37pm UTC](https://www.ruby-forum.com/t/unittest-problem/72586/2 "2006-10-18T13:37:45Z")

</div>

M. R. wrote:

> I enter three integers with the aid of a form into the database (I  
> believe it is :post). In the controller, I make some calculations with  
> the numbers and save this in the database. The method in the controller  
> is called “create\_index”
> 
> How can I test the calculation ? Is that a unit or functional test ?  
> Because I would like to test the calcualtion, if the results are  
> correctly saved in the database.

Can anyone help me ???

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 18, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/unittest-problem/72586/3 "2006-10-18T16:42:52Z")

</div>

I believe the rule is: if you’re testing a method of a model, use a unit  
test; if you’re testing a method of a controller, use a functional test.

M. R. wrote:

> 

–  
Lance I.  
Web Applications Developer  
RBS Interactive  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 18, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/unittest-problem/72586/4 "2006-10-18T19:05:54Z")

</div>

On 10/18/06, M. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I enter three integers with the aid of a form into the database (I  
> believe it is :post). In the controller, I make some calculations with  
> the numbers and save this in the database. The method in the controller  
> is called “create\_index”
> 
> How can I test the calculation ? Is that a unit or functional test ?  
> Because I would like to test the calcualtion, if the results are  
> correctly saved in the database.

I’m guessing that the calculation should be performed by the AR model,  
rather than in the controller directly. If you did this then it’d be  
very easy to unit test the model in isolation.

If you knew that the model was calculating correctly then you could  
use a mock object in your functional controller test to make sure that  
the calculate method is being called.

Chris
