Commit Graph

2854 Commits

Author SHA1 Message Date
Rafael Mendonça França 5c1bd20f0d
Merge pull request #44693 from ghousemohamed/fix-docs-related-gem-versions
Fix `#version` method docs and some typos [ci-skip]
2022-03-15 16:28:07 -04:00
Ghouse Mohamed 6ee6cb554b Fix #version docs and some typos 2022-03-16 01:48:37 +05:30
Aaron Patterson 8961b8ece7
Merge pull request #44669 from kaiquekandykoga/extract-float
Extract float
2022-03-14 15:16:06 -07:00
Kaíque Kandy Koga 16e6d77200 Extract float numbers when using size option
for image_tag and video_tag

Delete space

format_numbers number_formats

Add tests

Change tests

Use regex in extract_dimensations
2022-03-14 14:11:07 -03:00
Aaron Patterson d28efa55fa
Merge pull request #43975 from codergeek121/bugfix-for-time-select-prompt
Fix a bug with time_select and prompts
2022-03-14 09:44:42 -07:00
Matheus Richard 414394206a Extend audio_tag and video_tag to accept Active Storage attachments.
Now it's possible to write

    audio_tag(user.audio_file)
    video_tag(user.video_file)

Instead of

    audio_tag(polymorphic_path(user.audio_file))
    video_tag(polymorphic_path(user.video_file))

image_tag already supported that, so this follows the same pattern.
2022-03-14 02:05:37 -03:00
Jean Boussier 13dd6f93c8
Merge pull request #44585 from davekaro/remove_circle_void_element
Remove circle from HTML_VOID_ELEMENTS set.
2022-03-02 20:26:45 +01:00
Jean Boussier 2fd34270eb Eager load controllers `view_context_class`
These classes are relatively small, however they include lots of
modules as helpers. And if any of the included module hold constants
including it cause the global constant cache to be invalidated
which is really bad for performance.

So when eager loading is enabled we create all the possible classes
as part of the application boot.
2022-03-02 08:47:54 +01:00
Dave Kroondyk 8d51706c20 Remove circle from HTML_VOID_ELEMENTS set.
`<circle>` is in the SVG_SELF_CLOSING_ELEMENTS list and is not a void element according to
'https://html.spec.whatwg.org/multipage/syntax.html#void-elements'.
2022-03-01 09:08:23 -05:00
Dave Kroondyk 3814826885 Ensure SVG elements are closed.
Changes introduced in https://github.com/rails/rails/pull/43232 break SVGs
that have mulitple of the same descendant tag because they weren't being
closed. SVG elements must be closed accodoring to spec
https://html.spec.whatwg.org/multipage/syntax.html#elements-2.

Fixes https://github.com/rails/rails/issues/44563
2022-02-28 17:52:02 -05:00
Rafael Mendonça França 201aecb260
Merge pull request #44555 from koic/enable_style_map_to_hash_cop
Enable `Style/MapToHash` cop
2022-02-25 15:23:50 -05:00
Rafael Mendonça França b64cbc0b27
Merge pull request #44529 from Shopify/actionview-fix-flaky-tests
Fix flaky Action View tests
2022-02-25 14:47:49 -05:00
Koichi ITO 819871cc4e Enable `Style/MapToHash` cop
Ruby 2.6 added block argument processing to `Enumerable#to_h`.
https://bugs.ruby-lang.org/issues/15143

Rails 7 requires Ruby 2.7.0 or higher, so the new feature can use it.
`Style/MapToHash` cop will detect it. And this cop in the `Style` department,
but this seems to improve performance as follows:

```ruby
# map_to_hash.rb
require 'benchmark/ips'

ARRAY = (1..100).to_a
HASH = {foo: 1, bar: 2}

Benchmark.ips do |x|
  x.report('array.map.to_h') { ARRAY.map { |v| [v, v * 2] }.to_h }
  x.report('array.to_h')     { ARRAY.to_h { |v| [v, v * 2] } }

  x.compare!
end

Benchmark.ips do |x|
  x.report('hash.map.to_h') { HASH.map { |k, v| [k.to_s, v * 2] }.to_h }
  x.report('hash.to_h')     { HASH.to_h { |k, v| [k.to_s, v * 2] } }

  x.compare!
end
```

```console
% ruby map_to_hash.rb
Warming up --------------------------------------
      array.map.to_h     9.063k i/100ms
          array.to_h     9.609k i/100ms
Calculating -------------------------------------
      array.map.to_h     89.063k (± 3.9%) i/s -    453.150k in  5.096572s
          array.to_h     96.449k (± 1.7%) i/s -    490.059k in  5.082529s

Comparison:
          array.to_h:    96448.7 i/s
      array.map.to_h:    89063.4 i/s - 1.08x  (± 0.00) slower

Warming up --------------------------------------
       hash.map.to_h   106.284k i/100ms
           hash.to_h   149.354k i/100ms
Calculating -------------------------------------
       hash.map.to_h      1.102M (± 2.2%) i/s -      5.527M in   5.019657s
           hash.to_h      1.490M (± 0.9%) i/s -      7.468M in   5.013264s

Comparison:
           hash.to_h:  1489707.0 i/s
       hash.map.to_h:  1101561.5 i/s - 1.35x  (± 0.00) slower
```

`Style/MapToHash` cop ... https://docs.rubocop.org/rubocop/1.25/cops_style.html#stylemaptohash
2022-02-26 04:31:03 +09:00
Clayton Smith 6e56e18523 Fix flaky Action View tests 2022-02-23 09:39:57 -05:00
Jonathan Hefner a199aaedb8 Cross-link API docs [ci-skip]
RDoc will automatically format and link API references as long as they
are not already marked up as inline code.

This commit removes markup from various API references so that those
references will link to the relevant API docs.
2022-02-21 11:45:25 -06:00
Jonathan Hefner 9dbf7a58a2 Fix formatting of parameters doc [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner a801aa7cde Mark up inline code [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner e37adfed4e Add Oxford commas [ci-skip] 2022-02-21 11:11:11 -06:00
Jonathan Hefner 07bee949c4 Replace backticks with RDoc markup [ci-skip]
RDoc does not support backticks the way that Markdown does.  Instead,
inline code must be wrapped with `+` or `<tt>`.
2022-02-21 11:11:11 -06:00
Jonathan Hefner 0d3effc97e Replace "overwrite" with "override" [ci-skip]
"Overwrite" means "destructively replace", and is more suitable when,
for example, talking about writing data to a location.

"Override" means "supersede", and is more suitable when, for example,
talking about redifining methods in a subclass.
2022-02-21 11:11:11 -06:00
Jonathan Hefner 5fdbd217d1 Fix typos [ci-skip] 2022-02-21 11:11:11 -06:00
Jean Boussier e26372b713 Implicitly assert no exception is raised in `assert_queries` & al
Fix: https://github.com/rails/rails/pull/44397
Ref: https://github.com/rails/rails/pull/37313
Ref: https://github.com/rails/rails/pull/42459

This avoid mistakes such as:

```ruby
assert_raise Something do
  assert_queries(1) do
    raise Something
  end
end
```

Co-Authored-By: Alex Coomans <alexc@squareup.com>
2022-02-19 09:11:14 +01:00
Sean Doyle 9dc083f95d `form_for`: Attempt to call `to_model` on record
Related to https://github.com/rails/rails/issues/44326

---

The changes introduced in [rails/rails#43421][] did not account for
attempting to coerce the record with [#to_model][]. This commit resolves
that issue and adds test coverage to guard against future regressions.

Additionally, this adds tests to exercise `form_with` to ensure that it
_does not_ call `#to_model` on its `model:` argument, since that was the
behavior in [6.1.4.4][]

[rails/rails#43421]: https://github.com/rails/rails/pull/43421
[#to_model]: https://edgeapi.rubyonrails.org/classes/ActiveModel/Conversion.html#method-i-to_model
[6.1.4.4]: https://github.com/rails/rails/issues/44326#issuecomment-1029344241
2022-02-17 16:01:57 -05:00
John Hawthorn 3e2f9a66db
Merge pull request #43390 from jhawthorn/remove_notification_event_children
Remove child event tracking from ActiveSupport::Subscriber
2022-02-17 08:45:48 -08:00
John Hawthorn 139ef8a0bc
Merge pull request #44174 from jguecaimburu/add_lowdash_support_to_path_parser_locale_regex
Add support to locales with lowdash in Resolver::PathParser
2022-02-17 08:27:34 -08:00
John Hawthorn 9c58a54702 Split actionview log subscriber Start events
Previously one subscriber was used for both the "Rendering" (before) and
"Rendered" (after) events. With the previous change to AS::Subscriber
these need to be split.

Co-authored-by: Adam Hess <HParker@github.com>
2022-02-17 08:20:01 -08:00
Rafael Mendonça França b961af3345
Merge pull request #44093 from motine/doc-hint-for-fields_for
add hint to ActionView's fields_for
2022-02-09 20:17:01 -05:00
Ryuta Kamizono 135f41d0b0
Merge pull request #44337 from paulhenri-l/patch-1
Fix empty request inside helpers test
2022-02-09 17:33:40 +09:00
Paul-Henri Leobon 867e60f6c2
Fix empty request inside helpers test
During testing view helpers do not have access to the `request` object but they do when used inside of a view.

If we were to test a helper like this one :

```ruby
  def active?(test_path)
    request.path.match? test_path
  end
```

we would get this error : 

```
NoMethodError: undefined method `path' for nil:NilClass
```

Adding `:request` to the attr_accessor will make tests consistent with the default behavior.
2022-02-09 08:47:27 +01:00
Tom Rothe c6cb78349a add hint to ActionView's fields_for 2022-02-08 22:09:08 +01:00
David Heinemeier Hansson 41478f7074 Make #to_fs the default replacement for #to_s(:format)
#to_formatted_s is too cumbersome.
2022-02-07 12:41:21 +01:00
Jonathan Hefner 9648e89511 Fix test_tag_attributes_escapes_values assertion
The 1st argument to `assert_not_includes` is the collection to search;
the 2nd argument is the element to search for.  Thus this test was
checking if the output was included in the forbidden string, rather than
checking the if the forbidden string was included in the output.

Because negative assertions like this one can be fooled more easily,
this commit changes the test to use `assert_equal`, as the other tests
do.
2022-01-29 12:10:14 -06:00
Gannon McGibbon aaa64687e8
Revert #38957 (#44287)
* Revert "Pass service_name param to DirectUploadsController"

This reverts commit 193289dbbe.

* Revert "Multi-service direct uploads in Action Text attachment uploads"

This reverts commit 0b69ad4de6.
2022-01-29 14:27:45 +01:00
Yasuo Honda d6f96a9d7c Address ActionView::Template::Error
This commit addresses the following CI error.
https://buildkite.com/rails/rails/builds/84207#3bc8eb7f-c86d-4f6f-8932-e2e8c26cf893

There were similar pull requests #36189 #39949

```ruby
$ bin/test test/template/test_case_test.rb test/template/render_test.rb -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598
Run options: -n "/^(?:ActionView::HelperInclusionTest#(?:test_helper_class_that_is_being_tested_is_always_included_in_view_instance)|FrozenStringLiteralEnabledViewRenderTest#(?:test_render_partial_collection_for_non_array))$/" --seed 41598

.E

Error:
FrozenStringLiteralEnabledViewRenderTest#test_render_partial_collection_for_non_array:
ActionView::Template::Error: undefined method `__home_yahonda_src_github_com_rails_rails_actionview_test_fixtures_test__customer_erb__1256308179417979847_7880' for #<ActionView::Base:0x00000000003de0>
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `public_send'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:244:in `_run'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:157:in `block in render'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:208:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:361:in `instrument_render_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/template.rb:155:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:189:in `block in collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `block in each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `yield'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:385:in `block in test_render_partial_collection_for_non_array'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:70:in `each_with_info'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `each'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `map'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:180:in `collection_with_template'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:162:in `block (2 levels) in render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb:21:in `cache_collection_render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:161:in `block in render_collection'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `block in instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
    /home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/notifications.rb:206:in `instrument'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:147:in `render_collection'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/collection_renderer.rb:119:in `render_collection_with_partial'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:72:in `render_partial_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:27:in `render_to_object'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/renderer/renderer.rb:22:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:38:in `block in render'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/base.rb:270:in `in_rendering_context'
    /home/yahonda/src/github.com/rails/rails/actionview/lib/action_view/helpers/rendering_helper.rb:34:in `render'
    /home/yahonda/src/github.com/rails/rails/actionview/test/template/render_test.rb:388:in `test_render_partial_collection_for_non_array'

bin/test test/template/render_test.rb:383

Finished in 0.047002s, 42.5514 runs/s, 63.8271 assertions/s.
2 runs, 3 assertions, 0 failures, 1 errors, 0 skips
$
```
2022-01-27 16:36:27 +09:00
Shunichi Ikegami a692bb628c Fix typos and remove unused options in DateTimeSelector 2022-01-25 09:51:52 +09:00
Alex Ghiculescu 85b533308f
Document that @rails/ujs is deprecated for `button_to` (#44100)
* Document that @rails/ujs is deprecated for `button_to`

This was missed in https://github.com/rails/rails/pull/43112

* deprecation needs to go below the examples
2022-01-20 12:23:37 +01:00
Rafael Mendonça França c777afb242
Merge pull request #44198 from ElMassimo/preload-modules
Ensure preload_link_tag preloads modules correctly
2022-01-19 21:12:26 -05:00
Rafael Mendonça França b1ac36e305
Remove duplicated response check 2022-01-20 02:10:49 +00:00
Rafael Mendonça França f708b9f6f0
Merge pull request #44190 from dark-panda/7-0-stable-fix-asset-helpers-for-view-components
Use the safe navigation operator on response.sending?
2022-01-20 02:08:02 +00:00
Maximo Mussini dd870eef11 Ensure preload_link_tag preloads modules correctly
Prior to this change, preload_link_tag always used rel=preload

This causes the browser to make a request to preload the script, but
for modules scripts the rel does not match the type, so the browser
can not reuse the prefetched script and discards it.

When passing type="module", it should use rel=modulepreload instead.

[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
[3] developers.google.com/web/updates/2017/12/modulepreload
2022-01-18 18:00:04 -03:00
Juan Guecaimburu bd0753b396 Add support to locales with lowdash in Resolver::PathParser
In previous versions of Rails, a dynamic regex was built to find templates.
After that, PathParser started to be used to both match and sort templates.
With the dynamic regex, templates with lowdash locales (es_AR) were
found properly. But the PathParser regex does not match locales with this
format, only allowing dash (es-AR) or no dash (es). Templates with lowdash
locales have a wrong virtual path and get filtered.

In this commit the PathParser regex is extended to support the lowdash.
2022-01-14 15:11:58 -03:00
Nick Rivadeneira e9c09c4b73
Fix documentation comments for form_tag
The comment break caused a break in documentation
2022-01-11 06:25:40 -05:00
John Hawthorn 94643fde8f Reuse view_context_class when possible
The generated view context classes tend to be fairly complex and use a
lot of memory. Similar to how we only generate new helper classes when
necessary (see https://github.com/rails/rails/pull/40204) we should be
doing the same for view context classes.
2022-01-06 10:23:59 -08:00
Rafael Mendonça França af4d9def81
Fix documentation output to remove escaping 2022-01-05 20:50:52 +00:00
Ryuta Kamizono 65766ebcc8 Bump license years to 2022 [ci-skip] 2022-01-01 15:22:15 +09:00
soartec-lab c478b163c6 Fix example codes. The default autocomplete specification is `off` for helpers that build hidden type input tags. [skip ci] 2021-12-25 11:42:00 +09:00
Niklas Haeusele 46e2901f12 Fix a bug with time_select and prompts
Rendering a time_select like suggested here actionview/lib/action_view/helpers/date_helper.rb:317
does not actually show the default prompt but a prompt with textcontent "true".
Now it actually renders the default prompt in this case, like suggested
in the documentation.
2021-12-23 18:27:45 +01:00
Rafael Mendonça França d7e07ea255
Fix #43918 2021-12-20 23:09:14 +00:00
Rafael Mendonça França dfd28646fe
Merge PR #43157
Add test for #43157

    fix test

    fix #43146

Co-Authered-By: qinmingyuan <mingyuan0715@foxmail.com>
2021-12-20 23:01:53 +00:00
Alex Ghiculescu da7ff04c69 Fix `link_to` with a model passed as an argument twice
Fixes https://github.com/rails/rails/issues/43913 which found a regression in https://github.com/rails/rails/pull/42234
2021-12-17 12:24:25 -06:00