Commit Graph

15915 Commits

Author SHA1 Message Date
Jean Boussier bbc7ec49fb Improve routes source location detection
Followup: https://github.com/rails/rails/pull/50923

Instead of stopping on the first frame that isn't in
Action Dispatch, we should return the first frame that
isn't filtered by the backtrace cleaner.
2024-02-05 16:37:37 +01:00
Nick Dower 22bc976576 Tiny update to callbacks docs [ci skip]
The following was added to the `ActiveJob::Callbacks`,
`ActiveModel::Callbacks` and `AbstractController:Callbacks` docs
in #29072:

> NOTE: Calling the same callback multiple times will overwrite
> previous callback definitions.

The comment refers to "calling" callbacks but seems to be about defining
callbacks, as mentioned in the PR description.

In the ActiveJob and AbstractController docs, I believe this will be
misinterpreted as referring to setting callbacks, which, as far as I can
tell, does not have such a restriction.

In the ActiveModel docs, I believe it would be slightly clearer to
replace "calling" with "defining".
2024-02-02 12:11:30 +01:00
m-nakamura145 930649598f
Add example to modules_for_helpers documentation [ci-skip] 2024-01-20 00:48:59 +09:00
Jonathan Hefner 9c3ffab47c Fix RateLimitingTest assertion for :by option
Follow-up to #50788.

This test wasn't actually asserting that the `:by` option worked.
2024-01-18 18:43:43 -06:00
Eugene Kenny 78fd6b7816 Remove outdated comment in ExceptionsWrapper#show? [ci skip]
Support for `true` and `false` was removed in
ec2c2666c2.
2024-01-18 21:31:32 +00:00
Jean Boussier 4530a56e0f `RateLimiting` Cleanups
Followup: https://github.com/rails/rails/pull/50781

Some small issues I failed to address in the original PR.
2024-01-18 10:11:43 +01:00
Jean Boussier 194ce13228 More AC::RateLimiting documentation fixes 2024-01-17 18:01:22 +01:00
Jean Boussier 10a34b7621 Touch up the AC::RateLimiting documentation 2024-01-17 17:59:49 +01:00
Jean Boussier d839ddb71a Refactor `ActionController::RateLimiting` to use `AS::Cache`
Given that the limiter implementation provided by Kredis is a simple
increment with a limit, all `ActiveSupport::Cache` already provide that
same capability, with a wide range of backing stores, and not just Redis.

This even allow to use SolidCache has a backend if you so desire.

If we feel particularly fancy, we could also accept a more generic
limiter interface to better allow users to swap the implementation
for better algorithms such as leaky-bucket etc.
2024-01-17 15:40:49 +01:00
Eugene Kenny 0656787be6
Merge pull request #50764 from eugeneius/syntax_error_proxy_nil_backtrace_locations
Handle nil backtrace_locations in SyntaxErrorProxy
2024-01-16 14:20:13 +00:00
Jean Boussier 946e46ebcc Modernize method missing implementations
`...` is both simpler an more correct since the keyword argument
separation.
2024-01-16 13:17:45 +01:00
Eugene Kenny 16d1351a93 Handle nil backtrace_locations in SyntaxErrorProxy 2024-01-16 01:05:53 +00:00
Rafael Mendonça França a39332fa45
Remove code duplication and improve message 2024-01-15 22:29:46 +00:00
Hartley McGuire 0821d25d56
Add custom ArgumentError for invalid to: values
Previously, it was theoretically possible to define a route with a
Symbol as a `to:` value (or at least, it would not raise a
`NoMethodError`). However, passing a Symbol broke when `/#/.match?(to)`
was [replaced][1] with `to&.include?("#")` with the assumption that `to`
was always a String.

Instead of restoring the previous error, this commit improves how the
`to:` value is checked so that it raises an `ArgumentError` for any
invalid values. The extra strictness will specifically improve the error
when a Symbol or String that doesn't include a "#" are passed since they
were effectively equivalent to passing a `nil` value, or not specifying
`to:` at all.

[1]: 5726b1d1d7
2024-01-15 22:29:45 +00:00
Jean Boussier 2d6b02bad6
Merge pull request #50632 from skipkayhil/hm-move-chunk-test-to-actionpack
Move Transfer-Encoding chunked test to Action Pack
2024-01-09 14:35:50 +01:00
Rafael Mendonça França 84f773f9d1
Merge pull request #50622 from seanpdoyle/document-render-in-examples
Document rendering `:renderable` and `#render_in`
2024-01-08 16:51:39 -05:00
Rafael Mendonça França b6a0fd8087
Merge pull request #50627 from koya1616/delete-fixed-FIXME
Delete FIXME annotation in dispatch/mapper_test.rb
2024-01-08 12:17:17 -05:00
Dwight Watson e358953660 Add missing & 2024-01-08 16:19:19 +11:00
Jonathan Hefner 3bbf21c343 Use verb form of "fallback"
"Fallback" is a noun, whereas "fall back" is a verb.
2024-01-07 17:27:23 -06:00
Jonathan Hefner ff9b62417f Prepend `$` to example CLI commands [ci-skip]
This allows the syntax highlighter to recognize the code as CLI commands.
2024-01-07 17:27:23 -06:00
Hartley McGuire a03a854193
Move Transfer-Encoding chunked test to Action Pack
While working on [another PR][1], I found that removing the
Transfer-Encoding conditionals did not result in any failing tests in
Action Pack. This was surprising to me until I found that there was a
test for this behavior in Railties. However, nothing about the test
really depends on having a full Rails application or the Railties test
suite.

This commit moves the test into Action Pack to simplify/speedup the test
(no need to build a full app) as well as keeping the test closer to the
actual behavior being tested.

[1]: 0c334b48fdc5d70b0c8406ba184fbfd26750b049
2024-01-07 14:33:25 -05:00
Hartley McGuire 580e1d621a
Fix links to master branches renamed to main
We recently had [two][1] [PRs][2] to update these types of links, so
this commit does all of the rest (remaining links to master branches
were checked and still exist).

[1]: e76c52a939
[2]: a2ed3437e3
2024-01-07 12:35:46 -05:00
koya1616 6fe2221225 Delete FIXME annotation in dispatch/mapper_test.rb
Delete `FIXME` in `actionpack/test/dispatch/mapper_test.rb` because it's fixed.
2024-01-07 21:43:41 +09:00
Sean Doyle 4117583e4b Document rendering `:renderable` and `#render_in`
Provide examples for rendering objects that respond to `render_in`. Also
highlight that the object can also define a `#format` method to control
how the rendered String should be treated.

Add test coverage for both Action View's and Action Pack's support for
`render` with `:renderable` options.
2024-01-06 17:57:02 -05:00
Jean Boussier 27140247c2 Cleanup `defined?` usage
Now that we dropped support for Ruby 2.7, we no longer
need to check if variables are defined before accessing them
to avoid the undefined variable warning.
2024-01-05 15:05:35 +01:00
Jean Boussier ef65e5fb32 Cleanup usage of ruby2_keywords
Now that we no longer support Ruby 2.7, many `ruby2_keyword` calls
can be eliminated.

The ones that are left could be eliminated but would end up substantially
slower or more compliacated so I left them for now.
2024-01-05 14:40:18 +01:00
Rafael Mendonça França 8b4e92f4be
Point rubocop to ruby 3.1 2024-01-03 19:02:32 +00:00
Rafael Mendonça França 9d18dc8505
Remove all code to work with Ruby < 3.1 2024-01-03 19:02:31 +00:00
Petrik de Heus 1ea796d6a8
Merge pull request #50523 from bparanj/correct-usage-of-named-routes
Document correct usage of named routes [skip ci]
2024-01-03 08:16:09 +01:00
Bala Paranj 74ad7356e2 Document correct usage of named routes [skip ci] 2024-01-02 21:27:54 -05:00
Hartley McGuire 90da071bb6
bundle update rubocop --conservative (#50515)
Also perform two autocorrects with `bundle exec rubocop -A`:

- fixes a new case of [`Style/RedundantReturn`][1]
- fixes a new case of [`Performance/StringInclude`][2]

[1]: 146b1c2e33
[2]: 3158bbb9f6

Co-authored-by: David Heinemeier Hansson <david@basecamp.com>
2024-01-02 12:49:36 +01:00
zzak 2016c664b8
✂️ cut trailing whitespace 2024-01-01 09:20:27 +09:00
Vipul A M 5d56bb8777
Add changelog entry for #50505 [ci skip] (#50513) 2024-01-01 01:06:13 +01:00
David Heinemeier Hansson e3da4fc53d
Add allow_browser to set minimum versions for your application (#50505)
* Add allow_browser to set minimum versions for your application
2023-12-31 19:19:16 +01:00
Jonathan Hefner fe39741382
Merge pull request #50500 from matthieuprat/fix-typos
Fix a couple of typos [ci-skip]
2023-12-31 09:14:03 -06:00
David Heinemeier Hansson 179b979ddb
Add rate limiting to Action Controller via the Kredis limiter type (#50490)
* Add rate limiting via the Kredis limiter type
2023-12-31 13:26:01 +01:00
Matthieu Prat 070487e09e
Fix a couple of typos [ci skip] 2023-12-31 12:28:30 +01:00
Jean Boussier 6ba2fdb2fe Bump the required Ruby version to 3.1.0
Until now, Rails only droped compatibility with older
rubies on new majors, but I propose to change this policy
because it causes us to either keep compatibility with long
EOLed rubies or to bump the Rails major more often, and to
drop multiple Ruby versions at once when we bump the major.

In my opinion it's a bad alignments of incentives. And we'd
be much better to just drop support in new minors whenever they
go EOL (so 3 years).

Also Ruby being an upstream dependency, it's not even
a semver violation AFAICT.

Since Rails 7.2 isn't planned before a few months, we
can already drop Ruby 3.0 as it will be EOL in March.
2023-12-31 08:54:03 +01:00
Jonathan Hefner 76c26135b9 Fix inclusion of url_helpers module in concern
Follow-up to #46530.

The dynamically generated `url_helpers` module is an
`ActiveSupport::Concern`.  Therefore, when it is included directly in
another `ActiveSupport::Concern`, its `included` block is deferred until
the latter concern is itself included elsewhere.  Thus, in that case,
the call to `base._routes` in `def self.included(base)` will raise
`NoMethodError` because the `included` block will not yet have defined
the `_routes` method.

This commit prevents the error by first checking if `base` responds to
`_routes`.
2023-12-19 17:43:32 -06:00
Georg Ledermann 0fc5b06c08
Allow serving compressed SVG images
This adds `image/svg+xml` to the compressible content types
of ActionDispatch::Static

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
2023-12-14 11:38:07 -05:00
Eugene Kenny 8278626a2c
Merge pull request #49297 from hannahramadan/main
Add instrumentation for ActionController::Live#send_stream
2023-12-13 08:38:59 +00:00
hramadan 6488bd9ec0 Add instrumentation for ActionController::Live#send_stream
Allows subscribing to `send_stream` events.
The event payload contains the filename, disposition, and type.
2023-12-13 08:19:48 +00:00
Jean Boussier 572f4750f1
Merge pull request #47306 from zzak/re-47129
Follow up to HTTP::Request#route_uri_pattern
2023-12-11 18:39:05 +01:00
Aaron Patterson 0915a3eed8
Merge pull request #49858 from skipkayhil/hm-dont-assign-internal-variables
Prevent assigning internal ivars to AV::Base
2023-12-11 09:06:05 -08:00
Hartley McGuire eed1cb25ed
Fix tests for status code change on Rack HEAD
Rack was recently [updated][1] with a deprecation for some status codes
that have been renamed (most notably, Unprocessable Entity was renamed
to Unprocessable Content). Since the deprecation was only added to
the `#status_code` method, this has caused test failures for some tests
that depend on the `SYMBOLS_TO_STATUS_CODE` hash.

This commit replaces the usage of `SYMBOLS_TO_STATUS_CODE` with
`#status_code` so that we get the deprecation message instead of a test
failure.

[1]: 64ad26e338
2023-12-11 01:17:28 -05:00
Ben Sheldon [he/him] 4c0eceae06
Do not instance_eval method into RoutesProxy 2023-12-08 15:39:12 -08:00
Jonathan Hefner be272a83a0 Fix system tests with Chrome cached by Selenium
Follow-up to #49908.

When Selenium resolves the driver path to a copy of Chrome that it has
downloaded / cached, it mutates the `Selenium::WebDriver::Chrome::Options`
object it receives, and relies on those changes later when the options
are used.  If `Selenium::WebDriver::Chrome::Service.driver_path` is set
but a different options object is used, Selenium will raise "cannot find
Chrome binary".  Therefore, this commit ensures that the options object
passed to `Selenium::WebDriver::DriverFinder.path` is the same options
object used by the driver later.
2023-12-07 12:52:51 -06:00
Mario Caropreso df6d2fbf2e Addressed an issue where syntax errors generated inside an eval
method cause an Internal Server Error due to a TypeError.

In order to display the extraced source of a syntax error, we try
to locate the node id for the backtrace location. The call to
RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location is expecting
a Thread::Backtrace::Location object, but we are passing a
SourceMapLocation instead.

This commit does two things:
1) it addresses the issue by making sure that we are always passing
a Thread::Backtrace::Location instead
2) it allows the development view to show the extracted source fragment
2023-12-05 06:40:19 +00:00
Hartley McGuire ec3d392e20
Fix skips in Action Pack
We can't run this test on Ruby 2.7 due to minitest being locked in the
Gemfile to an older version, so we should use that as a condition
instead of skipping if minitest doesn't have metadata.
2023-11-30 11:11:22 -05:00
Jean Boussier 4467b26a3e
Merge pull request #50145 from fatkodima/include-db-errors-in-connection-errors
Include exception causes into log messages
2023-11-28 20:45:13 +01:00