Commit Graph

2310 Commits

Author SHA1 Message Date
Rafael França
9c6bdb54a3
Merge pull request #34809 from bogdanvlviv/fix-select-with-nil
`ActionView::Helpers::FormOptionsHelper#select` should mark option for `nil` as selected
2019-09-19 15:45:40 -04:00
Akira Matsuda
9bce8c3c02 form_authenticity_token takes keyword arguments 2019-09-15 03:05:52 +09:00
Akira Matsuda
fb6d5e0473 Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-14 08:53:04 +09:00
glacials
c2cadd2f6d
Fix a button_to documentation example
Fixes an example in `button_to`'s documentation; the description states
`button_to` only takes a symbol for the `method` argument, but an
example just below uses a string.

Passing an all-lowercase string incidentally works, so the example is
technically functional despite being undefined behavior. But passing an
all-uppercase string fails, and this is a pretty common practice when
specifying HTTP methods (e.g. `DELETE`), so I think it's best this
example is put in line with the documentation and converted to use
symbols.

I fell for it myself and tried to pass an all-uppercase string after
seeing the example without reading the options descriptions.

Reproduction steps:

```sh
rails new buttonto
cd buttonto
rails c
> def protect_against_forgery?
>   false
> end
=> :protect_against_forgery?
>  button_to('Destroy', 'http://www.example.com', method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' })
=> "<form class=\"button_to\" method=\"post\" action=\"http://www.example.com\" data-remote=\"true\"><input type=\"hidden\" name=\"_method\" value=\"delete\" /><input data-confirm=\"Are you sure?\" data-disable-with=\"loading...\" type=\"submit\" value=\"Destroy\" /></form>"
>  button_to('Destroy', 'http://www.example.com', method: "DELETE", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' })
=> "<form class=\"button_to\" method=\"post\" action=\"http://www.example.com\" data-remote=\"true\"><input data-confirm=\"Are you sure?\" data-disable-with=\"loading...\" type=\"submit\" value=\"Destroy\" /></form>"
```
2019-09-12 18:46:40 -07:00
John Hawthorn
2f44c3b00b
Merge pull request #37119 from jonathanhefner/fix-escaping-in-view-path-resolver
Fix escaping in OptimizedFileSystemResolver
2019-09-10 17:36:22 -07:00
Jonathan Hefner
897cdc721e Fix escaping in OptimizedFileSystemResolver
`OptimizedFileSystemResolver` builds a regular expression to match view
template paths.  Prior to this patch, only file globbing special
characters were escaped when building this regular expression, leaving
other regular expression special characters unescaped.

This patch properly escapes all regular expression special characters,
and adds test coverage for paths that include these characters.

Fixes #37107.
2019-09-09 12:20:02 -05:00
Akira Matsuda
7a563f749d Fix Class#new + keyword arguments warnings 2019-09-09 02:35:59 +09:00
bogdanvlviv
cd2cbdcb48
ActionView::Helpers::FormOptionsHelper#select should mark option for nil as selected
```ruby
 @post = Post.new
 @post.category = nil

 # Before
 select("post", "category", none: nil, programming: 1, economics: 2)
 # =>
 # <select name="post[category]" id="post_category">
 #   <option value="">none</option>
 #  <option value="1">programming</option>
 #  <option value="2">economics</option>
 # </select>

 # After
 select("post", "category", none: nil, programming: 1, economics: 2)
 # =>
 # <select name="post[category]" id="post_category">
 #   <option selected="selected" value="">none</option>
 #  <option value="1">programming</option>
 #  <option value="2">economics</option>
 # </select>
 ```

To get the same result without these changes we can set `:selected` as `@post.category.to_s`:
 ```ruby
 select("post", "category", {none: nil, programming: 1, economics: 2}, {selected: @post.category.to_s}
 ```
2019-09-05 21:41:34 +03:00
George Claghorn
3437691708
Merge pull request #37040 from rails/reduce-info-level-logging
Logging at info level should be reserved for top-level concerns
2019-09-05 09:44:20 -04:00
Ryuta Kamizono
0cf609661e Auto-correct rubocop offences 2019-09-05 15:46:58 +09:00
Akira Matsuda
d2f4541f12 Passing in a Hash instance as non-kwargs parameters has to be curly braced now 2019-09-05 13:26:58 +09:00
Akira Matsuda
4071115ddd Passing in a Hash instance as kwargs parameters requires the "double splat" prefix 2019-09-05 13:26:58 +09:00
sinsoku
7b157f1409
Add doc about I18n support for :placeholder option [ci skip]
The :placeholder option accepts true, so it should be mentioned in the documentation.

Ref: https://github.com/rails/rails/pull/16438
2019-08-28 02:25:41 +09:00
David Heinemeier Hansson
6315a11b90 Logging at info level should be reserved for top-level concerns
Information about partials and cable connection notices are too low level.
2019-08-26 16:43:45 -04:00
Akira Matsuda
cade89e034 Reduce Hash creation in FormHelper 2019-08-27 04:07:22 +09:00
Akihito Tsukamoto
0a77c05308 Prevent TagBuilder modify options 2019-08-20 00:13:02 +09:00
Akira Matsuda
88fe8d9e7c Stop reopening ClassMethods and merge definitions 2019-08-19 00:35:23 +09:00
Akira Matsuda
2f71297919 :action is just a string 2019-08-19 00:34:28 +09:00
Akira Matsuda
07c50800fb Reduce Array allocations while finding templates 2019-08-19 00:22:42 +09:00
Will Jessop
fdb6a90794
Remove misleading documentation
The docs for ActionView partial renderer state:

> NOTE: Due to backwards compatibility concerns, the collection can't be one of hashes. Normally you'd also just keep domain objects, like Active Records, in there.

The reporter stated:

> I can render a collection of hashes without problems:
>
> = render :partial => "info_row", :collection => my_collection, :as => :d

I tested this in a Rails 6.0 rc2 app and hashes were passed as described. Fixes #36897. [ci skip]
2019-08-10 02:52:15 +01:00
Kasper Timm Hansen
12001611d6
Require and support rails-html-sanitzer 1.2.0
Rails now requires 1.2.0 because it relies on the safe_list_sanitizer
API exclusively.

Also raise `sanitizer_vendor` API from the dead for
rails-deprecated_sanitizer.

Fixes https://github.com/rails/rails-deprecated_sanitizer/pull/6
2019-08-09 00:07:45 +02:00
Cliff Pruitt
265f97f1c1 Update rails-html-sanitizer to 1.1.0 in actionview.gemspec
Commit 52f0b050e2 replaces `white_list_sanitizer` with `safe_list_sanitizer`. This is a breaking change unless the installed version of `rails-html-sanitizer` is `>= 1.1.0`.

This commit updates the minimum version in `actionview/actionview.gemspec` to `1.1.0`.
2019-08-05 13:20:53 -04:00
Kasper Timm Hansen
064b7f6082
Remove unused require 2019-08-05 04:10:54 +02:00
Juanito Fatas
52f0b050e2
Update sanitizer in ActionView::Helpers::SanitizeHelper
- The sanitizer has been changed to safe_list_sanitizer.
- deprecate white_list_sanitizer
2019-08-05 03:35:35 +02:00
Rafael Mendonça França
92cb55ce19
This test needs integer core ext for time 2019-08-02 01:16:50 -04:00
Rafael Mendonça França
4b4bed83e2
Require integer conversion for this test 2019-08-02 00:49:47 -04:00
Rafael Mendonça França
967beb7229
Revert "MethodCallAssertions is a regular player of the team ActiveSupport::TestCase now"
This reverts commit 98d0f7ebd34b858f12a12dcf37ae54fdbb5cab64.
2019-08-02 00:24:21 -04:00
Rafael Mendonça França
6384933994
Revert "You give jruby_skip & rubinius_skip a good name"
This reverts commit 8d2866bb80fbe81acb04f5b0c44f152f571fb29f.
2019-08-02 00:24:11 -04:00
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