# Testing RESTful actions (put/post)

**URL:** <https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347>\
**Category:** Rails\
**Created:** [April 12, 2009, 9:42pm UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347 "2009-04-12T21:42:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 12, 2009, 9:42pm UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/1 "2009-04-12T21:42:57Z")

</div>

I am trying to test my update method:  
put :update, {:id =\> topics(:one).id, :topics =\> {:title =\> ‘Updated  
Unique Title’}}, {:user =\> users(:admin).id, :user\_role =\>  
users(:admin).role.name}

The above statement works fine and test returns positive result. I  
thought doing post for an update should fail:  
post :update, {:id =\> topics(:one).id, :topics =\> {:title =\> ‘Updated  
Unique Title’}}, {:user =\> users(:admin).id, :user\_role =\>  
users(:admin).role.name}

However, this also works. So even after doing RESTful routing post for  
update and destroy will work or what?

Thanks,  
CS.

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 13, 2009, 12:20am UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/2 "2009-04-13T00:20:54Z")

</div>

REST is a suggested architecture style. Rails does not enforce it.

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 14, 2009, 12:13am UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/3 "2009-04-14T00:13:39Z")

</div>

I’m pretty sure that the functional test helpers don’t run through the  
router - that’s why you can do ‘post :update’, rather than ‘post “/  
some/path/to/update”’ like you would in an integration test.

–Matt J.

On Apr 12, 3:42 pm, Carlos S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 14, 2009, 1:32am UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/4 "2009-04-14T01:32:51Z")

</div>

Something is wrong - may be my understanding of REST.  
Following is the output using curl.  
$ curl -X POST [http://localhost:3000/topics/update/1](http://localhost:3000/topics/update/1)

You are being [redirected](http://localhost:3000/topics/1).

Mongrel:  
Processing TopicsController#update (for 127.0.0.1 at 2009-04-13  
18:26:01) [POST]  
Session ID: 9dc3bd98a336027e75b2b4836967b497  
Parameters: {“action”=\>“update”, “id”=\>“1”, “controller”=\>“topics”}  
Anonymous Columns (0.001320) SHOW FIELDS FROM `users`  
Topic Columns (0.001158) SHOW FIELDS FROM `topics`  
Topic Load (0.000609) SELECT \* FROM `topics` WHERE (`topics`.`id` =  
1)  
CACHE (0.000000) SELECT \* FROM `topics` WHERE (`topics`.`id` = 1)  
SQL (0.000169) BEGIN  
SQL (0.000435) SELECT `title` FROM `topics` WHERE (`topics`.title =  
‘test’ AND `topics`.id \<\> 1)  
SQL (0.000157) COMMIT  
Redirected to [http://localhost:3000/topics/1](http://localhost:3000/topics/1)  
Completed in 0.04002 (24 reqs/sec) | DB: 0.00423 (10%) | 302 Found  
[[http://localhost/topics/update/1](http://localhost/topics/update/1)]

Following is my routes file.  
map.resources :topics do |topics|  
topics.resources :items do |items|  
items.resources :attachments, :member =\> {:view\_pdf =\> :get}  
end  
end

Is this okay/expected behavior?  
Or am I missing something?

Thanks,  
CS.  
Matt J. wrote:

> I’m pretty sure that the functional test helpers don’t run through the  
> router - that’s why you can do ‘post :update’, rather than ‘post “/  
> some/path/to/update”’ like you would in an integration test.
> 
> –Matt J.

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 14, 2009, 5:11am UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/5 "2009-04-14T05:11:27Z")

</div>

I think RESTful urls like edit\_topic\_url(id) work using REST. So routing  
is coming into the picture.

Matt J. wrote:

> I’m pretty sure that the functional test helpers don’t run through the  
> router - that’s why you can do ‘post :update’, rather than ‘post “/  
> some/path/to/update”’ like you would in an integration test.
> 
> –Matt J.
> 
> On Apr 12, 3:42ï¿½pm, Carlos S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![neubyr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c37758/32.png) [@neubyr](https://www.ruby-forum.com/u/neubyr)\
**Post date:** [April 14, 2009, 6:00am UTC](https://www.ruby-forum.com/t/testing-restful-actions-put-post/165347/6 "2009-04-14T06:00:41Z")

</div>

Matt, I think you are right. Functional test helpers aren’t referring to  
routing. ☹

Any more thoughts on this?

- 

CS.

Carlos S. wrote:

> I think RESTful urls like edit\_topic\_url(id) work using REST. So routing  
> is coming into the picture.
> 
> Matt J. wrote:
> 
> > I’m pretty sure that the functional test helpers don’t run through the  
> > router - that’s why you can do ‘post :update’, rather than ‘post “/  
> > some/path/to/update”’ like you would in an integration test.
> > 
> > –Matt J.
