aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/render_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* `RenderingHelper` supports rendering objects that `respond_to?` `:render_in`Joel Hawksley2019-06-121-0/+17
| | | | | | | | | | | | Co-authored-by: Natasha Umer <natashau@github.com> Co-authored-by: Aaron Patterson <tenderlove@github.com> Co-authored-by: Shawn Allen <shawnbot@github.com> Co-authored-by: Emily Plummer <emplums@github.com> Co-authored-by: Diana Mounter <broccolini@github.com> Co-authored-by: John Hawthorn <jhawthorn@github.com> Co-authored-by: Nathan Herald <myobie@github.com> Co-authored-by: Zaid Zawaideh <zawaideh@github.com> Co-authored-by: Zach Ahn <engineering@zachahn.com>
* Remove useless `GC.start` in `test/template/render_test.rb`Ryuta Kamizono2019-05-061-14/+0
| | | | | The `GC.start` was added at b29e893, but the finalizer has been removed at 7d0ce78 in #35036.
* Clear Resolvers' cache after running RenderTestCases' test casesst00122019-05-061-4/+9
| | | | | | | | | The templates rendered in RenderTestCases tests will be cached by the resolvers unexpectedly. And this will break other tests when executed in certain order. (See https://github.com/rails/rails/issues/36154 for more detail) So to fix this issue, we just need to clear the caches on all resolvers.
* Fix partial caching ignore repeated items issuest00122019-04-041-0/+22
| | | | | | This is because we only use hash to maintain the result. So when the key are the same, the result would be skipped. The solution is to maintain an array for tracking every item's position to restructure the result.
* Merge pull request #35688 from jhawthorn/render_file_rfcAaron Patterson2019-03-301-13/+23
|\ | | | | RFC: Introduce Template::File
| * Introduce Template::File as new render file:John Hawthorn2019-03-271-13/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Fix annotated typoPrathamesh Sonpatki2019-03-291-4/+4
| |
* | Merge pull request #35308 from ↵Rafael França2019-03-281-0/+6
|\ \ | |/ |/| | | | | erose/better-error-reporting-for-syntax-errors-in-templates Display a more helpful error message when an ERB template has a Ruby syntax error.
| * Add handling and tests.Eli Rose2019-02-171-0/+6
| |
* | Prefer render template: in testsJohn Hawthorn2019-03-211-20/+21
| | | | | | | | | | | | | | | | | | | | | | | | Many tests were using `render file:`, but were only testing the behaviour of `render template:` (file: just allows more paths/ is less secure then template:). The reason for so many `render file:` is probably that they were the old default. This commit replaces `render file:` with `render template:` anywhere the test wasn't specifically interested in using `render file:`.
* | Deprecate ActionView::PathSet as argument to ActionView::Base.newCliff Pruitt2019-02-201-0/+4
| | | | | | | | Currently, `ActionView::Base.new` will raise a `NotImplementedError` when given an instance of `ActionView::PathSet` on initialization. This commit prevents the raised error in favor of a deprecation warning.
* | Move inline rendering content-type test to a controller testAaron Patterson2019-02-191-5/+0
| | | | | | | | | | | | This commit is to remove direct access to the "rendered_format" attribute on the lookup context. "rendered_format" is an implementation detail that we shouldn't test directly.
* | Add a test that writes to the collection cacheAaron Patterson2019-02-191-1/+8
| |
* | Merge pull request #35293 from rails/remove-rendered-format-from-cacheAaron Patterson2019-02-191-1/+1
|\ \ | | | | | | Pass the template format to the digestor
| * | Pass the template format to the digestorAaron Patterson2019-02-151-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* / Show deprecated message instead of raise exception in ↵yuuji.yaginuma2019-02-161-0/+7
|/ | | | | | | | | | | | | `compiled_method_container` method Since #35036, the subclasses of `ActionView::Base` requires the `compiled_method_container`. This is incompatible. For example, `web-console` use view class that subclass of `ActionView::Base`, and does not work it now cause of this. Actually, since it seems that it is only `ActionView::Base` that `compiled_method_container` is necessary, modified the condition that emits a warning.
* Merge pull request #35253 from rails/cached-collections-must-have-a-templateAaron Patterson2019-02-131-0/+11
|\ | | | | Cached collections only work if there is one template
| * Cached collections only work if there is one templateAaron Patterson2019-02-131-0/+11
| | | | | | | | | | Cached collections only work if there is one template. If there are more than one templates, the caching mechanism doesn't have a key.
* | Turn lookup context in to a stack, push and pop if formats changeAaron Patterson2019-02-111-2/+5
| | | | | | | | | | | | | | | | | | | | | | This commit keeps a stack of lookup contexts on the ActionView::Base instance. If a format is passed to render, we instantiate a new lookup context and push it on the stack, that way any child calls to "render" will use the same format information as the parent. This also isolates "sibling" calls to render (multiple calls to render in the same template). Fixes #35222 #34138
* | Adding another failing test caseAaron Patterson2019-02-111-1/+10
| |
* | Add a failing test for #35222Aaron Patterson2019-02-111-0/+6
|/
* Always call superAaron Patterson2019-02-081-2/+0
|
* Teach DetailsKey how to clear the template cacheAaron Patterson2019-02-081-6/+5
| | | | | This commit exposes all system wide view paths so that we can clear their caches.
* Pull generated methods up in to the anonymous subclassAaron Patterson2019-02-061-8/+1
| | | | Then we don't need the extra module.
* Move templates to an anonymous subclass of AV::BaseAaron Patterson2019-02-061-2/+19
| | | | | Now we can throw away the subclass and the generated methods will get GC'd too
* Take in to account optional arguments when deprecatingAaron Patterson2019-02-041-0/+9
| | | | Refs: rails/jbuilder#452
* Pass source to template handler and deprecate old style handlerAaron Patterson2019-02-011-3/+12
| | | | | | | | | This commit passes the mutated source to the template handler as a parameter and deprecates the old handlers. Old handlers required that templates contain a reference to mutated source code, but we would like to make template objects "read only". This change lets the template remain "read only" while still giving template handlers access to the source code after mutations.
* add tests to make sure deprecated API is still supportedAaron Patterson2019-01-311-0/+10
|
* Tighten up the AV::Base constructorAaron Patterson2019-01-291-1/+1
| | | | | | | | | | | | | | | The AV::Base constructor was too complicated, and this commit tightens up the parameters it will take. At runtime, AV::Base is most commonly constructed here: https://github.com/rails/rails/blob/94d54fa4ab641a0ddeb173409cb41cc5becc02a9/actionview/lib/action_view/rendering.rb#L72-L74 This provides an AV::Renderer instance, a hash of assignments, and a controller instance. Since this is the common case for construction, we should remove logic from the constructor that handles other cases. This commit introduces special constructors for those other cases. Interestingly, most code paths that construct AV::Base "strangely" are tests.
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Don’t allocate array on no argsschneems2018-09-071-1/+1
| | | | | | | | | | When no dependencies are present to be digested there is no reason to build an array just to turn around and turn it back into a string. The dependencies array is not mutated in this method so we can use the same empty array across all invocations. Total allocated: 791402 bytes (7294 objects) Total allocated: 777442 bytes (7132 objects) (791402 - 777442) / 791402.0 # => 1.76 % speed improvement
* Use frozen string literal in actionview/Kir Shatrov2017-07-241-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
|\ | | | | | | Enforce frozen string in Rubocop
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | Make ActionView frozen string literal friendly.Pat Allan2017-06-201-2/+2
|/ | | | Plus a couple of related ActionPack patches.
* Define path with __dir__bogdanvlviv2017-05-231-2/+2
| | | | | | ".. with __dir__ we can restore order in the Universe." - by @fxn Related to 5b8738c2df003a96f0e490c43559747618d10f5f
* Use recyclable cache keys (#29092)David Heinemeier Hansson2017-05-181-3/+3
|
* Should escape meta characters in regexpRyuta Kamizono2017-05-071-2/+2
|
* Add tests for render template/partial with variants option.Stan Lo2017-04-141-0/+8
|
* Add information on `:formats` option in action_view_overview.mdkenta-s2017-02-061-2/+1
|
* Fix CI failure caused by aa647b46cce55ec12f5895e403c0d1b85502c8e0Ryuta Kamizono2017-02-021-1/+1
|
* Fix test failures only seen when executed via bin/testAkira Matsuda2017-02-021-1/+1
| | | | | sub_template_message distracts Rails.root from its message only when Rails.root is defined, and Rails.root is defined at tools/test.rb
* Merge pull request #27795 from meagar/fix-missing-partial-iterationRafael França2017-01-311-0/+9
|\ | | | | Fix missing partial iteration
| * Add partial iteration variable to template keysMatthew Eagar2017-01-251-0/+9
| | | | | | | | | | | | | | When rendering heterogeneous collection using `render @collection` or `render partial: @collection`, the expected `<partial_name>_iteration` variable is missing due to `find_template` not having the name of the iteration variable included in its cache keys.
* | Get neglected TODO done in render_testkenta-s2017-01-241-2/+1
|/
* Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-5/+5
| | | | (I personally prefer writing one string in one line no matter how long it is, though)
* Remove unneeded Deprecation silenceRafael Mendonça França2017-01-061-5/+3
|
* improve error message when include assertions failMichael Grosser2016-09-161-1/+1
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Add three new rubocop rulesRafael Mendonça França2016-08-161-7/+7
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.