This project is archived and is in readonly mode.
Functional tests don't care about http-verb that you use on the simulate request.
-
Andrew White
- State changed from new to invalid
- Importance changed from to Low
Functional tests call the controller action directly and don't go through the router. Use an ActionDispatch::IntegrationTest to check the routing constraints. e.g:
rails generate test_unit:integration my_controller_routing -
Fernando Guillen
But then what is the propose of having the five verbs in the
ActionController::TestCaseif I can use any of them without any restriction or diference?It is not intuitive.
And besides the
ActionController::TestCase, some way, looks to the defined routes because if don't have the route defined on yourroutes.rbit raises anActionController::RoutingError. -
Andrew White
The get, post, etc. methods are just wrappers around the process method of ActionController::TestCase. All they do is set the REQUEST_METHOD header in the Rack environment so that any code in your controller that is dependent on the request method acts appropriately, e.g.
# routes.rb match '/basket', :to => 'shop#basket', :via => [:get, :post] # app/controllers/shop_controller.rb class ShopController < ApplicationController before_filter :load_basket def basket @basket.update(params[:basket]) if request.post? end protected def load_basket @basket = Basket.new(session[:basket]) end endThe routing error you get is because the process method builds a request uri so it's a generation error and not a recognition error (generation of urls ignores HTTP verbs as well).
Functional tests are meant to be isolated tests of your controller - if you need to test the full stack use an integration test.
-
Fernando Guillen
Ok, I understand pretty much better all this behavior.
So the verbs in the
ActionController::TestCaseare just to mark this request with this REQUEST_METHOD header in order to be used (or not) in ourController.And also I have realized that we are also checking that the url we are calling can be built based on our routes definition, but without taken care about the verbs restrictions. So it should be able to be generated but it doesn't need to be recognized.
(This last point sounds a few inconsistent for me, but I understand I don't have the whole picture in my mind)
Thanks for your explanation.
-
Andrew White
That's pretty much it except the route is being built so that the REQUEST_URI header can be set and not to check whether the route can be generated (though it obviously it needs to be).