Commit Graph

2382 Commits

Author SHA1 Message Date
Akira Matsuda 8d2866bb80 You give jruby_skip & rubinius_skip a good name
This hack prevails everywhere in the codebase by being copy & pasted, and it's actually not a negative thing but a necessary thing for framework implementors,
so it should better have a name and be a thing.

And with this commit, activesupport/test/abstract_unit.rb now doesn't silently autoload AS::TestCase,
so we're ready to establish clearner environment for running AS tests (probably in later commits)
2019-08-02 05:36:38 +09:00
Akira Matsuda 98d0f7ebd3 MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now
It's used everywhere, clean and mature enough
2019-08-02 05:36:15 +09:00
Ryuta Kamizono ad957273f5 Fix `_write_layout_method` 2019-08-02 01:55:47 +09:00
Rafael Mendonça França d40c88ae05
No private def 2019-08-01 11:18:42 -04:00
Akira Matsuda d21e5fbc70 These methods doesn't have to be `protected` 2019-08-01 17:58:00 +09:00
Akira Matsuda af2129b4c7 Use `try` only when we're unsure if the receiver would respond_to the method 2019-08-01 17:58:00 +09:00
Ryuta Kamizono f40eb4a408
Merge pull request #36818 from hc0208/fix_typo_in_data_remote_js
Fix typo submited → submitted
2019-07-31 12:39:08 +09:00
hc0208 6a409f7341 Fix typo submited → submitted [ci skip] 2019-07-31 12:22:21 +09:00
Akira Matsuda 46d207fde4 Avoid creating new Array when looking up already registered detail 2019-07-31 12:18:42 +09:00
Prem Sichanugrist 004f223f33
Merge pull request #36813 from haruyuki97/haruyuki97/fix-comment-in-url-helper
Fix a/an usage on `phone_to` documentation.

[ci skip]
2019-07-30 18:59:31 +09:00
haruyuki97 96e8a817fa fix a typo [ci skip] 2019-07-30 18:49:25 +09:00
Akira Matsuda 0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
Akira Matsuda 8f90ac7827 Add AS::TimeZone#match? 2019-07-29 14:17:36 +09:00
Akira Matsuda 62d089a4ad Suppress Ruby warning: ⚠️ non-nil $, will be deprecated 2019-07-29 12:55:28 +09:00
st0012 e289c8d775 Assert query counts in cache relation test
This is to guard the change in #35982
2019-07-28 14:24:47 +08:00
Akira Matsuda d1ffe59ab5 Use match? where we don't need MatchData
We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice
2019-07-27 13:06:49 +09:00
Pietro Moro c285c15820 Change test description with the correct URL name 2019-07-26 21:25:23 +00:00
Rafael França a0e58e687d
Merge pull request #36178 from sshaw/fix_time_zone_options_priority
Update time_zone_options_for_select docs
2019-07-26 16:03:37 -04:00
Abhay Nikam b34d7692c1 Change the test description to say the URL helper name in test. 2019-07-27 00:41:28 +05:30
Pietro Moro 0eff6956a5 Added a phone_to helper method, on the style of mail_to and sms_to. (#36775)
* Added a phone_to helper method, on the style of mail_to and sms_to.

It creates an anchor tag with the href set to tel: *here your number*
which, when clicked on a mobile phone, or on a desktop with a supported
application, lets the phone app kick in, and it prepopulates it with the
phone number specified.

[Pietro Moro + Rafael Mendonça França]
2019-07-26 14:54:57 -04:00
Rafael França 1760fe919f
Merge pull request #36764 from willianveiga/feature/inputs-inside-disabled-fieldset-are-not-submited-on-remote-true-forms
Inputs inside disabled fieldset are not submited on remote: true forms
2019-07-26 13:48:18 -04:00
Willian Gustavo Veiga 64631d83c5 Add test for submitted fields within disabled fieldsets 2019-07-26 12:59:23 -03:00
Sharang Dashputre b00a183aa1 Add a default value for arg `format` in `ActionView::Digestor.digest()` 2019-07-26 15:22:43 +05:30
Rafael França a11a7b2c7b
Merge pull request #35334 from sharang-d/digest-doc-update
Update comment for ActionView::Digestor.digest [ci skip]
2019-07-26 00:01:08 -04:00
Rafael Mendonça França 64f4d7fcb0
Merge pull request #36576 from mtsmfm/mtsmfm/fix-fixture-resolver
Support :any variants for ActionView::FixtureResolver
2019-07-25 22:24:31 -04:00
Rafael Mendonça França c9b7b9ff8a
Merge pull request #36412 from robotdana/compact_blank
Add compact_blank shortcut for reject(&:blank?)
2019-07-25 16:18:18 -04:00
Willian Gustavo Veiga c3e786fc48 Issue #36728 - Inputs inside disabled fieldset are not submited on remote: true forms 2019-07-25 16:07:11 -03:00
Rafael França 89ba95b69a
Merge pull request #36467 from spk/add-doc-host-protocol-asset_path
Add documentation on actionview asset_path with host and protocol
2019-07-24 14:14:08 -04:00
Ryuta Kamizono 0e149abbd5 Fix broken rdoc for UrlHelper [ci skip]
* Fix unintentionally linked String, Symbol, Hash, and ERB.
* Fix unintentionally code block.
2019-07-24 12:55:28 +09:00
Carlos Antonio da Silva 876548a7e7 Fix argument in doc sample of new `sms_to` helper [ci skip] 2019-07-19 18:10:47 -03:00
Guillermo Iguaran ea91f9bc1c
Merge pull request #36511 from aantix/sms_link_helper
Helper method to create an sms link
2019-07-19 15:36:58 -05:00
Jean Boussier bd78d3eecf Fix a minor typo in ActionView::UnboundTemplate 2019-07-19 15:18:57 +02:00
Guilherme Mansur 526a5eb10c Empty array instead of nil for source_extract
The source_extract method will return nil when it can't find the file name in
the backtrace, methods that consume this method expect an array and the nil ends
up causing type errors down the road like it happened here: #36341. This
patch refactors the source_extract method so that it returns an empty
array instead of nil when it can't find the source code.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2019-07-14 15:04:25 -04:00
Akira Matsuda 356857a122 active_support/deprecation has to be already required via active_support/rails.rb 2019-07-12 18:34:07 +09:00
Akira Matsuda b2b897217d A type class or nil has to respond_to :to_s 2019-07-12 18:33:31 +09:00
Akira Matsuda 00c3f3fca2 No Woman, No try 2019-07-12 18:32:45 +09:00
Fumiaki MATSUSHIMA 92af4aba25 Support :any variants for FixtureResolver 2019-06-30 02:23:08 +09:00
Guilherme Mansur 99e52ae7b1 Autoload SyntaxErrorInTemplate
When a SyntaxError is detected in a template we raise this exception. On
a first request to the server the exception we get a NameError since the
exception is not required from `active_view/template/error.rb` yet.
However later on it gets required and a second request will succeed.
On the first request we see the rails "Something Wen Wrong" page and not
the expected syntax error in template error page with the webconsole and
stacktrace. By autoloading the constant we fix this issue.

Co-authored-by: Gannon McGibbon <gannon.mcgibbon@gmail.com>
2019-06-19 14:53:24 -04:00
Jim Jones d2d15ad8a5 Doc changes. 2019-06-18 14:01:43 -05:00
Jim Jones 3115b735ea Helper method to create an sms link - when clicked it opens the phone/desktop's messaging client with the phone number and optional body value prepopulated. 2019-06-18 12:10:16 -05:00
Rafael França c65acad0df
Merge pull request #36482 from Shopify/fix-translation-helper-default-hash
Fix TranslationHelper#translate handling of Hash defaults
2019-06-17 13:38:39 -04:00
Akira Matsuda c8a84603e2 2019-06-15 15:19:13 +09:00
Ryuta Kamizono c0af72bf86 Fix rubocop violations 2019-06-14 23:32:15 +09:00
Jean Boussier 5d4a77d324 Fix TranslationHelper#translate handling of Hash defaults
It is sometimes expected of the `translate` methods to return a Hash,
for instance it's the case of the `number.format` key.

As such users might need to specify a Hash default, e.g.

`translate(:'some.format', default: { separator: '.', delimiter: ',' })`.

This works as expected with the `I18n.translate` methods,
however `TranslationHelper#translate` apply `Array()` on the default value.

As a result the default value end up as `[:separator, '.', :delimiter, ',']`.
2019-06-14 14:07:28 +02:00
Rafael França 95d038f020
Merge pull request #36477 from albertoalmagro/alberto/button-to-default-path
[ci skip] Use default path in button_to documentation
2019-06-13 17:45:59 -04:00
Gannon McGibbon c9e52d028c
Merge pull request #36437 from sudara/fix_programmatic_clicks_with_data_remote
Fix programmatic clicks with data-remote
2019-06-13 17:30:38 -04:00
Alberto Almagro 4f4fd0a625 [ci skip] Use default path in button_to documentation
This is really a nit pick, but as this is the framework's documentation
I think it should follow standards as many times as possible to avoid
confusion in new users.

If we were using `resources :articles` in routes. which is what scaffold
adds, the generated helper would be `new_article_path` instead of
`new_articles_path`.
2019-06-13 23:20:31 +02:00
Sudara ab4ed8c786 Ensure non-mouse/programmatic clicks work with data-remote 2019-06-13 19:59:17 +02:00
Aaron Patterson 3683a828dc
Merge pull request #36388 from joelhawksley/actionview-component
Introduce ActionView::Component
2019-06-13 09:37:49 -07:00
Ryuta Kamizono c81af6ae72 Enable `Layout/EmptyLinesAroundAccessModifier` cop
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.
2019-06-13 12:00:45 +09:00
Joel Hawksley c221b5b448
`RenderingHelper` supports rendering objects that `respond_to?` `:render_in`
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>
2019-06-12 16:31:01 -06:00
Laurent Arnoud 6b651d9904
Add documentation on actionview asset_path with host and protocol 2019-06-12 13:57:48 +02:00
John Hawthorn 1126d14c14
Merge pull request #36422 from jhawthorn/parallelize_actionview
Run actionview tests in parallel
2019-06-06 11:23:31 -07:00
Abhay Nikam 00b3b68602 Bump rubocop to 0.71 2019-06-06 15:34:50 +05:30
John Hawthorn df4ab6e103 Run actionview tests in parallel 2019-06-05 18:40:08 -07:00
John Hawthorn d130ea2ff2 Remove actionview tests which modify fixtures
We shouldn't modify fixtures (or any files which are checked-in). It
prevents us from parallelizing, and probably has other issues.

We could fix these tests by copying the file to a tmpdir and modifying
it there, but I don't think they are testing anything useful anymore.
Re-initializing a resolver isn't representative of "uncached" rendering
(either in dev-mode or using lookup_context.disable_cache).
2019-06-05 18:40:06 -07:00
Dana Sherson 459657a9f8 Use compact_blank throughout rails 2019-06-05 18:26:19 +10:00
yuuji.yaginuma a72f19a6c3 Only clear cache when view paths are specified
Currently, `clear_cache_if_necessary` is executed even if view paths are
not set like `rails console`.
If the watcher class is `EventedFileUpdateChecker` and the watch
directories are empty, the application root directory will watch. This
is because listen uses the current directory as the default watch directory.
8d85b4cd57/lib/listen/adapter/config.rb (L13)

As a result, `node_modules` also watch. This cause a warning of `listen`.
Ref: https://github.com/rails/rails/pull/36377#issuecomment-498399576
2019-06-04 08:44:28 +09:00
yuuji.yaginuma ea5f509643 Change `ActionDispatch::Response#content_type` returning Content-Type header 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.
39de7fac05/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 ]
2019-06-01 09:20:13 +09:00
Eileen M. Uchitelle 350ae29635
Merge pull request #36324 from yoones/fix-unexpected-select-tag-delete-behavior
Fix unexpected select_tag delete behavior when include_blank is present
2019-05-28 08:20:21 -07:00
Younes SERRAJ a4229a534f Fix select_tag so that is doesn't change options when include_blank is set 2019-05-22 10:21:59 +02:00
John Hawthorn be34af0c53 Wrap actionview cache expiry in a mutex 2019-05-21 19:46:42 -07:00
Alexander Graul 2256f0bdb0
Correct human file size examples [ci skip]
The `number_to_human_size` helpers in Action View and Active Support
calculate the "human size" with a base of 1024. The examples should
reflect that so they don't confuse the reader.

The updated documentations use the values from:

    helper.number_to_human_size(1500)
2019-05-20 18:25:11 +02:00
Xavier Noria 65f9e0c4bb NPM -> npm [ci skip]
According to https://www.npmjs.com/.
2019-05-12 12:00:03 +02:00
st0012 405b4c7f1e Remove useless find_partial method 2019-05-07 01:21:07 +08:00
Ryuta Kamizono 020856c328 Remove useless `GC.start` in `test/template/render_test.rb`
The `GC.start` was added at b29e893, but the finalizer has been removed
at 7d0ce78 in #35036.
2019-05-06 23:30:07 +09:00
st0012 34a33f8b0c Clear Resolvers' cache after running RenderTestCases' test cases
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.
2019-05-06 22:08:48 +08:00
sshaw 5ee4a57a26 Update time_zone_options_for_select docs 2019-05-04 20:17:35 -04:00
Rafael França a0434ce37f
Merge pull request #35337 from abhaynikam/35265-remove-unused-argument-layout-from-rendered-template
Removed unused layout attribute from RenderedTemplate
2019-05-01 15:45:06 -05:00
Akira Matsuda fef174f5c5 `@controller` may not be defined here, and if so, it causes a Ruby warning
e.g. via test-unit-rails' `run_setup`
2019-05-01 13:33:38 +09:00
Michael Bock 74d74496ba
Fixes grammar in comments on tag_name and tag_id 2019-04-25 11:56:56 -07:00
Rafael França d4d145a679
Merge pull request #32313 from lulalala/model_error_as_object
Model error as object
2019-04-24 16:16:00 -04:00
Rafael Mendonça França 9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Ryuta Kamizono 3a4aa49256 Fix markup in CHANGELOGs [ci skip]
Need to new line to break line in the markdown.
2019-04-25 03:19:15 +09:00
st0012 88c195bf81 Update the changelog to explain the fix 2019-04-20 01:34:53 +09:00
Koichi ITO c6379fd27f Bump RuboCop to 0.67.2
Performance cops will be extracted from RuboCop to RuboCop Performance
when next RuboCop 0.68 will be released.
https://github.com/rubocop-hq/rubocop/issues/5977

RuboCop 0.67 is its transition period.

Since rails/rails repository uses Performance cops, This PR added
rubocop-performance gem to Gemfile.

And this PR fixes some offenses using the following auto-correct.

```console
% bundle exec rubocop -a

Offenses:

activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb:212:26:
C: [Corrected] Layout/SpaceAroundOperators: Operator =
> should be surrounded by a single space.
              "primary"  => { adapter: "sqlite3", database: "db/primary.sqlite3" }
                         ^^
activerecord/test/cases/connection_adapters/connection_handlers_multi_db_test.rb:239:26:
C: [Corrected] Layout/SpaceAroundOperators: Operator => should be
surrounded by a single space.
              "primary"  => { adapter: "sqlite3", database: "db/primary.sqlite3" }
                         ^^
actionview/test/template/resolver_shared_tests.rb:1:1: C: [Corrected]
Style/FrozenStringLiteralComment: Missing magic comment #
frozen_string_literal: true.
module ResolverSharedTests
^
actionview/test/template/resolver_shared_tests.rb:10:33: C: [Corrected]
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in
default value assignment.
  def with_file(filename, source="File at #{filename}")
                                ^
actionview/test/template/resolver_shared_tests.rb:106:5: C: [Corrected]
Rails/RefuteMethods: Prefer assert_not_same over refute_same.
    refute_same a, b
    ^^^^^^^^^^^

2760 files inspected, 5 offenses detected, 5 offenses corrected
```
2019-04-16 17:58:24 +09:00
Sharang Dashputre f22441ff6e Update comment for ActionView::Digestor.digest [ci skip] 2019-04-16 14:18:41 +05:30
Rafael França ddf471a163
Merge pull request #35959 from jhawthorn/unbound_templates
De-duplicate templates, introduce UnboundTemplate
2019-04-15 17:57:39 -04:00
John Hawthorn 2455d16a5a Add additional test for sharing templates 2019-04-12 16:08:30 -07:00
John Hawthorn 0b26cc41db Avoid duplication using _find_all 2019-04-12 15:40:33 -07:00
John Hawthorn 53e4055a75 Support disabling cache for Digestor
This adds a bit of complexity, but is necessary for now to avoid holding
extra copies of templates which are resolved from ActionView::Digestor
after disabling cache on the lookup context.
2019-04-12 12:30:26 -07:00
John Hawthorn 1fc735e5f5 De-dup Templates, introduce UnboundTemplate
Previously it's possible to have multiple copies of the "same" Template.
For example, if index.html.erb is found both the :en and :fr locale, it
will return a different Template object for each. The same can happen
with formats, variants, and handlers.

This commit de-duplicates templates, there will now only be one template
per file/virtual_path/locals tuple.

We need to consider virtual_path because both `render "index"`, and
`render "index.html"` can both find the same file but will have
different virtual_paths. IMO this is rare and should be
deprecated/removed, but it exists now so we need to consider it in order
to cache correctly.

This commit introduces a new UnboundTemplate class, which represents a
template with unknown locals. Template objects can be built from it by
using `#with_locals`. Currently, this is just a convenience around
caching templates, but I hope it's a helpful concept that could have
more utility in the future.
2019-04-12 12:30:26 -07:00
utilum f999210c98 Squash `warning: instance variable @filename not initialized` 2019-04-12 15:25:30 +02:00
John Hawthorn 80e2aaa80a Add tests against resolver
We didn't previously have many tests directly against the
OptimizedFileSystemResolver or FileSystemResolver, though usually
failures would be exposed through other tests.

It's easier to test some specifics of the behaviour with unit tests.
This also lets us test FileSystemResolver (non-optimized) which I don't
think previously had much testing (other than from classses inheriting
it).
2019-04-11 17:09:00 -07:00
John Hawthorn 6e85c5c634 Remove FileTemplate
This is unnecessary now that we can just provide a file source
2019-04-04 16:21:12 -07:00
John Hawthorn 151cac65f1 Deprecate Template#refresh 2019-04-04 15:07:14 -07:00
John Hawthorn db1830a7ec Add ActionView::Template::Sources::File 2019-04-04 15:07:14 -07:00
John Hawthorn b8e6594181 Don't call Template#refresh
Now that Template#source will always return a source, this is
unnecessary.
2019-04-04 14:28:10 -07:00
John Hawthorn b8c90c3644 Don't discard source after rendering
Previously, we would discard the template source after rendering, if we
had a virtual path, in hopes that the virtual path would let us find our
same template again going through the Resolver.

Previously we discarded the source as an optimization, to avoid keeping
it around in memory. By instead just reading the file every time source
is called, as FileTemplate does, this is unnecessary.
2019-04-04 14:25:31 -07:00
localhostdotdev b2b2f70f1f Fix arity warning for template handlers
Mainly to help with knowning which template is reponsible for the
warning.

handler.class # => Class

handler.to_s # => Coffee::Rails::TemplateHandler

Before:

Change:
  >> Class#call(template)
To:
  >> Class#call(template, source)

After:

Change:
  >> Coffee::Rails::TemplateHandler.call(template)
To:
  >> Coffee::Rails::TemplateHandler.call(template, source)
2019-04-04 19:13:46 +02:00
Prathamesh Sonpatki 6a4bf486c3
Fix deprecation warning about variants and formats
- After https://github.com/rails/rails/pull/35408 and
  https://github.com/rails/rails/pull/35406, the `formats` and
  `variants` methods are deprecated in favor of `format` and `variant`.
2019-04-04 19:29:27 +05:30
Fumiaki MATSUSHIMA 61c4be4777 Output junit format test report 2019-04-04 14:34:46 +09:00
Rafael França eda2d7d7b9
Merge pull request #35145 from st0012/fix-35114
Fix partial caching ignore repeated items issue
2019-04-03 23:03:30 -04:00
st0012 e8688ddb33 Fix partial caching ignore repeated items issue
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.
2019-04-04 09:59:06 +08:00
Edward Rudd c5efbbbccb Fix checking for template variants when using the ActionView::FixtureResolver 2019-04-03 18:09:34 -04:00
Eileen M. Uchitelle d39b2b684e
Merge pull request #35825 from jhawthorn/always_filter_view_paths
Make Resolver#find_all_anywhere equivalent to #find_all
2019-04-03 13:21:51 -04:00
John Hawthorn eb52904eb5 Always reject files external to app
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.
2019-04-03 09:02:28 -07:00
Abhay Nikam b04656ecb2 [ci skip] Updated the doc after renaming Template::File -> Template::RawFile in #35826 2019-04-02 14:03:43 +05:30
Cliff Pruitt 90196398a1 Rename File to RawFile 2019-04-01 19:29:03 -04:00
Kasper Timm Hansen beb0bc9907
[ci skip] Follow up c8bf334104 2019-04-01 21:26:13 +02:00
John Hawthorn c8bf334104 Only clear template caches in dev after changes (#35629) 2019-04-01 21:22:57 +02:00
Sharang Dashputre 771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Kasper Timm Hansen 563bf5771f
Merge pull request #35793 from jhawthorn/deprecate_layout_absolute_path
Deprecate render layout with an absolute path
2019-03-31 19:05:27 +02:00
lulalala abee034368 Raise deprecation for calling `[:f] = 'b'` or `[:f] << 'b'`
Revert some tests to ensure back compatibility
2019-03-31 22:59:12 +08:00
Ryuta Kamizono b89a3e7e63 Tweaks CHANGELOGs and docs [ci skip]
* add leading `#` before `=>` since hash rocket is valid Ruby code
* add backticks
* remove trailing spaces
* and more
2019-03-31 08:38:37 +09:00
Aaron Patterson 2bf5517981
Merge pull request #35688 from jhawthorn/render_file_rfc
RFC: Introduce Template::File
2019-03-30 13:33:52 -07:00
John Hawthorn 6841d0cc6d Deprecate render layout with an absolute path
This has similar problems to render file:.

I've never seen this used, and believe it's a relic from when all
templates could be rendered from an absolute path.
2019-03-29 11:39:40 -07:00
Prathamesh Sonpatki 12701d5a46
Fix annotated typo 2019-03-29 20:42:35 +05:30
Rafael França e3f5f1c936
Merge pull request #35308 from erose/better-error-reporting-for-syntax-errors-in-templates
Display a more helpful error message when an ERB template has a Ruby syntax error.
2019-03-28 14:53:22 -04:00
John Hawthorn c7820d8124 Introduce Template::File as new render file:
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.
2019-03-27 15:51:25 -07:00
Rafael França 7fe7e74171
Merge pull request #35758 from Shigeyuki-fukuda/aligned_order_of_argument
Aligned the order of the arguments of render_template and render_with_layout
2019-03-26 22:01:18 -04:00
Ryuta Kamizono bde5f3bfc6
Merge pull request #35761 from koic/bump_rubocop_to_0_66_0
Bump RuboCop to 0.66.0
2019-03-27 08:38:57 +09:00
Koichi ITO 1e1adadb41 Bump RuboCop to 0.66.0
### Summary

RuboCop 0.66.0 has been released.
https://github.com/rubocop-hq/rubocop/releases/tag/v0.66.0

And rubocop-0-66 channel is available in Code Climate.
https://github.com/codeclimate/codeclimate/releases/tag/v0.84.0

RuboCop 0.66.0 fixed the false negative to indentation for
modifier. And this PR applied the auto-correction fixed by it.
https://github.com/rubocop-hq/rubocop/pull/6792

In addtion, this PR is also updating the following 4 gems that
RuboCop depends on.

- Update Psych gem ... https://github.com/rubocop-hq/rubocop/pull/6766
- Update Parser gem to 2.6.2.0 that supports Ruby 2.5.5 and 2.6.2 ...
 https://github.com/whitequark/parser/blob/v2.6.2.0/CHANGELOG.md#changelog
- Remove powerpack gem ... https://github.com/rubocop-hq/rubocop/pull/6806
- Update unicode-display_width gem ... https://github.com/rubocop-hq/rubocop/pull/6813
2019-03-27 07:57:43 +09:00
John Hawthorn 573e361a3c Deprecate custom patterns for PathResolver
Custom glob patterns tie the implementation (Using Dir.glob) to the API
we provide.

It also doesn't really work. extract_handler_and_format_and_variant
expects the handler, format, and variant to be at the end of the
template path, and in the same order as they are in the default pattern.

This deprecates specifying a custom path for FileSystemResolver and
removes the pattern argument of OptimizedFileSystemResolver#initialize,
which does not work with a custom pattern.
2019-03-26 14:19:31 -07:00
Shigeyuki-fukuda c546f9040e Aligned the order of the arguments of render_template and render_with_layout 2019-03-27 01:09:34 +09:00
Shailesh Kalamkar 839328c700 [ci skip] Fixed typo 2019-03-23 07:22:52 +05:30
John Hawthorn 5c2d695993 Update CHANGELOGs for 6.0.0.beta3 release 2019-03-22 13:13:01 -07:00
John Hawthorn f35631d466 Prefer render template: in tests
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:`.
2019-03-21 13:44:56 -07:00
Eileen M. Uchitelle d369911478
Merge pull request #35661 from jhawthorn/lookup_context_validation
Validate types assigned to LookupContext#formats=
2019-03-20 11:52:55 -04:00
John Hawthorn 0756733d75 Don't compact formats 2019-03-19 16:34:12 -07:00
John Hawthorn 31e488b901 Avoid assigning [nil] to formats 2019-03-19 16:33:56 -07:00
John Hawthorn a4bb6fd008 Re-add Template#updated_at as deprecated 2019-03-19 15:01:56 -07:00
Aaron Patterson 6f03c314de
Merge pull request #35662 from jhawthorn/fallback_resolver_no_virtual_path
Remove virtual_path from fallback templates
2019-03-19 12:18:17 -07:00
Eileen M. Uchitelle 7fe3c69331
Merge pull request #35604 from jhawthorn/validate_mime_types
Raise exception when building invalid mime type
2019-03-19 09:22:16 -04:00
John Hawthorn 15b315ca9c Improve "raises on invalid format assignment" test 2019-03-18 16:35:50 -07:00
John Hawthorn c80b33a461 Rename invalid_types to invalid_values 2019-03-18 16:10:13 -07:00
John Hawthorn d0c745b863 Remove virtual_path from fallback templates 2019-03-18 12:21:28 -07:00
John Hawthorn 0eb9e1e51a Raise in LookupContext#formats= on invalid format
This is a developer quality of life improvement, to ensure that unknown
formats aren't assigned (which it would previously accept, but wouldn't
work 100% correctly due to caching).
2019-03-18 11:25:50 -07:00
John Hawthorn ffc842a099 Make uniq in LookupContext#formats=
Having a format listed twice had no effect. This is mostly helpful to
avoid an extra format when assigning [:html, "*/*"]
2019-03-18 11:12:22 -07:00
John Hawthorn c555e28a4c Ignore nil in LookupContext#formats=
This also removes the mutation we were performing on the values being
passed in.
2019-03-18 11:10:52 -07:00
razh 34fc4dee39 Add regression test for HTML content in rails-ujs
See discussion in #32287
2019-03-17 14:52:14 -04:00
razh 2674fe38eb Revert "Pass HTML responses as plain-text in rails-ujs"
This reverts commit 48e44edfd0.

See discussion in #32287

For HTML content in `ajax:success` handlers, `event.detail[0]` should
be an `HTMLDocument` instance.
2019-03-17 14:50:39 -04:00
Ryuta Kamizono 98e380f024 Ruby 2.4 and later support native Unicode case mappings
Here is only place where we use `mb_chars` internally.
2019-03-18 02:27:47 +09:00
Aaron Patterson d7e4cb87d3
Merge pull request #35623 from jhawthorn/actionview_cache
Make Template::Resolver always cache
2019-03-15 14:19:17 -07:00
Seb Jacobs 47fea39ed6 Rename `ActionView::Base#run` to `#_run`
There was a recent change by @tenderlove to Action view which introduced
`ActionView::Base#run` [1].

We ran into an issue with our application because one of the core
concepts in our domain model is a `Run` which is exposed in most of our
views as a helper method, which now conflicts with this new method.

Although this is a public method it is not really meant to be part of
the public API.

In order to discourage public use of this method and to reduce the
chances of this method conflicting with helper methods we can prefix
this method with an underscore, renaming this method to `_run`.

[1] https://github.com/rails/rails/commit/c740ebdaf5
2019-03-15 20:31:24 +00:00
John Hawthorn 80c0ae7de8 Remove updated_at from Templates 2019-03-15 09:30:44 -07:00
John Hawthorn d445ceb9b5 Make Template::Resolver always cache
All actionview caches are already cleared at the start of each request
(when Resolver.caching is false) by PerExecutionDigestCacheExpiry, which
calls LookupContext::DetailsKey.clear (which clears all caches).

Because caches are always cleared per-request in dev, we shouldn't need
this extra logic to compare mtimes and conditionally reload templates.

This should make templates slightly faster in development (particularly
multiple renders of the same template)
2019-03-15 09:20:05 -07:00
John Hawthorn b5e8942c95 Raise exception when building invalid mime type
This allows mime types in the form text/html, text/*, or */*

This required a few minor test/code changes where previously nil was
used as a mime string.
2019-03-14 11:33:48 -07:00
eileencodes a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
eileencodes 7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Prathamesh Sonpatki 538a459a3b
Squish the deprecation messages across the codebase
Sample example ->

Before:

prathamesh@Prathameshs-MacBook-Pro-2 blog *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated
and will be removed in the next Rails version. Please, use the -u
option instead.

After:

prathamesh@Prathameshs-MacBook-Pro-2 squish_app *$ rails server thin
DEPRECATION WARNING: Passing the Rack server name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -u option instead.
2019-03-11 19:22:37 +05:30
Kasper Timm Hansen c87f6841b7
Merge pull request #35121 from utilum/warning_tried_to_create_proc_without_block
Ruby 2.7 warning: creating a Proc without a block
2019-03-10 16:31:15 +01:00
Kasper Timm Hansen 0fc1397784
Merge pull request #35559 from ashishprajapati/ashishprajapati/important_textual_improvements
Added missing guide links in documentation and minor wording fix
2019-03-09 22:54:21 +01:00
ashishprajapati e3ef12b310 Added missing guide links in README documentation and minor wording fix [ci skip] 2019-03-10 03:17:01 +05:30
Sharang Dashputre a90593273c Revert an incorrect change in jquery-2.2.0.js 2019-03-10 00:33:50 +05:30
Abhay Nikam 027e492b6f Fix links in gemspec and docs from http to https. 2019-03-09 19:42:35 +05:30
Ryuta Kamizono b7fa01bb2f
Merge pull request #35529 from abhaynikam/35492-follow-up-to-updates-links-to-https
Updated links from http to https in guides, docs, etc
2019-03-09 20:49:27 +09:00
Abhay Nikam 476abd403b Updated links from http to https in guides, docs, etc 2019-03-09 16:43:47 +05:30
Shailesh Kalamkar 70192cec42 [ci skip] Minor documentation fixes for consistency 2019-03-09 12:15:00 +05:30
Abhay Nikam 1de6a20a6d Removed unused layout attribute from RenderedTemplate 2019-03-09 11:54:42 +05:30
George Claghorn ceeef26fd4
Read the CSP nonce on page load
Turbolinks replaces the CSP nonce <meta> tag on page change, but inline scripts inserted by UJS need the nonce from the initial page load. In general, it doesn't matter to UJS if the nonce changes after the page loads: only the initial value is relevant.
2019-03-08 15:25:24 -05:00
Shailesh Kalamkar de5d84bfbb [ci skip] Fix typos 2019-03-07 10:06:30 +05:30
Aaron Patterson ed6364f7b6
Merge pull request #35429 from jhawthorn/template_format_nil
Allow nil format on templates
2019-03-01 14:06:41 -08:00
Xavier Noria 42ca13a994 Removes unnecessary dot in regexp
A string S matches ([.]|\b)html if an only if matches \bhtml:

  * If S matches [.]html, then it matches \bhtml.

  * If S matches \bhtml, then it matches \bhtml.

Reciprocally:

  * If S matches \bhtml, then it matches ([.]|\b)html.

The character class can be removed, and since we are on it we remove the
group too so that it is clear to a reader of the code that there is no
grouping going on.

References #35166.
2019-02-28 14:08:54 -08:00
John Hawthorn bcd42ae974 Remove query_format argument from resolver 2019-02-26 16:59:04 -08:00
John Hawthorn c214546217 Create templates with format=nil 2019-02-26 16:59:04 -08:00
John Hawthorn ff4b2cf241 Allow format to be nil 2019-02-26 16:59:04 -08:00
Aaron Patterson 383efb0138
Merge pull request #35411 from rails/pass-locals-to-template
Pass locals in to the template object on construction
2019-02-26 11:03:46 -08:00
Aaron Patterson 082130d1d4
Remove unused method / fix documentation 2019-02-26 10:07:46 -08:00
John Hawthorn ebb4e015c9
Update actionview/lib/action_view/template/resolver.rb
Co-Authored-By: tenderlove <tenderlove@github.com>
2019-02-26 10:05:02 -08:00
Abhay Nikam 622e32c188 [ci skip] Renamed formats -> format in test after #35406 2019-02-26 08:35:15 +05:30
Aaron Patterson 0e13941dbe
`original_encoding` isn't used, so deprecate it and remove the ivar 2019-02-25 16:42:45 -08:00
Aaron Patterson 3a8d5dac9a
Expand key word args for ActionView::Template 2019-02-25 16:39:13 -08:00
Aaron Patterson 9a343d148b
Don't mutate `virtual_path`, remove `decorate`
`virtual_path` is calculated in the constructor when the Template object
is allocated.  We don't actually need to set it in the `decorate`
method.  That means we can remove the decorate method all together.
2019-02-25 16:33:05 -08:00
Aaron Patterson d4015a7f06
Pass locals in to the template object on construction
This commit ensures that locals are passed in to the template objects
when they are constructed, then removes the `locals=` mutator on the
template object.  This means we don't need to mutate Template objects
with locals in the `decorate` method.
2019-02-25 15:14:53 -08:00
Aaron Patterson a92e5eb4ae
Merge pull request #35408 from rails/template-has-one-variant
Template has one variant
2019-02-25 15:11:12 -08:00
Rafael Mendonça França 5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
John Hawthorn dcb1347099 Improve Template#inspect output (#35407)
* Don't call inspect from identifier_method_name

* Add locals Template#inspect

Handler, formats, and variant are usually obvious from looking at the
identifier. However it's not uncommon to have different locals for the
same template so we should make that obvious in inspect.

* Add tests for short_identifier and inspect

[John Hawthorn + Rafael Mendonça França]
2019-02-25 17:43:30 -05:00
Aaron Patterson da8cb4fa3d
Change `variants` to `variant`
Templates only have one variant, so we should not store it in an array.
This commit converts `variants` to `variant` and deprecates the plural
accessor
2019-02-25 14:38:12 -08:00
Aaron Patterson bcf49299ff
Remove potential `variants` mutation in `decorate`
Even if the template is constructed with a `nil` variant, the array it
constructs will never be `empty?`:

  56b030605b/actionview/lib/action_view/template.rb (L152)

We get an array that is `[nil]`, which is not empty, so this conditional
is never true.
2019-02-25 14:25:43 -08:00
Aaron Patterson c0c1441144
Convert `variant` to a keyword arg 2019-02-25 14:21:14 -08:00
Aaron Patterson ca5e23ed4d
Templates have one format
Templates only have one format.  Before this commit, templates would be
constructed with a single element array that contained the format.  This
commit eliminates the single element array and just implements a
`format` method.  This saves one array allocation per template.
2019-02-25 13:18:44 -08:00
Ryuta Kamizono 12ff6064d1
Update actionview/lib/action_view/template.rb
Co-Authored-By: tenderlove <tenderlove@github.com>
2019-02-25 12:33:29 -08:00
Aaron Patterson a213c4829a
remove the formats writer on templates 2019-02-25 12:26:30 -08:00
Aaron Patterson bc74959aad
Dereference the format type before template construction
The format should always be exactly one symbol.  Now we don't need to
check whether or not the format is a `Type` in the constructor.
2019-02-25 12:26:30 -08:00
Aaron Patterson 2f128a82e6
Always pass a format to the ActionView::Template constructor
This means we can eliminate nil checks and remove some mutations from
the `decorate` method.
2019-02-25 12:26:25 -08:00
Aaron Patterson 52eafbd749
Add a finalizer to inline templates
This commit adds a finalizer just to inline templates.  We can't cache
compilation of inline templates because it's possible that people could
have render calls that look like this:

```ruby
loop do
  render inline: "#{rand}"
end
```

and we would cache every one of these different inline templates.  That
would cause a memory leak.  OTOH, we don't need finalizers on regular
templates because we can cache, control, and detect changes to the
template source.

Fixes: #35372
2019-02-22 17:59:55 -08:00
Aaron Patterson a342d97d57
Merge pull request #35371 from rails/always-have-a-format
Ensure that rendered templates always have a format
2019-02-22 12:48:45 -08:00
Aaron Patterson 62cb3ee35c
Ensure that rendered templates always have a format
This removes one call to `lookup_context` and also eliminates a
conditional in `_render_template`.
2019-02-22 11:58:04 -08:00
Aaron Patterson 5e29ea0f2a
Merge pull request #35369 from rails/fewer-lookup-context-calls
Pass lookup context to the layout handlers
2019-02-22 11:20:33 -08:00
Aaron Patterson 1cf3878927
Pass lookup context to the layout handlers
I want to start reducing the calls to `lookup_context`.  That method
caches the lookup context in an ivar, but I would like to cache the
lookup context on the stack.  That way we aren't coupled to the behavior
of the `lookup_context` method.
2019-02-22 10:39:25 -08:00
George Claghorn 2083f38735 Prefer I18n.with_locale 2019-02-21 23:57:45 -05:00
alkesh26 955eac5a52 [ci skip] actionview typo fixes. 2019-02-21 01:33:14 +05:30
Cliff Pruitt 998ed7eb3e Deprecate ActionView::PathSet as argument to ActionView::Base.new
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.
2019-02-20 10:54:05 -05:00
Aaron Patterson 1c74752500
Deprecate LookupContext#rendered_format
We no longer depend on `rendered_format` side effects, so we can remove
this method now. 🎉
2019-02-19 15:52:33 -08:00
Aaron Patterson 3f84a814aa
Fix up style 2019-02-19 14:57:29 -08:00
Aaron Patterson 1bc0a59d6e
Return rendered template information instead of just strings
This commit introduces "rendered template" and "rendered collection"
objects.  The template renderers can now return a more complex object
than just strings.  This allows the framework to get more information
about the templates that were rendered.  In this commit we use the
rendered template object to set the "rendered_format" on the lookup
context in the controller rather than all the way in the template renderer.
That means we don't need to check the "rendered_format" every time we
render a template, we just do it once after all templates have been
rendered.
2019-02-19 13:46:09 -08:00
Aaron Patterson d0733ba8c0
Move inline rendering content-type test to a controller test
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.
2019-02-19 13:46:09 -08:00
Aaron Patterson 4f77982e21
Add a test that writes to the collection cache 2019-02-19 13:46:09 -08:00
Aaron Patterson 3077cdf921
rename push / pop function 2019-02-19 13:46:09 -08:00
Aaron Patterson ff6b713f5e
Merge pull request #35293 from rails/remove-rendered-format-from-cache
Pass the template format to the digestor
2019-02-19 13:45:30 -08:00
Eli Rose 07804d4759 Add handling and tests. 2019-02-17 23:07:16 -05:00
Aaron Patterson df12a1b241
remove another call to rendered_format= 2019-02-17 17:43:39 -08:00
Aaron Patterson fdc05952bd
Merge pull request #35281 from y-yagi/show_deprecated_message_instead_of_raise_exception
Show deprecated message instead of raise exception in `compiled_method_container` method
2019-02-15 22:33:30 -08:00
yuuji.yaginuma 7878027ca7 Show deprecated message instead of raise exception in `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.
2019-02-16 13:00:28 +09:00
Aaron Patterson 1581cab9ff
Pass the template format to the digestor
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.
2019-02-15 17:27:33 -08:00
yuuji.yaginuma 96937335d1 Allow to pass options to `csp_meta_tag`
Currently `csp_meta_tag` generates `name` attribute only.
However, in libraries like `Material-UI` and `JSS`, expect that the meta tag
that contains the nonce with `property` attribute.

https://material-ui.com/css-in-js/advanced/#how-does-one-implement-csp
https://github.com/cssinjs/jss/blob/master/docs/csp.md

This patch allows `csp_meta_tag` to specify arbitrary options and
allows `nonce` to be passed to those libraries.
2019-02-16 09:36:37 +09:00
yuuji.yaginuma 3f186e3045 Add test for `csp_meta_tag` 2019-02-14 13:51:18 +09:00
Aaron Patterson af6ade0cfd
Merge pull request #35253 from rails/cached-collections-must-have-a-template
Cached collections only work if there is one template
2019-02-13 11:21:57 -08:00
Aaron Patterson bfcdd46614
Cached collections only work if there is one template
Cached collections only work if there is one template.  If there are
more than one templates, the caching mechanism doesn't have a key.
2019-02-13 10:35:28 -08:00