# Integration testing edit actions (PUT method)

**URL:** <https://www.ruby-forum.com/t/integration-testing-edit-actions-put-method/167816>\
**Category:** Rails\
**Created:** [May 12, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/integration-testing-edit-actions-put-method/167816 "2009-05-12T22:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [May 12, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/integration-testing-edit-actions-put-method/167816/1 "2009-05-12T22:30:42Z")

</div>

Hi.

I am (integration) testing a standard edit action. I realise that the  
http request is not actually a PUT request, but rather a POST request  
with a hidden field in the form named “\_method”, which has the value  
“put”.

This means that a browser will generate a POST request, so an  
integration test using put or put\_via\_redirect will actually not  
simulate a real browsers behaviour.

What does people do here? ignore the fact that the integration test  
generate HTTP request which differs from what a broswer will do, or do  
you use post (or post\_via\_redirect) and adding the “\_method” parameter  
manually.

Jarl

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [May 12, 2009, 10:47pm UTC](https://www.ruby-forum.com/t/integration-testing-edit-actions-put-method/167816/2 "2009-05-12T22:47:49Z")

</div>

> What does people do here? ignore the fact that the integration test  
> generate HTTP request which differs from what a broswer will do, or do  
> you use post (or post\_via\_redirect) and adding the “\_method” parameter  
> manually.

I think you’re just splitting hairs at that point. If the put request in  
your integration test doesn’t get routed to the correct action, the test  
will fail anyway.

SH

–  
Starr H.  
Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)

---

<div class="post-metadata">

**Author:** ![jarl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/6bbea6/32.png) [@jarl](https://www.ruby-forum.com/u/jarl)\
**Post date:** [May 13, 2009, 9:27am UTC](https://www.ruby-forum.com/t/integration-testing-edit-actions-put-method/167816/3 "2009-05-13T09:27:00Z")

</div>

Starr H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > What does people do here? ignore the fact that the integration test  
> > generate HTTP request which differs from what a broswer will do, or do  
> > you use post (or post\_via\_redirect) and adding the “\_method” parameter  
> > manually.
> 
> I think you’re just splitting hairs at that point. If the put request in your integration test doesn’t get routed to the correct action, the test will fail anyway.

Hi Starr.

Thanks for taking your time to answer my post.

I think you misunderstand. My put request in my integration test do  
get routed to the correct action. My point is a standard browser will  
not generate HTTP PUT request upon edits, so my integration test does  
not reflect standard usage of my web-app.

rake routes show:  
edit\_order GET /orders/:id/edit(.:format)  
{:controller=\>“orders”, :action=\>“edit”}  
PUT /orders/:id(.:format)  
{:controller=\>“orders”, :action=\>“update”}

However the default (which I use) view (app/views/order/edit.html.erb  
contains

\<% form\_for(@order) do |f| %\>

And one should expect this to generate HTML that upon commit makes a  
HTTP PUT request to the update action.

However the above form\_for(@order) call generates the following HTML  
form:

So even though I tell rails that I want the update action to use the  
HTTP PUT request, the generated HTML in the edit.html.erb is form  
generating a HTTP POST request with an additional hidden input named  
“\_method” with the value “put”

That means, that when people are using the app from a standard  
browser the browser will send a HTTP POST request.

First of all I wonder why rails (the form\_for method) does not  
generate a form that will send a HTTP PUT request. I think (but this  
is only a wild guess) this is because it is work-in-progress

Secondly, now the situation is like that, what does people do (in  
their integration test) to accommodate for the situation.

Basically I don’t have a problem with my application. I just see that  
my integration tests does not generate the HTTP requests that a real  
browser would have done.

Jarl
