aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/test_case.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #26092 from kerrizor/kerrizor/force-param-encodingAaron Patterson2016-08-101-5/+8
|\ | | | | Allow specifying encoding of parameters by action
| * Allow specifying encoding of parameters by actionKerri Miller2016-08-091-5/+8
| | | | | | | | | | At GitHub we need to handle parameter encodings that are not UTF-8. This patch allows us to specify encodings per parameter per action.
* | Remove unused methodAndrew White2016-08-101-5/+0
|/ | | | | | | In c546a2b parameter handling in AC test cases was changed to round tripping through encoders/decoders so that they matched reality and in 0adb8f8 the old methods were removed but the `html_format?` method was overlooked.
* code gardening: removes redundant selfsXavier Noria2016-08-081-4/+4
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-44/+44
|
* applies new string literal convention in actionpack/libXavier Noria2016-08-061-36/+36
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Reset rack.input when the environment is scrubbed for the next requestNick Sieger2016-07-271-0/+1
| | | | | | | | | | | | | | | | | Before this change, posted parameters would leak across requests. The included test case failed like so: 1) Failure: TestCaseTest#test_multiple_mixed_method_process_should_scrub_rack_input: --- expected +++ actual @@ -1 +1 @@ -{"bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"} +{"foo"=>"an foo", "bar"=>"an bar", "controller"=>"test_case_test/test", "action"=>"test_params"} An argument could be made that this situation isn't encountered often and that one should limit the number of requests per test case, but I still think the parameter leaking is an unexpected side-effect.
* Clean up the test request/response even after an exceptionMatthew Draper2016-06-011-23/+26
|
* Fixes #23964Ryan T. Hosford2016-03-131-0/+2
| | | | | | | | | | | | | | | | | | - Adds #each_chunk to ActionDispatch::Response. it's a method which will be called by ActionDispatch::Response#each. - Make Response#each a proper method instead of delegating to @stream - In Live, instead of overriding #each, override #each_chunk. - `#each` should just spit out @str_body if it's already set - Adds #test_set_header_after_read_body_during_action to prove this fixes #23964 - Adds #test_each_isnt_called_if_str_body_is_written to ensure #each_chunk is not called when @str_body is available - Call `@response.sent!` in AC::TestCase's #perform so a test response acts a bit more like a real response. Makes test that call `#assert_stream_closed` pass again. - Additionally assert `#committed?` in `#assert_stream_closed` - Make test that was calling @response.stream.each pass again by calling @response.each instead.
* Change 'a HTTP' to 'an HTTP' [ci skip]Santosh Wadghule2016-03-031-1/+1
|
* Revert "Update Session to utilize indiffernt access"Matthew Draper2016-02-261-1/+1
| | | | | | | | | | | This reverts commit 45a75a3fcc96b22954caf69be2df4e302b134d7a. HWIAs are better than silently deeply-stringified hashes... but that's a reaction to a shortcoming of one particular session store: we should not break the basic behaviour of other, more featureful, session stores in the process. Fixes #23884
* Merge pull request #20851 from tomprats/indifferent-sessionsRafael Mendonça França2016-02-241-1/+1
|\ | | | | | | Give Sessions Indifferent Access
| * Update Session to utilize indiffernt accessTom Prats2016-01-301-1/+1
| |
* | Use symbol of mime type instead of object to get correct parserMehmet Emin İNAÇ2016-02-221-2/+2
| | | | | | | | | | | | After registering new `:json` mime type `parsers.fetch` can't find the mime type because new mime type is not equal to old one. Using symbol of the mime type as key on parsers hash solves the problem. Closes #23766
* | fix 'method redefined' warningsScott Bronson2016-02-061-0/+1
| |
* | 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
|