Permalink
Browse files

Fix GH #4873. Allow swapping middleware of same class

  • Loading branch information...
1 parent 7a72fdc commit e7ec96989543b95d3459fcdab1f31466ec179233 @kennyj kennyj committed Feb 4, 2012
@@ -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)
@@ -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)

0 comments on commit e7ec969

Please sign in to comment.