mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #42821 from p8/actionpack/middleware-remove
Add `Middleware#remove` to delete middleware or raise if not found.
This commit is contained in:
commit
f4229a2bf0
3 changed files with 30 additions and 14 deletions
|
@ -1,3 +1,10 @@
|
|||
* Add `Middleware#remove` to delete middleware or raise if not found.
|
||||
|
||||
`Middleware#remove` works just like `Middleware#delete` but will
|
||||
raise an error if the middleware isn't found.
|
||||
|
||||
*Alex Ghiculescu*, *Petrik de Heus*
|
||||
|
||||
* Exclude additional flash types from `ActionController::Base.action_methods`.
|
||||
|
||||
Ensures that additional flash types defined on ActionController::Base subclasses
|
||||
|
@ -11,13 +18,6 @@
|
|||
|
||||
*Gavin Morrice*
|
||||
|
||||
* Deleting an item from the Middleware stack will raise if the item is not found
|
||||
|
||||
Previously, calling `config.middleware.delete(ItemNotInMiddleware)` would fail silently.
|
||||
Now it will raise, same as `config.middleware.move(0, ItemNotInMiddleware)` does.
|
||||
|
||||
*Alex Ghiculescu*
|
||||
|
||||
* OpenSSL constants are now used for Digest computations.
|
||||
|
||||
*Dirkjan Bussink*
|
||||
|
|
|
@ -130,7 +130,11 @@ module ActionDispatch
|
|||
ruby2_keywords(:swap)
|
||||
|
||||
def delete(target)
|
||||
middlewares.reject! { |m| m.name == target.name } || (raise "No such middleware to delete: #{target.inspect}")
|
||||
middlewares.reject! { |m| m.name == target.name }
|
||||
end
|
||||
|
||||
def remove(target)
|
||||
delete(target) || (raise "No such middleware to remove: #{target.inspect}")
|
||||
end
|
||||
|
||||
def move(target, source)
|
||||
|
|
|
@ -37,6 +37,24 @@ class MiddlewareStackTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "delete ignores middleware not in the stack" do
|
||||
assert_no_difference "@stack.size" do
|
||||
@stack.delete BazMiddleware
|
||||
end
|
||||
end
|
||||
|
||||
test "remove deletes the middleware" do
|
||||
assert_difference "@stack.size", -1 do
|
||||
@stack.remove FooMiddleware
|
||||
end
|
||||
end
|
||||
|
||||
test "remove requires the middleware to be in the stack" do
|
||||
assert_raises RuntimeError do
|
||||
@stack.remove BazMiddleware
|
||||
end
|
||||
end
|
||||
|
||||
test "use should push middleware as class onto the stack" do
|
||||
assert_difference "@stack.size" do
|
||||
@stack.use BazMiddleware
|
||||
|
@ -105,12 +123,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "delete requires the middleware to be in the stack" do
|
||||
assert_raises RuntimeError do
|
||||
@stack.delete(BazMiddleware)
|
||||
end
|
||||
end
|
||||
|
||||
test "move preserves the arguments of the moved middleware" do
|
||||
@stack.use BazMiddleware, true, foo: "bar"
|
||||
@stack.move_before(FooMiddleware, BazMiddleware)
|
||||
|
|
Loading…
Reference in a new issue