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?
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.
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 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.
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, 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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.