aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/test_case.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | disable controller / view thread spawning in testsAaron Patterson2016-02-051-0/+10
|/ | | | | | | | | | | | | | | | | | Tests can (and do) access the database from the main thread. In this case they were starting a transaction, then making a request. The request would create a new thread, which would allocate a new database connection. Since the main thread started a transaction that contains data that the new thread wants to see, the new thread would not see it due to data visibility from transactions. Spawning the new thread in production is fine because middleware should not be doing database manipulation similar to the test harness. Before 603fe20c it was possible to set the database connection id based on a thread local, but 603fe20c changes the connection lookup code to never look at the "connection id" but only at the thread object itself. Without that indirection, we can't force threads to use the same connection pool as another thread. Fixes #23483
* remove `present?` callsAaron Patterson2016-01-121-4/+4
| | | | | Empty strings / data structures should be treated differently than nils. We don't really need these calls here (don't pass in blank strings).
* monkey patch `recycle!` on to controllers onceAaron Patterson2016-01-121-4/+4
| | | | | | | | | | | Instead of checking whether the class has recycle! or not, we can just always add the method to all controller classes when the test harness is loaded. Technically this means that the controller test harness will not work with controllers that do not inherit from AC::Metal, but then, I'm not sure that is supported anyway. Mixing in the module one will ensure that we don't break method caches, and eliminates a runtime check so it should speed up tests (slightly).
* Remove ActionController::TestCase from documentationeileencodes2015-12-121-0/+4
| | | | | | | | | | | | | | | | | | In Rails 5.1 `ActionController::TestCase` will be moved out of Rails into it's own gem. Please use `ActionDispatch::IntegrationTest` going foward. Because this will be moved to a gem I used `# :stopdoc:` instead of deleting the documentation. This will remove it from the Rails documentation but still leave the method documented for when we move it to a gem. Guides have been updated to use the routing structure used in Integration and all test examples have been updated to inherit from `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase. Fixes #22496
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-10-311-2/+2
|\
| * Improved readability of Assertion docs, replaced ‘Assert’ -> ↵amitkumarsuroliya2015-10-091-2/+2
| | | | | | | | | | ‘Asserts’ at all places [ci skip] Following commit https://github.com/rails/docrails/commit/495722a95687e25114ae75608dd3107ac5d6611b
* | use `dispatch` instead of `process` to run requests thougheileencodes2015-10-291-4/+3
| | | | | | | | | | | | | | | | | | `dispatch` sets the request and response on the controller for us automatically, so the test harness doesn't need to know the internals of how request / response is set. Conflicts: actionpack/lib/action_controller/test_case.rb
* | Write the cookie jar it was not committed in TestCaseRafael Mendonça França2015-10-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For ActionController::Base we write the cookies in a middleware if it was not yet committed no matter if the response was committed or not. [1] For ActionController::Live we write the cookies before the response is committed. [2] We already mimic ActionController::Live in ActionController::TestCase but we don't mimic the ActionController::Base behavior because we were checking if the response was committed before writing the cookies. Now we are matching the behavior of the middleware and writing the cookies if it was not written before. [1]: https://github.com/rails/rails/blob/80c6b901d4d87cee610ab0a438ff6e3c6bf118d1/actionpack/lib/action_dispatch/middleware/cookies.rb#L599-L604 [2]: https://github.com/rails/rails/blob/80c6b901d4d87cee610ab0a438ff6e3c6bf118d1/actionpack/lib/action_controller/metal/live.rb#L218-L223
* | Use `Mime[:foo]` instead of `Mime::Type[:FOO]` for back compatJeremy Daer2015-10-061-3/+3
|/ | | | | | | | | | | | | | | | | Rails 4.x and earlier didn't support `Mime::Type[:FOO]`, so libraries that support multiple Rails versions would've had to feature-detect whether to use `Mime::Type[:FOO]` or `Mime::FOO`. `Mime[:foo]` has been around for ages to look up registered MIME types by symbol / extension, though, so libraries and plugins can safely switch to that without breaking backward- or forward-compatibility. Note: `Mime::ALL` isn't a real MIME type and isn't registered for lookup by type or extension, so it's not available as `Mime[:all]`. We use it internally as a wildcard for `respond_to` negotiation. If you use this internal constant, continue to reference it with `Mime::ALL`. Ref. efc6dd550ee49e7e443f9d72785caa0f240def53
* stop applying default headers in ActionDispatch::ResponseAaron Patterson2015-09-231-1/+1
| | | | | | | | | | I'm making this change so that I can construct response objects that *don't* have the default headers applied. For example, I would like to construct a response object from the return value of a controller. If you need to construct a response object with the default headers, then please use the alternate constructor: `ActionDispatch::Response.create`
* stop calling deprecated methodsAaron Patterson2015-09-211-3/+3
| | | | | We should be asking the mime type method for the mime objects rather than via const lookup
* remove outdated commentAaron Patterson2015-09-181-4/+0
| | | | | all parameter parsing is done on the request object now, so we don't need to worry about at ParamParser middleware
* all parameter parsing is done through the request object now.Aaron Patterson2015-09-181-1/+1
|
* let the request object handle parsing XML postsAaron Patterson2015-09-181-2/+9
| | | | | The test request object will handle parsing XML posts now, so we don't need to eagerly parse them in the test harness
* remove setting request parameters for JSON requestsAaron Patterson2015-09-181-2/+0
| | | | | The request object will automatically parse these in the `parse_formatted_parameters` method, so we don't have to worry about it.
* Handle Content-Types that are not :json, :xml, or :url_encoded_formeileencodes2015-09-091-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In c546a2b this was changed to mimic how the browser behaves in a real situation but left out types that were registered. When this was changed it didn't take `text/plain` or `text/html` content types into account. This is a problem if you're manipulating the `Content-Type` headers in your controller tests, and expect a certain result. The reason I changed this to use `to_sym` is because if the `Content-Type` is not registered then the symbol will not exist. If it's one of the special types we handle that specifically (:json, :xml, or :url_encoded_form). If it's any registered type we handle it by setting the `path_parameters` and then the `request_parameters`. If the `to_sym` returns nil an error will be thrown. If the controller test sets a `Content-Type` on the request that `Content-Type` should remain in the header and pass along the filename. For example: If a test sets a content type on a post ``` @request.headers['CONTENT_TYPE'] = 'text/plain' post :create, params: { name: 'foo.txt' } ``` Then `foo.txt` should be in the `request_parameters` and params related to the path should be in the `path_parameters` and the `Content-Type` header should match the one set in the `@request`. When c546a2b was committed `text/plain` and `text/html` types were throwing a "Unknown Content-Type" error which is misleading and incorrect. Note: this does not affect how this is handled in the browser, just how the controller tests handle setting `Content-Type`.
* stop using deprecated Abstract::ID classAaron Patterson2015-09-041-1/+1
|
* stop inheriting from Rack::RequestAaron Patterson2015-09-041-4/+4
| | | | | | Just include the modules necessary in the Request object to implement the things we need. This should make it easier to build delegate request objects because the API is smaller
* Fix bug where cookies mutated by request were not persistedeileencodes2015-09-011-0/+1
| | | | | | | | | | | | | | | With changes made in 8363b8 and ae29142 cookies that are mutated on the request like `cookies.signed = x` were not retained in subsequent tests, breaking cookie authentiation in controller tests. The test added demonstrates the issue. The reason we need to select from non-deleted cookies is because without checking the `@delete_cookies` the `cookie_jar` `@cookies` will send the wrong cookies to be updated. The code must check for `@deleted_cookies` before sending an `#update` with the requests cookie_jar cookies. This follows how the cookie_jar cookies from the request were updated before these changes.
* Updating TestSession to access with indifferenceJeremy Friesen2015-08-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following Rails code failed (with a `KeyError` exception) under test: ```ruby class ApplicationController < ActionController::Base def user_strategy # At this point: # ```ruby # session == { # "user_strategy"=>"email", # "user_identifying_value"=>"hello@world.com" # } # ``` if session.key?(:user_strategy) session.fetch(:user_strategy) end end end ``` When I checked the session's keys (`session.keys`), I got an array of strings. If I accessed `session[:user_strategy]` I got the expected `'email'` value. However if I used `session.fetch(:user_strategy)` I got a `KeyError` exception. This appears to be a Rails 4.2.4 regression (as the code works under Rails 4.2.3). Closes #21383
* remove more direct `env` mutationsAaron Patterson2015-08-241-1/+3
|
* rm useless methodAaron Patterson2015-08-241-4/+0
| | | | superclass already has this method, so remove this one
* remove more `env` accessAaron Patterson2015-08-231-11/+19
|
* remove more env accessAaron Patterson2015-08-231-3/+3
|
* remove more env accessAaron Patterson2015-08-231-4/+6
|
* convert more `@env` access to get / set headerAaron Patterson2015-08-231-1/+1
|
* Fix master buildMarcin Olichwirowicz2015-08-171-0/+1
|
* Refactor how assign_parameters sets generated_path & query_string_keyseileencodes2015-08-151-8/+20
| | | | | | | | | | | | | This is part of a larger refactoring on controller tests. We needed to move these methods here so that we could get rid of the `|| key == :action || key == :controller` in `assign_parameters`. We know this is ugly and intend to fix it but for now `generate_extras` needs to be used in the two methods to access the path and the query_string_keys. We're adding `:controller` and `:action` to the `query_string_keys` because we always need a controller and action. If someone passed `action` or `controller` in in there test they are unambigious - we know they have to go into the query params.
* Rename `extra_keys` variables to `query_string_keys`eileencodes2015-08-081-2/+2
| | | | | | `extra_keys` is a confusing variable name because it's not clear what is "extra". This renames it to `query_string_keys` so it's clear that the "extra" is just the query string.
* Adds missing argument handling for ActionController::TestSession toMatthew Gerrior2015-08-061-0/+4
| | | | allow testing controllers that use session#fetch with a default value.
* Rack implements `redirect?` so we don't need itAaron Patterson2015-07-141-3/+0
| | | | Rack [already implements `redirect?` on the response object](https://github.com/rack/rack/blob/1569a985e17d9caaf94d0e97d95ef642c4ab14ba/lib/rack/response.rb#L141) so we don't need to implement our own.
* Change AC::TestResponse to AD::TestResponsePrem Sichanugrist2015-07-141-1/+1
| | | | | ActionController::TestResponse was removed in d9fe10c and caused a test failure on Action View as its test case still refers to it.
* only have one TestResponse classAaron Patterson2015-07-131-4/+1
|
* move buffer caching on to the bufferAaron Patterson2015-07-131-4/+0
|
* we don't really need an extra method to set the script nameAaron Patterson2015-07-101-5/+1
|
* Remove useless conditionalAaron Patterson2015-07-101-12/+0
| | | | PATH_INFO is already set, so this branch will never execute.
* default `PATH_INFO` to the generated pathAaron Patterson2015-07-101-1/+2
| | | | | | we were already generating a path in the previous code (it was just not returned), so lets just use the already computed path to popluate the PATH_INFO header
* always default the SCRIPT_NAME to whatever is on the controllerAaron Patterson2015-07-101-1/+1
|
* remove useless ivar clearingAaron Patterson2015-07-101-6/+0
| | | | Since we only work with new instances, these ivars will not be set.
* call the `path_parameters=` setter rather than rely on mutationsAaron Patterson2015-07-101-1/+3
| | | | | We should call the setter on `path_parameters` so that we know the hash will only contain the values that we've set.
* start collecting `env` mutationsAaron Patterson2015-07-101-5/+3
| | | | | I'd like to put all env mutations together so we can understand how to change this code to call `call` on the controller
* Parameters are converted to a query stringAaron Patterson2015-07-101-17/+0
| | | | | Since parameters are converted to a query string, they will automatically be turned in to strings by the query parser
* no more HWIAAaron Patterson2015-07-101-1/+1
| | | | | non_path_parameters is used internally (it never escapes this method) so we should be able to safely use a regular hash.
* remove param dup'ing logicAaron Patterson2015-07-101-8/+0
| | | | | since we are serializing parameters, we don't need to do all the dup checks on each object.
* encode / decode parameters before assigning them to the requestAaron Patterson2015-07-101-5/+58
| | | | | | We should roundtrip the parameters through their respective encoders / decoders so that the controller will get parameters similar to what they actually get in a real world situation
* set parameters as a query stringAaron Patterson2015-07-091-6/+9
| | | | | | We should convert request parameters to a query string, then let the request object parse that query string. This should give us results that are more similar to the real-world
* build and assign parameters rather than rely on mutationsAaron Patterson2015-07-081-1/+15
| | | | | We should assign parameters to the request object rather than mutate the hash that is returned by `query_parameters` or `request_parameters`
* assign the cookie hash on request allocationAaron Patterson2015-07-081-1/+1
| | | | this prevents mutations from being available globally
* request objects are no longer recycledAaron Patterson2015-07-081-10/+8
| | | | | | Instead of trying to manually clear out a request object, lets just allocate a new one. The rack ENV is reused and cleaned (still), but the request object is not.
* add a new constructor for allocating test requestsAaron Patterson2015-07-081-11/+13
|