Skip to content

Commit

Permalink
Merge branch 'main' into decouple-nokogiri
Browse files Browse the repository at this point in the history
* main: (169 commits)
  Add endless range example to the Active Record Querying guide
  Added default values to raise_delivery_errors guide (rails#45616)
  better docs for ActiveSupport::EncryptedFile#read
  Fix caching of missed translations
  Fix extra changelog entry added in 959d46e (rails#45604)
  Add `quarter` method to date/time (rails#45009)
  Fix testing changing yaml_column_permitted_classes
  Remove unnecessary or incorrect calls to connection_handler
  Defer constant loading of `ActiveRecord::DestroyAssociationAsyncJob` via a String instead of a class constant
  ActiveRecord::Store encode store as a regular Hash
  Appease rubocop
  Fix failing test with mysql 5.7
  Fix cases where CTE's are not supported
  Allow Symbols by default in YAML serialized columns
  Remove unnecessary initializers
  Preserve `job.enqueued_at` timestamp precision
  Improve performance by removing respond_to? from runtime code
  Move configuration to the right section
  Fix ivar name in PoolManager
  Change ActiveRecord::Coders::YAMLColumn default to safe_load
  ...
  • Loading branch information
jamis committed Jul 18, 2022
2 parents 68ca5b0 + 4e9fee9 commit 48a4beb
Show file tree
Hide file tree
Showing 277 changed files with 5,507 additions and 2,117 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \


ARG IMAGEMAGICK_VERSION="7.1.0-5"
RUN wget -qO /tmp/im.tar.xz https://imagemagick.org/download/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz \
&& wget -qO /tmp/im.sig https://imagemagick.org/download/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz.asc \
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 \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Ruby 2.7
- name: Set up Ruby 3.1
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.1
bundler-cache: true

- name: Run RuboCop
Expand Down
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec

gem "minitest", ">= 5.15.0"
if RUBY_VERSION < "3"
gem "minitest", ">= 5.15.0", "< 5.16"
else
gem "minitest", ">= 5.15.0"
end

# We need a newish Rake since Active Job sets its test tasks' descriptions.
gem "rake", ">= 11.1"
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PATH
activesupport (= 7.1.0.alpha)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.5)
zeitwerk (~> 2.6)
actionmailbox (7.1.0.alpha)
actionpack (= 7.1.0.alpha)
activejob (= 7.1.0.alpha)
Expand Down Expand Up @@ -97,7 +97,7 @@ PATH
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -322,7 +322,7 @@ GEM
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
minitest (5.15.0)
minitest (5.16.1)
minitest-bisect (1.5.1)
minitest-server (~> 1.0)
path_expander (~> 1.1)
Expand Down Expand Up @@ -499,7 +499,7 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
sqlite3 (1.4.4)
stackprof (0.2.17)
stimulus-rails (1.0.2)
railties (>= 6.0.0)
Expand Down Expand Up @@ -551,7 +551,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.5.3)
zeitwerk (2.6.0)

PLATFORMS
ruby
Expand Down
6 changes: 6 additions & 0 deletions actioncable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* The Action Cable server is now mounted with `anchor: true`.

This means that routes that also start with `/cable` will no longer clash with Action Cable.

*Alex Ghiculescu*

* `ActionCable.server.remote_connections.where(...).disconnect` now sends `disconnect` message
before closing the connection with the reconnection strategy specified (defaults to `true`).

Expand Down
2 changes: 1 addition & 1 deletion actioncable/actioncable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ Gem::Specification.new do |s|

s.add_dependency "nio4r", "~> 2.0"
s.add_dependency "websocket-driver", ">= 0.6.1"
s.add_dependency "zeitwerk", "~> 2.5"
s.add_dependency "zeitwerk", "~> 2.6"
end
6 changes: 3 additions & 3 deletions actioncable/lib/action_cable/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Engine < Rails::Engine # :nodoc:
config = app.config
unless config.action_cable.mount_path.nil?
app.routes.prepend do
mount ActionCable.server => config.action_cable.mount_path, internal: true
mount ActionCable.server => config.action_cable.mount_path, internal: true, anchor: true
end
end
end
Expand All @@ -60,7 +60,7 @@ class Engine < Rails::Engine # :nodoc:
initializer "action_cable.set_work_hooks" do |app|
ActiveSupport.on_load(:action_cable) do
ActionCable::Server::Worker.set_callback :work, :around, prepend: true do |_, inner|
app.executor.wrap do
app.executor.wrap(source: "application.action_cable") do
# If we took a while to get the lock, we may have been halted
# in the meantime. As we haven't started doing any real work
# yet, we should pretend that we never made it off the queue.
Expand All @@ -71,7 +71,7 @@ class Engine < Rails::Engine # :nodoc:
end

wrap = lambda do |_, inner|
app.executor.wrap(&inner)
app.executor.wrap(source: "application.action_cable", &inner)
end
ActionCable::Channel::Base.set_callback :subscribe, :around, prepend: true, &wrap
ActionCable::Channel::Base.set_callback :unsubscribe, :around, prepend: true, &wrap
Expand Down
2 changes: 1 addition & 1 deletion actioncable/lib/action_cable/server/connections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def remove_connection(connection)
# disconnect.
def setup_heartbeat_timer
@heartbeat_timer ||= event_loop.timer(BEAT_INTERVAL) do
event_loop.post { connections.map(&:beat) }
event_loop.post { connections.each(&:beat) }
end
end

Expand Down
22 changes: 14 additions & 8 deletions actioncable/lib/rails/generators/channel/USAGE
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Description:
============
Generates a new cable channel for the server (in Ruby) and client (in JavaScript).
Pass the channel name, either CamelCased or under_scored, and an optional list of channel actions as arguments.

Example:
========
bin/rails generate channel Chat speak
Examples:
`bin/rails generate channel notification`

creates a Chat channel class, test and JavaScript asset:
Channel: app/channels/chat_channel.rb
Test: test/channels/chat_channel_test.rb
Assets: $JAVASCRIPT_PATH/channels/chat_channel.js
creates a notification channel class, test and JavaScript asset:
Channel: app/channels/notification_channel.rb
Test: test/channels/notification_channel_test.rb
Assets: $JAVASCRIPT_PATH/channels/notification_channel.js

`bin/rails generate channel chat speak`

creates a chat channel with a speak action.

`bin/rails generate channel comments --no-assets`

creates a comments channel without JavaScript assets.
4 changes: 1 addition & 3 deletions actionmailbox/lib/rails/generators/mailbox/USAGE
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Description:
============
Generates a new mailbox class in app/mailboxes and invokes your template
engine and test framework generators.

Example:
========
bin/rails generate mailbox inbox
`bin/rails generate mailbox inbox`

creates an InboxMailbox class and test:
Mailbox: app/mailboxes/inbox_mailbox.rb
Expand Down
20 changes: 12 additions & 8 deletions actionmailer/lib/rails/generators/mailer/USAGE
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Description:
============
Generates a new mailer and its views. Passes the mailer name, either
CamelCased or under_scored, and an optional list of emails as arguments.

This generates a mailer class in app/mailers and invokes your template
engine and test framework generators.

Example:
========
bin/rails generate mailer Notifications signup forgot_password invoice
Examples:
`bin/rails generate mailer sign_up`

creates a sign up mailer class, views, and test:
Mailer: app/mailers/sign_up_mailer.rb
Views: app/views/sign_up_mailer/signup.text.erb [...]
Test: test/mailers/sign_up_mailer_test.rb

`bin/rails generate mailer notifications sign_up forgot_password invoice`

creates a notifications mailer with sign_up, forgot_password, and invoice actions.


creates a Notifications mailer class, views, and test:
Mailer: app/mailers/notifications_mailer.rb
Views: app/views/notifications_mailer/signup.text.erb [...]
Test: test/mailers/notifications_mailer_test.rb
10 changes: 10 additions & 0 deletions actionpack/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
* Allow opting out of the `SameSite` cookie attribute when setting a cookie.

You can opt out of `SameSite` by passing `same_site: nil`.

`cookies[:foo] = { value: "bar", same_site: nil }`

Previously, this incorrectly set the `SameSite` attribute to the value of the `cookies_same_site_protection` setting.

*Alex Ghiculescu*

* Allow using `helper_method`s in `content_security_policy` and `permissions_policy`

Previously you could access basic helpers (defined in helper modules), but not
Expand Down
16 changes: 0 additions & 16 deletions actionpack/lib/action_controller/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,6 @@ module ActionController
class Base < Metal
abstract!

# We document the request and response methods here because albeit they are
# implemented in ActionController::Metal, the type of the returned objects
# is unknown at that level.

##
# :method: request
#
# Returns an ActionDispatch::Request instance that represents the
# current request.

##
# :method: response
#
# Returns an ActionDispatch::Response that represents the current
# response.

# Shortcut helper that returns all the modules included in
# ActionController::Base except the ones passed as arguments:
#
Expand Down
20 changes: 18 additions & 2 deletions actionpack/lib/action_controller/metal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,25 @@ def controller_name
self.class.controller_name
end

attr_internal :response, :request
##
# :attr_reader: request
#
# The ActionDispatch::Request instance for the current request.
attr_internal :request

##
# :attr_reader: response
#
# The ActionDispatch::Response instance for the current response.
attr_internal :response

delegate :session, to: "@_request"
delegate :headers, :status=, :location=, :content_type=,

##
# Delegates to ActionDispatch::Response#headers.
delegate :headers, to: "@_response"

delegate :status=, :location=, :content_type=,
:status, :location, :content_type, :media_type, to: "@_response"

def initialize
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/metal/redirecting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def _enforce_open_redirect_protection(location, allow_other_host:)
end

def _url_host_allowed?(url)
[request.host, nil].include?(URI(url.to_s).host)
host = URI(url.to_s).host
host == request.host || host.nil? && url.to_s.start_with?("/")
rescue ArgumentError, URI::Error
false
end
Expand Down
13 changes: 13 additions & 0 deletions actionpack/lib/action_dispatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ module Session
autoload :CookieStore, "action_dispatch/middleware/session/cookie_store"
autoload :MemCacheStore, "action_dispatch/middleware/session/mem_cache_store"
autoload :CacheStore, "action_dispatch/middleware/session/cache_store"

def self.resolve_store(session_store) # :nodoc:
self.const_get(session_store.to_s.camelize)
rescue NameError
raise <<~ERROR
Unable to resolve session store #{session_store.inspect}.
#{session_store.inspect} resolves to ActionDispatch::Session::#{session_store.to_s.camelize},
but that class is undefined.
Is #{session_store.inspect} spelled correctly, and are any necessary gems installed?
ERROR
end
end

mattr_accessor :test_app
Expand Down
32 changes: 20 additions & 12 deletions actionpack/lib/action_dispatch/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ module ActionDispatch # :nodoc:
# back to the web browser) or a TestResponse (i.e. one that is generated
# from integration tests).
#
# \Response is mostly a Ruby on \Rails framework implementation detail, and
# should never be used directly in controllers. Controllers should use the
# methods defined in ActionController::Base instead. For example, if you want
# to set the HTTP response's content MIME type, then use
# ActionControllerBase#headers instead of Response#headers.
# The \Response object for the current request is exposed on controllers as
# ActionController::Metal#response. ActionController::Metal also provides a
# few additional methods that delegate to attributes of the \Response such as
# ActionController::Metal#headers.
#
# Nevertheless, integration tests may want to inspect controller responses in
# more detail, and that's when \Response can be useful for application
# developers. Integration test methods such as
# ActionDispatch::Integration::Session#get and
# ActionDispatch::Integration::Session#post return objects of type
# TestResponse (which are of course also of type \Response).
# Integration tests will likely also want to inspect responses in
# more detail. Methods such as Integration::RequestHelpers#get
# and Integration::RequestHelpers#post return instances of
# TestResponse (which inherits from \Response) for this purpose.
#
# For example, the following demo integration test prints the body of the
# controller response to the console:
Expand Down Expand Up @@ -64,7 +61,18 @@ def to_hash
# The HTTP status code.
attr_reader :status

# Get headers for this response.
# The headers for the response.
#
# header["Content-Type"] # => "text/plain"
# header["Content-Type"] = "application/json"
# header["Content-Type"] # => "application/json"
#
# Also aliased as +headers+.
#
# headers["Content-Type"] # => "text/plain"
# headers["Content-Type"] = "application/json"
# headers["Content-Type"] # => "application/json"
#
attr_reader :header

alias_method :headers, :header
Expand Down
5 changes: 3 additions & 2 deletions actionpack/lib/action_dispatch/middleware/cookies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ def handle_options(options)

options[:path] ||= "/"

cookies_same_site_protection = request.cookies_same_site_protection
options[:same_site] ||= cookies_same_site_protection.call(request)
unless options.key?(:same_site)
options[:same_site] = request.cookies_same_site_protection.call(request)
end

if options[:domain] == :all || options[:domain] == "all"
# If there is a provided tld length then we use it otherwise default domain regexp.
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def call(env)
response = @app.call(env)
returned = response << ::Rack::BodyProxy.new(response.pop) { state.complete! }
rescue => error
@executor.error_reporter.report(error, handled: false)
@executor.error_reporter.report(error, handled: false, source: "application.action_dispatch")
raise
ensure
state.complete! unless returned
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def mount(app, options = nil)
target_as = name_for_action(options[:as], path)
options[:via] ||= :all

match(path, options.merge(to: app, anchor: false, format: false))
match(path, { to: app, anchor: false, format: false }.merge(options))

define_generate_prefix(app, target_as) if rails_app
self
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_dispatch/testing/test_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "action_dispatch/testing/request_encoder"

module ActionDispatch
# Integration test methods such as ActionDispatch::Integration::Session#get
# and ActionDispatch::Integration::Session#post return objects of class
# Integration test methods such as Integration::RequestHelpers#get
# and Integration::RequestHelpers#post return objects of class
# TestResponse, which represent the HTTP response results of the requested
# controller actions.
#
Expand Down

0 comments on commit 48a4beb

Please sign in to comment.