# Test params

**URL:** <https://www.ruby-forum.com/t/test-params/181727>\
**Category:** Rails\
**Created:** [January 17, 2010, 3:46am UTC](https://www.ruby-forum.com/t/test-params/181727 "2010-01-17T03:46:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Learn\_by\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Learn\_by\_D](https://www.ruby-forum.com/u/Learn_by_D)\
**Post date:** [January 17, 2010, 3:46am UTC](https://www.ruby-forum.com/t/test-params/181727/1 "2010-01-17T03:46:59Z")

</div>

Hi,

In my RESTful implementation, :new shows a form for @link . When a  
user clicks on Create, the value of @link is posted to :create through  
params. How do I test the value of params and that :create actually  
uses these value to create a new link.

Right now I test :create by by using a link fixture but I want to  
actually use the value of params passed in through :new. I suspect  
that an integration test is needed but how can I do this?

Thanks.

Vincent.

---

<div class="post-metadata">

**Author:** ![Learn\_by\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Learn\_by\_D](https://www.ruby-forum.com/u/Learn_by_D)\
**Post date:** [January 17, 2010, 4:50am UTC](https://www.ruby-forum.com/t/test-params/181727/2 "2010-01-17T04:50:47Z")

</div>

What’s your test suite of choice? Using plain old TestUnit, try  
something like this:

def test\_link\_creates\_correctly  
post :create, :link =\> {:name =\> ‘Contact Us’, :href =\> ‘/  
contact’, :title =\> ‘Contact Us’}  
assert Link.find(:first, :conditions =\> {:name =\> ‘Contact  
Us’, :href =\> ‘/contact’, :title =\> ‘Contact Us’})  
end

This will test that the record was created as you wish. Honestly  
though, I don’t test for this, and I’m more paranoid than most. If  
you’re passing params[:link] to your Link.new method in the create  
action, that’s good enough. Since I stub out most database  
interaction with Mocha, I actually just test that Link.new was  
_called_ with the right parameters.

If you want to go nuts on controller tests, I have a pretty detailed  
article about it with more to come:

> **[KconRails.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=kconrails.com)**
>
> This domain name is available, own it today. Affordable payment options. Fast and professional service.

And if you have any questions, contact me through my blog or twitter  
(@kconrails) and I’ll be glad to help!

Jaime

---

<div class="post-metadata">

**Author:** ![Learn\_by\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Learn\_by\_D](https://www.ruby-forum.com/u/Learn_by_D)\
**Post date:** [January 17, 2010, 5:03am UTC](https://www.ruby-forum.com/t/test-params/181727/3 "2010-01-17T05:03:28Z")

</div>

Learn by Doing wrote:

> Hi,
> 
> In my RESTful implementation, :new shows a form for @link . When a  
> user clicks on Create, the value of @link is posted to :create through  
> params. How do I test the value of params and that :create actually  
> uses these value to create a new link.
> 
> Right now I test :create by by using a link fixture but I want to  
> actually use the value of params passed in through :new. I suspect  
> that an integration test is needed but how can I do this?

Use Cucumber. It makes this kind of thing pretty easy.

> Thanks.
> 
> Vincent.

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Learn\_by\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/e274bd/32.png) [@Learn\_by\_D](https://www.ruby-forum.com/u/Learn_by_D)\
**Post date:** [January 20, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/test-params/181727/4 "2010-01-20T20:30:15Z")

</div>

Thanks all. Cucumber sounds very promising. I will pick up a book on  
BDD.
