提交 a6a89571 编写于 作者: J José Valim

Merge pull request #6372 from richo/bugs/middleware_stack_as_array

Add some common Array methods to the middleware stack
......@@ -75,6 +75,11 @@ def [](i)
middlewares[i]
end
def unshift(*args, &block)
middleware = self.class::Middleware.new(*args, &block)
middlewares.unshift(middleware)
end
def initialize_copy(other)
self.middlewares = other.middlewares.dup
end
......
......@@ -87,6 +87,11 @@ def setup
assert_equal FooMiddleware, @stack[0].klass
end
test "unshift adds a new middleware at the beginning of the stack" do
@stack.unshift :"MiddlewareStackTest::BazMiddleware"
assert_equal BazMiddleware, @stack.first.klass
end
test "raise an error on invalid index" do
assert_raise RuntimeError do
@stack.insert("HiyaMiddleware", BazMiddleware)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册