aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
Commit message (Collapse)AuthorAgeFilesLines
* Use match? where we don't need MatchDataAkira Matsuda2019-07-292-2/+2
|
* Add `Vary: Accept` header when renderingst00122019-07-261-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem description (quoted from @rafaelfranca's excellent explanation in https://github.com/rails/jquery-ujs/issues/318#issuecomment-88129005): > Let say that we requested /tasks/1 using Ajax, and the previous page has the same url. When we click the back button the browser tries to get the response from its cache and it gets the javascript response. With vary we "fix" this behavior because we are telling the browser that the url is the same but it is not from the same type what will skip the cache. And there's a Rails issue discussing about this problem as well https://github.com/rails/rails/issues/25842 Also, according to [RFC 7231 7.1.4](https://tools.ietf.org/html/rfc7231#section-7.1.4) > An origin server SHOULD send a Vary header field when its algorithm > for selecting a representation varies based on aspects of the request > message other than the method and request target we should add `Vary: Accept` header when determining content based on the `Accept` header. Although adding such header by default could cause unnecessary cache invalidation. But this PR only adds the header if: - The format param is not provided - The request is a `xhr` request - The request has accept headers and the headers are valid So if the user - sends request with explicit format, like `/users/1.json` - or sends a normal request (non xhr) - or doesn't specify accept headers then the header won't be added. See the discussion in https://github.com/rails/rails/issues/25842 and https://github.com/rails/rails/pull/36213 for more details.
* Fix flaky test ActionControllerBaseRenderTest#test_direct_render_to_stringFumiaki MATSUSHIMA2019-07-261-4/+20
|
* Merge pull request #36412 from robotdana/compact_blankRafael Mendonça França2019-07-251-0/+18
|\ | | | | | | Add compact_blank shortcut for reject(&:blank?)
| * Add compact_blank shortcut for reject(&:blank?)Dana Sherson2019-06-051-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | I frequently find myself having to .compact but for blank. which means on an array reject(&:blank?) (this is fine), or, on a hash `.reject { |_k, v| v.blank? }` which is slightly more frustrating and i usually write it as .reject(&:blank?) first and am confused when it's trying to check if the keys are blank. I've added the analagous .compact_blank! where there's a reject! to build on (there's also a reject! in Set, but there's no other core_ext touching Set so i've left that alone)
* | fix `follow_redirect!` not using the same HTTP verb on 307 redirection:Edouard CHIN2019-07-251-0/+13
| | | | | | | | | | | | | | | | | | | | - According to the HTTP 1.1 spec, the 307 redirection guarantees that the method and the body will not be changed during redirection. This PR fixes that since follow_redirect! would always follow the redirection my making a GET request. Ref https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307
* | Add hash method to ActionController::ParametersEugene Baranov2019-07-141-0/+8
| |
* | try (Just a Little Bit Harder)Akira Matsuda2019-07-121-2/+1
| |
* | Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-1318-24/+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.
* | Bump rubocop to 0.71Abhay Nikam2019-06-061-2/+0
| |
* | Give HelperMethods module a nameJohn Hawthorn2019-06-031-2/+2
|/
* Remove unnecessary require pathname from actionpack controller specsAbhay Nikam2019-06-023-3/+0
|
* Change `ActionDispatch::Response#content_type` returning Content-Type header ↵yuuji.yaginuma2019-06-0110-76/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | as it is Since #35709, `Response#conten_type` returns only MIME type correctly. It is a documented behavior that this method only returns MIME type, so this change seems appropriate. https://github.com/rails/rails/blob/39de7fac0507070e3c5f8b33fbad6fced84d97ed/actionpack/lib/action_dispatch/http/response.rb#L245-L249 But unfortunately, some users expect this method to return all Content-Type that does not contain charset. This seems to be breaking changes. We can change this behavior with the deprecate cycle. But, in that case, a method needs that include Content-Type with additional parameters. And that method name is probably the `content_type` seems to properly. So I changed the new behavior to more appropriate `media_type` method. And `Response#content_type` changed (as the method name) to return Content-Type header as it is. Fixes #35709. [Rafael Mendonça França & Yuuji Yaginuma ]
* Implemented deep_transform_keys/! for ActionController::ParametersGustavo Gutierrez2019-05-222-0/+18
|
* Merge pull request #36302 from eugeneius/parameters_transform_keys_enumeratorRyuta Kamizono2019-05-201-2/+14
|\ | | | | | | Return parameters enumerator from transform_keys/!
| * Return parameters enumerator from transform_keys/!Eugene Kenny2019-05-181-2/+14
|/ | | | | | | | | | | | | | | | | Previously calling `ActionController::Parameters#transform_keys/!` without passing a block would return an enumerator for the underlying hash, which was inconsistent with the behaviour when a block was passed: ActionController::Parameters.new(foo: "bar").transform_keys { |k| k } => <ActionController::Parameters {"foo"=>"bar"} permitted: false> ActionController::Parameters.new(foo: "bar").transform_keys.each { |k| k } => {"foo"=>"bar"} An enumerator for the parameters is now returned instead, ensuring that evaluating it produces another parameters object instead of a hash: ActionController::Parameters.new(foo: "bar").transform_keys.each { |k| k } => <ActionController::Parameters {"foo"=>"bar"} permitted: false>
* fixed usage of Parameters when a non-numeric key existsL.Fexon2019-05-131-2/+28
| | | | | | | | | | test for non-numeric key in nested attributes test: extra blank line between tests removed test for non-numeric key fixed (by Daniel) Update according to feedback
* Only build middleware proxy when instrumentatingJohn Hawthorn2019-05-081-1/+1
| | | | | | | | | | | | | | | | | The instrumentation proxy adds three stack frames per-middleware, even when nothing is listening. This commit, when the middleware stack is built, only adds instrumentation when the `process_middleware.action_dispatch` event has already been subscribed to. The advantage to this is that we don't have any extra stack frames in apps which don't need middleware instrumentation. The disadvantage is that the subscriptions need to be in place when the middleware stack is built (during app boot). I think this is likely okay because temporary AS::Notifications subscriptions are strongly discouraged.
* Remove redundant test setups in log_subscriber_testst00122019-04-241-21/+1
| | | | | | | Because controllers' `perform_caching` config is `true` by default, it means we actually enable the caching in all those tests implicitly (and it works). Which also means we can avoid repeatedly declaring that and just specify it once in the setup method (just for declaration).
* Always reject files external to appJohn Hawthorn2019-04-032-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, when using `render file:`, it was possible to render files not only at an absolute path or relative to the current directory, but relative to ANY view paths. This was probably done for absolutely maximum compatibility when addressing CVE-2016-0752, but I think is unlikely to be used in practice. Tihs commit removes the ability to `render file:` with a path relative to a non-fallback view path. Make FallbackResolver.new private To ensure nobody is making FallbackResolvers other than "/" and "". Make reject_files_external_... no-op for fallbacks Because there are only two values used for path: "" and "/", and File.join("", "") == File.join("/", "") == "/", this method was only testing that the absolute paths started at "/" (which of course all do). This commit doesn't change any behaviour, but it makes it explicit that the FallbackFileSystemResolver works this way. Remove outside_app_allowed argument Deprecate find_all_anywhere This is now equivalent to find_all Remove outside_app argument Deprecate find_file for find Both LookupContext#find_file and PathSet#find_file are now equivalent to their respective #find methods.
* url -> URL where apt inside actionpack/Sharang Dashputre2019-04-014-7/+7
|
* Merge pull request #35688 from jhawthorn/render_file_rfcAaron Patterson2019-03-303-9/+21
|\ | | | | RFC: Introduce Template::File
| * Introduce Template::File as new render file:John Hawthorn2019-03-273-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous behaviour of render file: was essentially the same as render template:, except that templates can be specified as an absolute path on the filesystem. This makes sense for historic reasons, but now render file: is almost exclusively used to render raw files (not .erb) like public/404.html. In addition to complicating the code in template/resolver.rb, I think the current behaviour is surprising to developers. This commit deprecates the existing "lookup a template from anywhere" behaviour and replaces it with "render this file exactly as it is on disk". Handlers will no longer be used (it will render the same as if the :raw handler was used), but formats (.html, .xml, etc) will still be detected (and will default to :plain). The existing render file: behaviour was the path through which Rails apps were vulnerable in the recent CVE-2019-5418. Although the vulnerability has been patched in a fully backwards-compatible way, I think it's a strong hint that we should drop the existing previously-vulnerable behaviour if it isn't a benefit to developers.
* | Remove :all symbol from Mime::ALLJohn Hawthorn2019-03-271-0/+13
|/ | | | | | .all isn't a valid file extension, so it shouldn't used as a symbol. This also makes Mime::ALL better match how */* is parsed from an Accept header.
* Address rubocop offencesRyuta Kamizono2019-03-211-1/+1
|
* Fix test broken by 04ae0b0b5e594e0bb99c5cd608921745977bcdcdRafael Mendonça França2019-03-191-3/+4
| | | | | This test was trying to set the exception_app in the wrapper proxy instead in the middleware itself.
* Fix a ContentNegotiation test descriptionSharang Dashputre2019-03-191-1/+1
|
* Only accept formats from registered mime typesJohn Hawthorn2019-03-102-6/+18
| | | | | [CVE-2019-5418] [CVE-2019-5419]
* Pass the template format to the digestorAaron Patterson2019-02-151-11/+14
| | | | | | | | | | | | | | | This commit passes the template format to the digestor in order to come up with a key. Before this commit, the digestor would depend on the side effect of the template renderer setting the rendered_format on the lookup context. I would like to remove that mutation, so I've changed this to pass the template format in to the digestor. I've introduced a new instance variable that will be alive during a template render. When the template is being rendered, it pushes the current template on to a stack, setting `@current_template` to the template currently being rendered. When the cache helper asks the digestor for a key, it uses the format of the template currently on the stack.
* Ensure that `redirect_back` with `fallback_location` to another host is allowedbogdanvlviv2019-01-251-0/+29
| | | | I would like to add those tests to prevent regression.
* Merge pull request #35018 from gmcgibbon/revert_redirect_to_allow_other_hostRafael França2019-01-223-42/+12
|\ | | | | Revert ensure external redirects are explicitly allowed
| * Revert ensure external redirects are explicitly allowedGannon McGibbon2019-01-223-42/+12
| |
* | Merge pull request #34952 from rails/template-stuffAaron Patterson2019-01-221-55/+0
|\ \ | |/ |/| Template Handler Refactoring
| * Templates should be eval'd in the context of an AV::Base objectAaron Patterson2019-01-171-55/+0
| |
* | Remove secret_token rack env and cookie upgrade codeRafael Mendonça França2019-01-172-3/+10
| | | | | | | | Now that secret_token was removed all this code is now dead.
* | Remove deprecated `fragment_cache_key` helper in favor of ↵Rafael Mendonça França2019-01-171-8/+0
| | | | | | | | `combined_fragment_cache_key`
* | Ensure external redirects are explicitly allowedGannon McGibbon2019-01-173-12/+42
| | | | | | | | Add `fallback_location` and `allow_other_host` options to `redirect_to`.
* | Revert "Don't handle params option in a special way in url_for helper"Rafael Mendonça França2019-01-162-1/+9
|/ | | | | | | | | | | This reverts commit e385e4678fc64be6e176c3bdac6641db9fe48d85. While this option was undocumented it exists to make possible to pass parameters to the route helpers that are reserved like `:domain`. While `url_for(domain: 'foo.com')` would generate a URL in the `foo.com` domain `url_for(params: { domain: 'foo.com' })` would generate a URL with `?domain=foo.com`.
* Enable `Lint/UselessAssignment` cop to avoid unused variable warnings (#34904)Ryuta Kamizono2019-01-092-4/+4
| | | | | | | | | | | | | | * Enable `Lint/UselessAssignment` cop to avoid unused variable warnings Since we've addressed the warning "assigned but unused variable" frequently. 370537de05092aeea552146b42042833212a1acc 3040446cece8e7a6d9e29219e636e13f180a1e03 5ed618e192e9788094bd92c51255dda1c4fd0eae 76ebafe594fc23abc3764acc7a3758ca473799e5 And also, I've found the unused args in c1b14ad which raises no warnings by the cop, it shows the value of the cop.
* Allow using combine the Cache-Control `public` and `no-cache` headersyuuji.yaginuma2019-01-071-0/+10
| | | | | | | | | | | | | | | | | Since #30367, if `no-cache` includes Cache-Control headers, special keys like `public`, `must-revalidate` are ignored. But in my understanding, `public` still need in case of want to cache authenticated pages. The authenticated pages to be cacheable, but still authenticated for every user, need to specify the `Cache-Control: public, no-cache`. For keys other than `public`, I did not know the case where it was necessary to use it in combination with `no-cache`, so I fixed that can be used only for `public`. Ref: https://www.mnot.net/cache_docs/#CACHE-CONTROL Fixes #34780.
* Make Rails Facebook-freeSasha Koss2018-12-241-2/+2
| | | If Basecamp is a Facebook-free business, then Rails should be Facebook-free framework.
* Remove unused methodsyuuji.yaginuma2018-12-231-26/+0
| | | | These were unused since 11af089cee0a0e744e267d32becfe2c66a586d31 and e35b98e6f5c54330245645f2ed40d56c74538902.
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-213-50/+38
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-1/+1
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Pass the correct value as JSONyuuji.yaginuma2018-12-191-1/+1
| | | | | | | | | | | | This takes away the following log. ``` Error occurred while parsing request parameters. Contents: {:foo=>"heyo"} ``` Pass the correct value as JSON
* Merge pull request #34737 from r7kamura/feature/test-case-params-nilKasper Timm Hansen2018-12-181-0/+12
|\ | | | | Allow nil params on controller HTTP test methods
| * Allow nil params on controller HTTP test methodsr7kamura2018-12-181-0/+12
| |
* | More exercise `test_running_prepended_before_and_after_action`Ryuta Kamizono2018-12-191-1/+3
|/ | | | | Just testing that `after_action` is invoked before `prepend_after_action`.
* Allow using parsed_body in ActionController::TestCaseTobias Bühlmann2018-12-161-0/+14
| | | | | | | | | | | | … by switching the initialzation of an appropriate response parser in `ActionDispatch::TestResponse` from eagerly to lazily. By doing so, the response parser can be correctly set for `ActionController::TestCase`, which doesn't include the content type header in the constructor but only sets it at a later time. Fixes #34676.
* Merge pull request #20865 from colavitam/only-except-behaviorRafael Mendonça França2018-11-191-0/+22
|\ | | | | | | :only and :except are now chained for routing resource(s)