Commit Graph

2992 Commits

Author SHA1 Message Date
Jonathan Hefner
cfe300ceb1 Format inline code [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Lachlan Sylvester
143472b944 restore coment from the old index.html about overwriting the link selector 2023-01-04 00:46:36 +11:00
Lachlan Sylvester
b39f06b226 move attach-bindings out of test as it doesn't contain test cases 2023-01-04 00:36:57 +11:00
Lachlan Sylvester
28b7a84b69 add comments to explain the test rollup and karma config files 2023-01-04 00:08:47 +11:00
Lachlan Sylvester
fbb5f5b4b6 Formatting
Co-authored-by: Michael Adams <github@michaeladams.org>
2022-12-31 23:03:09 +11:00
Lachlan Sylvester
b1bc3a0b20 add explaination of extracting from the ENCODED env var 2022-12-31 23:03:09 +11:00
Lachlan Sylvester
2f42c5810a Use explicit argument lists when spawning the server and tests.
Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2022-12-31 23:03:09 +11:00
Lachlan Sylvester
d9e79ce7f4 use Karma as the test runner for the UJS tests 2022-12-31 23:03:09 +11:00
Akira Matsuda
974de71036
Merge pull request #46763 from jdufresne/trimws
Trim trailing whitespace from *.md files
2022-12-18 12:22:50 +09:00
Akira Matsuda
45dd422901
Let initialize not create an Array as its return value 2022-12-18 12:11:34 +09:00
Jon Dufresne
aa81f67a9e Trim trailing whitespace from *.md files
Fixes the error:

    Run bin/check-changelogs ./rails
    ............F

    Offenses:

    ./rails/railties/CHANGELOG.md:4 Trailing whitespace detected.
2022-12-17 15:27:51 -08:00
Akira Matsuda
6576eec6a8
Create an Array for the error message only when invalid value exists 2022-12-17 17:13:17 +09:00
Akira Matsuda
d8c05043c3
Avoid creating new Array object per each comparison
Benchmark.ips do |x|
  arr = [:js]

  x.report('==') { arr == [:js] }
  x.report('length') { (arr.length == 0) && (arr[0] == :js) }
  x.report('one?') { arr.one? && (arr[0] == :js) }

  x.compare!
end

Warming up --------------------------------------
                  ==   731.426k i/100ms
              length     1.967M i/100ms
                one?     1.440M i/100ms
Calculating -------------------------------------
                  ==      7.291M (± 0.8%) i/s -     36.571M in   5.016130s
              length     19.633M (± 0.8%) i/s -     98.356M in   5.010104s
                one?     14.387M (± 0.8%) i/s -     71.998M in   5.004721s

Comparison:
              length: 19632843.5 i/s
                one?: 14386784.0 i/s - 1.36x  (± 0.00) slower
                  ==:  7291274.5 i/s - 2.69x  (± 0.00) slower
2022-12-15 11:55:03 +09:00
eileencodes
bd7b6decb9
Fix typo in new docs from #46730 2022-12-14 16:17:55 -05:00
eileencodes
171fea857d
Improve docs for strict_locals! [ci-skip]
The docs didn't say much about what strict locals are or why you would
use them. This adds docs on usage and what the functionality does.
2022-12-14 15:13:40 -05:00
eileencodes
334fa122b7
Refactor compiled_source
This is a continuation of #46706 to make sure we don't need to set an
instance variable to `@original_source` for the `compile` method to use.

We can't call `strict_locals!` after encode so we need to set it to a
local variable in `complile`. We changed the `strict_locals!` method to
check `NONE` instead of lazily defining instance variables which let us
simplify `strict_locals?` to return the value of `strict_locals!`. This
simplifies and clarifies the code.

Co-authored-by: Aaron Patterson tenderlove@ruby-lang.org
2022-12-14 14:12:25 -05:00
Alex Ghiculescu
49c2e51808 Allow f.select to be called with a single hash containing options and HTML options
I do this a lot:

```erb
<%= select :post, :author, authors, required: true %>
```

It doesn't work; the `required` attribute is ignored! Instead, you need to do this:

```erb
<%= select :post, :author, authors, {}, required: true %>
```

It's hard to remember the right API, and it looks to me like a code smell. It looks even smellier when you end up with this:

```erb
<%= select :post, :author, authors, { include_blank: "Choose an option" }, { required: true } %>
```

Where this would be nicer, but again, the `required` attribute is ignored:

```erb
<%= select :post, :author, authors, include_blank: "Choose an option", required: true %>
```

This PR implements a special handling for `required`, `multiple`, and `size` HTML attributes so that these now do the same thing:

```erb
<%= select :post, :author, authors, include_blank: "Choose an option", required: true %>
<%= select :post, :author, authors, { include_blank: "Choose an option" }, { required: true } %>
```

ps. as proof I'm not the only person who makes this mistake, one of the tests in the Rails test suite was wrong! The test added in https://github.com/rails/rails/pull/40522 puts the `multiple` attribute in the wrong place and has the wrong assertion as as result. This PR includes a fix for the test.
2022-12-13 11:44:34 -06:00
eileencodes
5026abaeb1
Refactor compiled source code into method
Moves the part of `compile!` that compiles the template source into it's
own method. We need this for future work in improving exceptions for ERB
templates to pass to ErrorHighlight.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2022-12-12 15:31:19 -05:00
Andrey Samsonov
c20b629f52 Fix inconsistent behavior in form helper date/time tags with options; issue #46677
This change makes date/time options (value, min, max) in `time_field`, `date_field`, `datetime_field`, `week_field`, `month_field` form helpers behave in a unified way.
2022-12-11 17:19:18 +01:00
Hartley McGuire
a07f2ace03
Fix lots of code highlighting issues
The most common is replacing back-ticks with either pluses or tt tags.
There were also a few instances of code blocks not being indented.
2022-11-29 00:51:02 -05:00
Étienne Barrié
3d6a7b2faa Initialize deprecators before configuring them
Since engine initializers run later in the process, we need to run this
initializer earlier than the default.

This ensures they're all registered before the environments are loaded.
2022-11-28 10:47:26 +01:00
Jonathan Hefner
1e68400930 Prefer deprecate_constant over constant proxy
`deprecate_constant` will warn whenever the constant is referenced
instead of when the constant is a method receiver, which increases the
likelihood that the warning will be seen.  Additionally,
`DeprecatedConstantProxy` prevents using the constant as a superclass,
such as in `class MyClass < SomeDeprecatedConstant`.
2022-11-25 11:25:03 -06:00
Rafael Mendonça França
db5a6ef624
Merge PR #43019 2022-11-23 19:14:33 +00:00
Mathieu Le Tiec
bab93a0570 Add FormBuilder#fields tests 2022-11-22 20:59:43 +01:00
Mathieu Le Tiec
a625e20825 Allow hash-like record_object in FormBuilder#fields_for 2022-11-22 20:03:43 +01:00
Rafael Mendonça França
a8efccc32e
Merge pull request #46531 from p8/guides/fix-capitalization-of-AJAX
Rename AJAX to Ajax for consistency [ci-skip]
2022-11-21 17:24:09 -05:00
Maciej Mensfeld
9a77b0fe28
Make sure that concurrent map usage is thread-safe
Behavior upon missing prefix partial name may cause a key to overwrite when executed in multiple threads at the same time.

ref https://github.com/ruby-concurrency/concurrent-ruby/issues/970
2022-11-20 20:50:06 +01:00
Petrik
93c51f92fd Rename AJAX to Ajax for consistency [ci-skip]
Currently we use both `AJAX` (11 times) and `Ajax` (22 times).
Wikipedia uses `Ajax`: https://en.wikipedia.org/wiki/Ajax_(programming)
Mozilla uses `Ajax`: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX

As `Ajax` is currently used the most and it's preferred by Wikipedia and
Mozilla, we can change all it's occurences to `Ajax`.
2022-11-20 11:17:44 +01:00
Petrik
482d94c139 Use 2 spaces for identation in ActionView code examples [ci-skip]
For consistency use 2 spaces for indentation (+ 1 default space after `#`)
Some of these were formatted incorrectly in the API docs.
2022-11-16 23:08:07 +01:00
Jonathan Hefner
ee8d9497dd Auto-link code references [ci-skip] 2022-11-15 13:57:15 -06:00
Jonathan Hefner
9588f780dc Format inline code [ci-skip] 2022-11-15 13:57:15 -06:00
Jonathan Hefner
b5248aca16 Add ActionView.deprecator
This commit adds `ActionView.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionview/lib` with
`ActionView.deprecator`.  This commit also replaces a call to Ruby's
`Module#deprecate_constant` with Rails' `DeprecatedConstantProxy`, so
that its deprecation behavior can be configured using
`ActionView.deprecator`.

Additionally, this commit adds `ActionView.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.

This commit also removes a few defunct `assert_deprecated` calls that
were not failing because they were nested in `assert_raises`, and the
raised error prevented checking the deprecation.  (One was mistakenly
kept in d52d7739468153bd6cb7c629f60bd5cd7ebea3eb when converting
`test_render_file_with_errors` to `test_render_template_with_errors`;
the other two were added in dd9991bac598bb5da312278a749cf85e19b027cc but
not removed when the deprecation was completed in
85ecf6e4098601222b604f7c1cbdcb4e49a6d1f0.)
2022-10-30 16:01:39 -05:00
Jonathan Hefner
48d4e6e02b Add ActionDispatch.deprecator
This commit adds `ActionDispatch.deprecator` and replaces all usages of
`ActiveSupport::Deprecation.warn` in `actionpack/lib/action_dispatch`
with `ActionDispatch.deprecator`.

Additionally, this commit adds `ActionDispatch.deprecator` to
`Rails.application.deprecators` so that it can be configured via
settings such as `config.active_support.report_deprecations`.
2022-10-27 17:11:02 -05:00
Alex Ghiculescu
4fcac154f4 Support checked as a keyword argument in check_box_tag and radio_button_tag
Currently if you do this:

```ruby
check_box_tag "admin", "1", checked: false
```

It is treated [as truthy](19f9922523/actionview/lib/action_view/helpers/form_tag_helper.rb (L444)), and your checkbox is checked. This can be a bit surprising, particularly because the `FormHelper` version [does support](19f9922523/actionview/lib/action_view/helpers/form_helper.rb (L1285)) a keyword argument.

```ruby
f.check_box "admin", checked: false
```

So this PR updates `check_box_tag` and `radio_button_tag` to support `checked` as a positional or keyword argument, this way you can use the same API in both cases.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-10-21 12:41:29 -05:00
Jean Boussier
05919b0802 Fix Action View compatibility with jbuilder
jbuilder is doing some weird things such as instantiatign RenderedTemplate
with a `Hash` instance as a `body`.

So we can't forcibly cast to string in these places.
2022-10-21 13:15:53 +02:00
Aaron Patterson
2f36f0a2bb
Merge pull request #46171 from rails/refactor-errors
Add column information inside ERB templates
2022-10-11 15:10:40 -07:00
Jean Boussier
d917896f45 Enable verbose mode in test and report warnings as errors
We recently let a few very easy to avoid warnings get merged.
The root cause is that locally the test suite doesn't run in
verbose mode unless you explictly pass `-w`.

On CI warnings are enabled, but there is no reason to look at the
build output unless something is failing. And even if one wanted
to do that, that would be particularly work intensive since warnings
may be specific to a Ruby version etc.

Because of this I believe we should:

  - Always run the test suite with warnings enabled.
  - Raise an error if a warning is unexpected.

We've been using this pattern for a long time at Shopify both in private
and public repositories.
2022-10-11 09:25:18 +02:00
Aaron Patterson
3deffa9974
Remove unused constant 2022-10-09 16:36:11 -07:00
Aaron Patterson
9f5dee3a91
move ERB monkey patches to their own file 2022-10-09 16:12:37 -07:00
Aaron Patterson
a7238cbfa4
rubocop 2022-10-09 15:54:42 -07:00
Aaron Patterson
0c55a87ccf
Stop using a global for storing template info
This isn't as easy, but should eliminate any memory leaks in dev
2022-10-09 15:51:23 -07:00
Aaron Patterson
aa37b787ef
Use file path as the error lookup key
We have access to the path from the backtrace location object.  If we
use the path of the ERB as the key, then anytime the ERB changes it'll
just overwrite that template instance in the error handling hash
2022-10-09 14:55:50 -07:00
Aaron Patterson
cd48642561
Add tests that column information can be translated 2022-10-09 14:52:17 -07:00
Aaron Patterson
1d39573a9f
Move ERB parsing to core_ext 2022-10-09 14:52:17 -07:00
Aaron Patterson
a23fef384c
Don't use pattern matching because it's causing warnings 2022-10-09 14:52:17 -07:00
Aaron Patterson
f6e20abd27
rubocop 2022-10-09 14:52:17 -07:00
Aaron Patterson
650e99ac5b
Map column information in to ERB templates
This commit maps the column information returned from ErrorHighlight in
to column information within the source ERB template.  ErrorHighlight
only understands the compiled Ruby code, so this commit adds a small
translation layer that converts the values from ErrorHighlight in to the
right values for the ERB source template
2022-10-09 14:52:17 -07:00
Aaron Patterson
343dba47e0
Only deal with backtrace locations in ExceptionWrapper
We should get out of the business of parsing backtraces and only use
backtrace locations.  Backtrace locations have the file and line number
information baked in, so we don't need to parse things anymore
2022-10-09 14:52:17 -07:00
Aaron Patterson
80a698d15c
Use a SyntaxError proxy object when displaying syntax error info
This commit adds a SyntaxErrorProxy object to active support and wraps
syntax error exceptions with that proxy object.  We want to enhance
syntax errors with information about the source location where they
actually happened (normally the backtrace doesn't contain such info).
Rather than mutating the original exception's backtrace, this wraps it
with a proxy object.

Eventually we will implement backtrace_locations on the proxy object so
that the exception handling middleware can be updated to _only_ deal
with backtrace_locations and never deal with raw `backtrace`
2022-10-09 14:52:17 -07:00