Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix GH #4873. Allow swapping middleware of same class

  • Loading branch information...
commit e7ec96989543b95d3459fcdab1f31466ec179233 1 parent 7a72fdc
@kennyj kennyj authored
View
5 actionpack/lib/action_dispatch/middleware/stack.rb
@@ -93,8 +93,9 @@ def insert_after(index, *args, &block)
end
def swap(target, *args, &block)
- insert_before(target, *args, &block)
- delete(target)
+ index = assert_index(target, :before)
+ insert(index, *args, &block)
+ middlewares.delete_at(index + 1)
end
def delete(target)
View
6 actionpack/test/dispatch/middleware_stack_test.rb
@@ -81,6 +81,12 @@ def setup
assert_equal BazMiddleware, @stack[0].klass
end
+ test "swaps one middleware out for same middleware class" do
+ assert_equal FooMiddleware, @stack[0].klass
+ @stack.swap(FooMiddleware, FooMiddleware, Proc.new { |env| [500, {}, ['error!']] })
+ assert_equal FooMiddleware, @stack[0].klass
+ end
+
test "raise an error on invalid index" do
assert_raise RuntimeError do
@stack.insert("HiyaMiddleware", BazMiddleware)
Please sign in to comment.
Something went wrong with that request. Please try again.