aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/test_case.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use match? where we don't need MatchDataAkira Matsuda2019-07-291-2/+2
|
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-3/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Update the promisse that ActionController::TestCase will be extractedRafael Mendonça França2019-01-171-1/+1
| | | | | | | | We are past 5.1 and it was not extrated yet, so while we still have plans they will not be realized on 6.0, so it is better to not set expectations of which release will exclude it just yet. [ci skip]
* Remove mention about `Test::Unit::TestCase` [ci skip]bogdanvlviv2019-01-021-3/+0
| | | | | | We've switched from `Test::Unit::TestCase` to `ActiveSupport::TestCase` since Rails 2.3. See https://edgeguides.rubyonrails.org/2_3_release_notes.html#other-railties-changes
* Allow nil params on controller HTTP test methodsr7kamura2018-12-181-2/+2
|
* e4e1b62 broke `to_param` handling:Edouard CHIN2018-07-121-1/+1
| | | | | | | | | | | | | | | | | | | - There was an issue inside controller tests where order params were not respected, the reason was because we were calling `Hash#to_query` which sorts the results lexicographically. 1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack. - However with the fix came another issue where it's now no longer possible to do this ``` post :foo, params: { user: User.first } # Prior to the patch the controller will receive { "user" => "1" } # Whereas now you get { "user": "#<User: ...>" } ``` The fix in this PR is to modify `Hash#to_query` to sort only when it doesn't contain an array structure that looks something like "bar[]" Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
* Use Rack to generate query information under testAaron Patterson2018-06-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | `to_query` sorts parameters before encoding them. This causes a round tripping issue as noted here: https://github.com/rails/rails/issues/23997#issuecomment-328297933 https://github.com/rails/rails/issues/10529#issuecomment-328298109 https://github.com/rails/rails/pull/30558 Unfortunately, that method is being used to generate cache keys, so its results need to be stable: https://github.com/rails/rails/commit/10dec0e65e1f4d87f411b4361045eba86b121be9 However, the test harness is only using `to_query` to encode parameters before sending them to the controller so the "cache key" usecase doesn't apply here. This commit adds a test that demonstrates the round trip problems and changes the serialization strategy to use Rack for encoding the parameters rather than `to_query`.
* Reset CONTENT_LENGTH between test requestsEugene Kenny2018-05-011-0/+1
| | | | | | | If a POST request is followed by a GET request in a controller test, the `rack.input` and `RAW_POST_DATA` headers from the first request will be reset but the `CONTENT_LENGTH` header will leak, leading the request object in the second request to incorrectly believe it has a body.
* Reset RAW_POST_DATA between test requestsEugene Kenny2018-04-201-4/+5
| | | | | | `RAW_POST_DATA` is derived from the `rack.input` header, which changes with each test request. It needs to be cleared in `scrub_env!`, or all requests within the same test will see the value from the first request.
* ActionController::TestCase: fix #post documentation [ci skip]Misty De Meo2018-01-291-1/+1
| | | | Fixes #31823.
* [Action Pack] require => require_relativeAkira Matsuda2017-10-211-1/+1
| | | | | This basically reverts e9fca7668b9eba82bcc832cb0061459703368397, d08da958b9ae17d4bbe4c9d7db497ece2450db5f, d1fe1dcf8ab1c0210a37c2a78c1ee52cf199a66d, and 68eaf7b4d5f2bb56d939f71c5ece2d61cf6680a3
* Clarify intentions around method redefinitionsMatthew Draper2017-09-011-1/+2
| | | | | | | | | Don't use remove_method or remove_possible_method just before a new definition: at best the purpose is unclear, and at worst it creates a race condition. Instead, prefer redefine_method when practical, and silence_redefinition_of_method otherwise.
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* [Action Controller] require => require_relativeAkira Matsuda2017-07-011-1/+1
|
* Revert "Merge pull request #27775 from domcleal/27774-format-reset"Rafael Mendonça França2017-03-211-1/+0
| | | | | | | | | | | | | | This reverts commit c6f9f8c28a720ad4ec7cf3613dddfa451d5968e2, reversing changes made to c309073c7476f50dfb1e796d058580f176101c36. Reason: This is fixing the behavior in the wrong place. Now the request path after the request is nil and there is no way to assert that. Also the test that was added in that PR also fails in 4.2 where the reporter says it was passing. The reason the bahavior changed between Rails 4.2 and Rails 5 is that the format in the path is now respected. The correct way to fix the problem is not doign two requests in the same controller test and use integrations tests. This change caused a regression between Rails 5.0.1 and 5.0.2.
* [docs] fix ActionController documentationHrvoje Šimić2017-03-121-5/+5
| | | | [ci skip]
* Delete PATH_INFO after each controller test requestDominic Cleal2017-01-231-0/+1
| | | | | | | | | | Prevents PATH_INFO from being used to infer the request format in later test requests when no explicit format is given. As the request PATH_INFO may be set before a request, it can't be deleted during pre-request scrubbing. Fixes #27774
* Revert "Merge pull request #27586 from maclover7/jm-fix-27584"Rafael Mendonça França2017-01-111-2/+3
| | | | | | | This reverts commit 5eff7a9ca7bb2ee7f16db1ab4d11cebe28757ba5, reversing changes made to 5f03172f54a58a57a48a3121562beb2cef866cbe. Reason: It caused a regression. The test case is on the PR.
* Update `cookies` helper on all HTTP requestsJon Moss2017-01-051-3/+2
| | | | | | | | | Regression introduced by ae29142142324545a328948e059e8b8118fd7a33 / 8363b879fe759f0645179f4521cc64795efbee6e. Previously, cookies were only updated on `GET` requests. Now we will update the helper for all requests, as part of `process`. Added regression tests for all available HTTP method helpers in `ActionController::TestCase`.
* `self.` is not needed when calling its own instance methodAkira Matsuda2017-01-051-1/+1
| | | | Actually, private methods cannot be called with `self.`, so it's not just redundant, it's a bad habit in Ruby
* Merge pull request #27146 from maclover7/jm-fix-27145Eileen M. Uchitelle2016-12-191-2/+0
|\ | | | | Do not clear HTTP_COOKIES header after request
| * Do not clear HTTP_COOKIES header after requestJon Moss2016-12-111-2/+0
| |
* | Missing require "active_support/testing/constant_lookup"Akira Matsuda2016-12-141-0/+1
|/
* Fixed CONTENT_LENGTH header in ActionController::TestRequestArtem Rashev2016-11-151-2/+3
| | | | | | | | | | | | | CONENT_LENGTH setted by string length, which is equal to number of characters in string but StringIO.length is byte sequence and when payload contains non-ASCII characters, stream's length will be different. That's why real byte length should be used for CONTENT_LENGTH header. Add unit test for CONTENT_LENGTH header fix It just passes non-ascii symbols as parameters and verifies that "CONTENT_LENGTH" header has content bytes count as value.
* Remove deprecated support to non-keyword arguments #processRafael Mendonça França2016-10-101-70/+16
|
* Remove deprecated `xml_http_request` and `xhr` methodsRafael Mendonça França2016-10-101-15/+0
|
* Merge pull request #26573 from kirs/action-controller-as-formatRafael França2016-09-271-4/+4
|\ | | | | Make :as option also set request format (AC::TestCase)
| * Make :as option also set request format (AC::TestCase)Kir Shatrov2016-09-211-4/+4
| | | | | | | | | | | | | | | | right now you'd have to specify both :as and :format: ``` post :create, params: { foo: "bar" } as: :json, format: :json ```
* | Do not mutate AC::TestRequest::DEFAULT_OPTIONSKir Shatrov2016-09-101-1/+1
|/
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-6/+6
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* Fix typo in the hook nameRafael Mendonça França2016-08-251-1/+1
|
* Add load hooks to all tests classesRafael Mendonça França2016-08-251-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Usually users extends tests classes doing something like: ActionView::TestCase.include MyCustomTestHelpers This is bad because it will load the ActionView::TestCase right aways and this will load ActionController::Base making its on_load hooks to execute early than it should. One way to fix this is using the on_load hooks of the components like: ActiveSupport.on_load(:action_view) do ActionView::TestCase.include MyCustomTestHelpers end The problem with this approach is that the test extension will be only load when ActionView::Base is loaded and this may happen too late in the test. To fix this we are adding hooks to people extend the test classes that will be loaded exactly when the test classes are needed.
* Copy edits in the documentation [ci skip]Rafael Mendonça França2016-08-191-1/+1
|
* Set the request type if as: is specifiedEverest Munro-Zeisberger2016-08-181-1/+8
| | | | Documentation & testing
* Merge pull request #25862 from ↵प्रथमेश Sonpatki2016-08-171-6/+12
|\ | | | | | | | | prathamesh-sonpatki/start-documenting-ac-testcase-again Start documenting ActionController::TestCase again
| * Start documenting ActionController::TestCase againPrathamesh Sonpatki2016-08-171-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | - Rails 5 changed interface for passing arguments to request methods to keyword args for AC::TestCase but also hid the documentation. - But existing AC::TestCase tests need the new documentation about keyword args. So resurrected documentation and added a note about not using this for new tests. - The guides and other documentation is already updated to use `ActionDispatch::IntegrationTest`. [Matthew Draper, Prathamesh Sonpatki]
* | 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
| |