1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/guides/source
Genadi Samokovarov 40fc1651ad Delayed middleware delete does not allow move operations
While trying to fix #16433, we made the middleware deletions always
happen at the end. While this works for the case of deleting the
Rack::Runtime middleware, it makes operations like the following
misbehave.

```ruby
gem "bundler", "< 1.16"

begin
  require "bundler/inline"
rescue LoadError => e
  $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
  raise e
end

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails"
end

require "action_controller/railtie"

class TestApp < Rails::Application
  config.root = __dir__
  secrets.secret_key_base = "secret_key_base"

  config.logger = Logger.new($stdout)
  Rails.logger  = config.logger

  middleware.insert_after ActionDispatch::Session::CookieStore, ::Rails::Rack::Logger, config.log_tags
  middleware.delete ::Rails::Rack::Logger
end

require "minitest/autorun"
require "rack/test"

class BugTest < Minitest::Test
  include Rack::Test::Methods

  def test_returns_success
    get "/"
    assert last_response.ok?
  end

  private
    def app
      Rails.application
    end
end
```

In the case ☝️  the ::Rails::Rack::Logger would be deleted instead of
moved, because the order of middleware stack building execution will be:

```ruby
[:insert, ActionDispatch::Session::CookieStore, [::Rails::Rack::Logger]]
[:delete, ::Rails::Rack::Logger, [config.log_tags]]
```

This is pretty surprising and hard to reason about behaviour, unless you
go spelunking into the Rails configuration code.

I have a few solutions in mind and all of them have their drawbacks.

1. Introduce a `Rails::Configuration::MiddlewareStackProxy#delete!` that
delays the deleted operations. This will make `#delete` to be executed
in order. The drawback here is backwards incompatible behavior and a new
public method.

2. Just revert to the old operations. This won't allow people to delete
the `Rack::Runtime` middleware.

3. Legitimize the middleware moving with the new `#move_after` and
`#move_before` methods. This does not breaks any backwards
compatibility, but includes 2 new methods to the middleware stack.

I have implemented `3.` in this pull request.

Happy holidays! 🎄
2020-01-08 11:30:02 +02:00
..
kindle
2_2_release_notes.md
2_3_release_notes.md Fix period position 2019-06-06 02:19:04 +09:00
3_0_release_notes.md
3_1_release_notes.md
3_2_release_notes.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
4_0_release_notes.md
4_1_release_notes.md
4_2_release_notes.md
5_0_release_notes.md [ci skip] switch eg. to proper e.g. 2019-10-07 02:18:36 +02:00
5_1_release_notes.md NPM -> npm [ci skip] 2019-05-12 12:00:03 +02:00
5_2_release_notes.md fix a typo in 5_2_release_notes.md 2019-07-24 18:23:15 +03:00
6_0_release_notes.md Merge pull request #36823 from abhaynikam/add-multiple-database-guide-entry-to-release-notes 2019-08-05 08:42:15 -04:00
_license.html.erb
_welcome.html.erb Fix Rails Version in Guides Index 2019-08-18 14:45:11 +02:00
action_cable_overview.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
action_controller_overview.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
action_mailbox_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
action_mailer_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
action_text_overview.md Fix markup and improve Action Text guide a bit [ci skip] 2019-12-31 07:42:13 -03:00
action_view_overview.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_job_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_model_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_record_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_record_callbacks.md Only assign @new_record_before_save once in autosave_association 2020-01-06 12:57:33 -05:00
active_record_migrations.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_record_multiple_databases.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_record_postgresql.md Fix the broken anchor of link [ci skip] 2020-01-06 19:15:53 +09:00
active_record_querying.md Add missing languages for guides code blocks [ci skip] 2019-12-17 19:38:45 -05:00
active_record_validations.md Add ActiveRecord::Validations::NumericalityValidator 2020-01-06 19:01:29 -05:00
active_storage_overview.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
active_support_core_extensions.md Merge pull request #37574 from Sean0628/mod-doc-for-including-and-excluding 2019-11-19 19:16:25 -06:00
active_support_instrumentation.md Remove connection_id key from the sql.active_record notification 2019-12-17 21:16:41 -03:00
api_app.md Fix typo s/prefered/preferred/ [ci skip] 2020-01-04 21:10:41 +09:00
api_documentation_guidelines.md Add missing languages for guides code blocks [ci skip] 2019-12-17 19:38:45 -05:00
asset_pipeline.md Merge branch 'master' into doc/asset-pipeline-guide 2019-12-19 12:52:40 +08:00
association_basics.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
autoloading_and_reloading_constants.md removes redundant constantize call [skip ci] 2019-12-25 09:22:55 +01:00
autoloading_and_reloading_constants_classic_mode.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
caching_with_rails.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
command_line.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
configuring.md Delayed middleware delete does not allow move operations 2020-01-08 11:30:02 +02:00
contributing_to_ruby_on_rails.md Fix title capitalization in guides according to guidelines [ci skip] 2019-12-23 10:47:23 +01:00
debugging_rails_applications.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
development_dependencies_install.md Update "The Hard Way" setup for Arch Linux 2020-01-04 01:29:51 +00:00
documents.yaml Keep the name of the releases note consistent 2019-08-19 14:17:35 -04:00
engines.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
form_helpers.md Update form examples [ci skip] 2019-11-01 18:10:36 -05:00
generators.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
getting_started.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
i18n.md Fix title capitalization in guides according to guidelines [ci skip] 2019-12-23 10:47:23 +01:00
index.html.erb
initialization.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
layout.html.erb Use prism.js for code highlighting in guides [ci skip] 2019-12-16 19:52:13 +01:00
layouts_and_rendering.md Fix typo in Options for render [ci skip] 2019-11-30 11:34:08 -03:00
maintenance_policy.md update https urls [ci skip] 2019-10-03 11:01:32 +02:00
plugins.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
rails_application_templates.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
rails_on_rack.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
routing.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
ruby_on_rails_guides_guidelines.md Add preposition and conjunction example to title guideline [ci skip] 2019-12-23 10:51:11 +01:00
security.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
testing.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
threading_and_code_execution.md
upgrading_ruby_on_rails.md remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
working_with_javascript_in_rails.md Fix title capitalization in guides according to guidelines [ci skip] 2019-12-23 10:47:23 +01:00