Skip to content

Commit

Permalink
Merge remote-tracking branch 'rails/main' into allow_redirect_from_co…
Browse files Browse the repository at this point in the history
…nfiguration_hosts
  • Loading branch information
Kevinrob committed Apr 12, 2024
2 parents a3e1537 + 7d17add commit 5bf46af
Show file tree
Hide file tree
Showing 585 changed files with 11,324 additions and 5,329 deletions.
32 changes: 10 additions & 22 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby/.devcontainer/base.Dockerfile

# [Choice] Ruby version: 3, 3.3, 3.2, 3.1, 3.0, 2, 2.7, 2.6
ARG VARIANT="3.3"
FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="lts/*"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
ARG VARIANT="3.3.0"
FROM ghcr.io/rails/devcontainer/images/ruby:${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
mariadb-client libmariadb-dev \
postgresql-client postgresql-contrib libpq-dev \
ffmpeg mupdf mupdf-tools libvips poppler-utils


ARG IMAGEMAGICK_VERSION="7.1.0-5"
RUN wget -qO /tmp/im.tar.xz https://imagemagick.org/archive/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz \
&& wget -qO /tmp/im.sig https://imagemagick.org/archive/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz.asc \
&& gpg --batch --keyserver keyserver.ubuntu.com --recv 89AB63D48277377A \
&& gpg --batch --verify /tmp/im.sig /tmp/im.tar.xz \
&& tar xJf /tmp/im.tar.xz -C /tmp \
&& cd /tmp/ImageMagick-$IMAGEMAGICK_VERSION \
&& ./configure --with-rsvg && make -j 9 && make install \
&& ldconfig /usr/local/lib \
&& rm -rf /tmp/*
ffmpeg mupdf mupdf-tools libvips-dev poppler-utils \
libxml2-dev sqlite3 imagemagick

# Add the Rails main Gemfile and install the gems. This means the gem install can be done
# during build instead of on start. When a fork or branch has different gems, we still have an
Expand All @@ -44,8 +29,11 @@ COPY activerecord/activerecord.gemspec /tmp/rails/activerecord/
COPY activestorage/activestorage.gemspec /tmp/rails/activestorage/
COPY activesupport/activesupport.gemspec /tmp/rails/activesupport/
COPY railties/railties.gemspec /tmp/rails/railties/
# Docker does not support COPY as users other than root. So we need to chown this dir so we
# can bundle as vscode user and then remove the tmp dir
RUN chown -R vscode:vscode /tmp/rails
USER vscode
RUN cd /tmp/rails \
&& bundle install \
&& yarn install \
&& /home/vscode/.rbenv/shims/bundle install \
&& rm -rf /tmp/rails
RUN chown -R vscode:vscode /usr/local/rvm

4 changes: 2 additions & 2 deletions .devcontainer/boot.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bundle install
yarn install

sudo chown -R vscode:vscode /usr/local/bundle
. ${NVM_DIR}/nvm.sh && nvm install --lts
yarn install

cd activerecord

Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "latest"
}
},

Expand Down
6 changes: 3 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ here](https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#cont
About this template
The following template aims to help contributors write a good description for their pull requests.
We'd like you to provide a description of the changes in your pull request (i.e. bugs fixed or features added), motivation behind the changes, and complete the checklist below before opening a pull request.
We'd like you to provide a description of the changes in your pull request (i.e. bugs fixed or features added), the motivation behind the changes, and complete the checklist below before opening a pull request.
Feel free to discard it if you need to (e.g. when you just fix a typo). -->

Expand All @@ -33,13 +33,13 @@ This Pull Request changes [REPLACE ME]

### Additional information

<!-- Provide additional information such as benchmarks, reference to other repositories or alternative solutions. -->
<!-- Provide additional information such as benchmarks, references to other repositories, or alternative solutions. -->

### Checklist

Before submitting the PR make sure the following are checked:

* [ ] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
* [ ] This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
* [ ] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]`
* [ ] Tests are added or updated if you fix a bug or add a feature.
* [ ] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
10 changes: 3 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ Rails/IndexWith:
Style/AndOr:
Enabled: true

# Align `when` with `case`.
Layout/CaseIndentation:
Enabled: true

Layout/ClosingHeredocIndentation:
Enabled: true

Expand Down Expand Up @@ -320,6 +316,9 @@ Style/RedundantCondition:
Style/RedundantDoubleSplatHashBraces:
Enabled: true

Style/OpenStructUse:
Enabled: true

Style/ArrayIntersect:
Enabled: true

Expand Down Expand Up @@ -359,9 +358,6 @@ Performance/DeletePrefix:
Performance/DeleteSuffix:
Enabled: true

Performance/OpenStruct:
Enabled: true

Performance/InefficientHashSearch:
Enabled: true

Expand Down
4 changes: 0 additions & 4 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

tap "homebrew/core"
tap "homebrew/bundle"
tap "homebrew/services"
tap "homebrew/cask"
brew "ffmpeg"
brew "memcached"
brew "mysql"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
libxml-ruby (5.0.0)
libxml-ruby (5.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand All @@ -317,7 +317,7 @@ GEM
net-imap
net-pop
net-smtp
marcel (1.0.2)
marcel (1.0.4)
matrix (0.4.2)
mdl (0.12.0)
kramdown (~> 2.3)
Expand Down
10 changes: 9 additions & 1 deletion actioncable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
* Add two new assertion methods for ActionCable test cases: `assert_has_no_stream`
* Record ping on every Action Cable message.

Previously only `ping` and `welcome` message types were keeping the connection active.
Now every Action Cable message updates the `pingedAt` value, preventing the connection
from being marked as stale.

*yauhenininjia*

* Add two new assertion methods for Action Cable test cases: `assert_has_no_stream`
and `assert_has_no_stream_for`. These methods can be used to assert that a
stream has been stopped, e.g. via `stop_stream` or `stop_stream_for`. They complement
the already existing `assert_has_stream` and `assert_has_stream_for` methods.
Expand Down
6 changes: 3 additions & 3 deletions actioncable/app/assets/javascripts/action_cable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions actioncable/app/assets/javascripts/actioncable.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions actioncable/app/assets/javascripts/actioncable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion actioncable/app/javascript/action_cable/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Connection.prototype.events = {
message(event) {
if (!this.isProtocolSupported()) { return }
const {identifier, message, reason, reconnect, type} = JSON.parse(event.data)
this.monitor.recordMessage()
switch (type) {
case message_types.welcome:
if (this.triedToReconnect()) {
Expand All @@ -139,7 +140,7 @@ Connection.prototype.events = {
logger.log(`Disconnecting. Reason: ${reason}`)
return this.close({allowReconnect: reconnect})
case message_types.ping:
return this.monitor.recordPing()
return null
case message_types.confirmation:
this.subscriptions.confirmSubscription(identifier)
if (this.reconnectAttempted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ class ConnectionMonitor {
return this.startedAt && !this.stoppedAt
}

recordPing() {
recordMessage() {
this.pingedAt = now()
}

recordConnect() {
this.reconnectAttempts = 0
this.recordPing()
delete this.disconnectedAt
logger.log("ConnectionMonitor recorded connect")
}
Expand Down
8 changes: 5 additions & 3 deletions actioncable/lib/action_cable/channel/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ def connection_gid(ids)
# ActionCable::Channel::TestCase will also automatically provide the following
# instance methods for use in the tests:
#
# **connection**
# connection
# : An ActionCable::Channel::ConnectionStub, representing the current HTTP
# connection.
# **subscription**
#
# subscription
# : An instance of the current channel, created when you call `subscribe`.
# **transmissions**
#
# transmissions
# : A list of all messages that have been transmitted into the channel.
#
#
Expand Down
6 changes: 3 additions & 3 deletions actioncable/test/subscription_adapter/postgresql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup
ActiveRecord::Base.establish_connection database_config

begin
ActiveRecord::Base.connection.connect!
ActiveRecord::Base.lease_connection.connect!
rescue
@rx_adapter = @tx_adapter = nil
skip "Couldn't connect to PostgreSQL: #{database_config.inspect}"
Expand Down Expand Up @@ -68,7 +68,7 @@ def active?
def test_default_subscription_connection_identifier
subscribe_as_queue("channel") { }

identifiers = ActiveRecord::Base.connection.exec_query("SELECT application_name FROM pg_stat_activity").rows
identifiers = ActiveRecord::Base.lease_connection.exec_query("SELECT application_name FROM pg_stat_activity").rows
assert_includes identifiers, ["ActionCable-PID-#{$$}"]
end

Expand All @@ -81,7 +81,7 @@ def test_custom_subscription_connection_identifier

subscribe_as_queue("channel", adapter) { }

identifiers = ActiveRecord::Base.connection.exec_query("SELECT application_name FROM pg_stat_activity").rows
identifiers = ActiveRecord::Base.lease_connection.exec_query("SELECT application_name FROM pg_stat_activity").rows
assert_includes identifiers, ["hello-world-42"]
end
end
2 changes: 1 addition & 1 deletion actionmailbox/test/migrations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ActionMailbox::MigrationsTest < ActiveSupport::TestCase
@original_verbose = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = false

@connection = ActiveRecord::Base.connection
@connection = ActiveRecord::Base.lease_connection
@original_options = Rails.configuration.generators.options.deep_dup
end

Expand Down
2 changes: 1 addition & 1 deletion actionmailer/test/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def exercise_url_for(options)
class ActionMailerUrlTest < ActionMailer::TestCase
class DummyModel
def self.model_name
OpenStruct.new(route_key: "dummy_model")
Struct.new(:route_key, :name).new("dummy_model", nil)
end

def persisted?
Expand Down
2 changes: 1 addition & 1 deletion actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

* Add `allow_browser` to set minimum browser versions for the application.

A browser that's blocked will by default be served the file in `public/426.html` with a HTTP status code of "426 Upgrade Required".
A browser that's blocked will by default be served the file in `public/406-unsupported-browser.html` with a HTTP status code of "406 Not Acceptable".

```ruby
class ApplicationController < ActionController::Base
Expand Down
5 changes: 2 additions & 3 deletions actionpack/lib/abstract_controller/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ def translate(key, **options)
key = "#{path}.#{action_name}#{key}"
end

if options[:default]
options[:default] = [options[:default]] unless options[:default].is_a?(Array)
options[:default] = options[:default].map do |value|
if options[:default] && ActiveSupport::HtmlSafeTranslation.html_safe_translation_key?(key)
options[:default] = Array(options[:default]).map do |value|
value.is_a?(String) ? ERB::Util.html_escape(value) : value
end
end
Expand Down
7 changes: 4 additions & 3 deletions actionpack/lib/action_controller/metal/allow_browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ module ClassMethods
# versions specified. This means that all other browsers, as well as agents that
# aren't reporting a user-agent header, will be allowed access.
#
# A browser that's blocked will by default be served the file in public/426.html
# with a HTTP status code of "426 Upgrade Required".
# A browser that's blocked will by default be served the file in
# public/406-unsupported-browser.html with a HTTP status code of "406 Not
# Acceptable".
#
# In addition to specifically named browser versions, you can also pass
# `:modern` as the set to restrict support to browsers natively supporting webp
Expand Down Expand Up @@ -43,7 +44,7 @@ module ClassMethods
# # In addition to the browsers blocked by ApplicationController, also block Opera below 104 and Chrome below 119 for the show action.
# allow_browser versions: { opera: 104, chrome: 119 }, only: :show
# end
def allow_browser(versions:, block: -> { render file: Rails.root.join("public/426.html"), layout: false, status: :upgrade_required }, **options)
def allow_browser(versions:, block: -> { render file: Rails.root.join("public/406-unsupported-browser.html"), layout: false, status: :not_acceptable }, **options)
before_action -> { allow_browser(versions: versions, block: block) }, **options
end
end
Expand Down
Loading

0 comments on commit 5bf46af

Please sign in to comment.