Forum: Ruby on Rails Testing RESTful actions (put/post)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-12 21:42
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.
3afd4d1f4094ece39bbc11e9d38b8b9a?d=identicon&s=25 Shaum Sona (shamarock)
on 2009-04-13 00:20
REST is a suggested architecture style. Rails does not enforce it.
6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2009-04-14 00:13
(Received via mailing list)
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 Jones

On Apr 12, 3:42 pm, Carlos Santana <rails-mailing-l...@andreas-s.net>
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-14 01:32
Something is wrong - may be my understanding of REST.
Following is the output using curl.
$ curl -X POST http://localhost:3000/topics/update/1

<html><body>You are being <a
href="http://localhost:3000/topics/1">redirected</a>.</b...

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
Completed in 0.04002 (24 reqs/sec) | DB: 0.00423 (10%) | 302 Found
[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 Jones 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 Jones
>
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-14 05:11
I think RESTful urls like edit_topic_url(id) work using REST. So routing
is coming into the picture.

Matt Jones 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 Jones
>
> On Apr 12, 3:42�pm, Carlos Santana <rails-mailing-l...@andreas-s.net>
6c3acc025a63460a367b7981e606e032?d=identicon&s=25 Neubyr Neubyr (neubyr)
on 2009-04-14 06:00
Matt, I think you are right. Functional test helpers aren't referring to
routing. :(

Any more thoughts on this?

-
CS.

Carlos Santana wrote:
> I think RESTful urls like edit_topic_url(id) work using REST. So routing
> is coming into the picture.
>
> Matt Jones 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 Jones
>>
This topic is locked and can not be replied to.