Skip to content

Commit

Permalink
Merge pull request #42655 from ghiculescu/middleware-delete-raise
Browse files Browse the repository at this point in the history
Deleting an item from the Middleware stack should raise if the item is not found
  • Loading branch information
rafaelfranca committed Jul 7, 2021
2 parents b995208 + 07558ff commit 2d1e6ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
* 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*
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/middleware/stack.rb
Expand Up @@ -130,7 +130,7 @@ def swap(target, *args, &block)
ruby2_keywords(:swap)

def delete(target)
middlewares.delete_if { |m| m.name == target.name }
middlewares.reject! { |m| m.name == target.name } || (raise "No such middleware to delete: #{target.inspect}")
end

def move(target, source)
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/dispatch/middleware_stack_test.rb
Expand Up @@ -105,6 +105,12 @@ def test_delete_works
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)
Expand Down

0 comments on commit 2d1e6ae

Please sign in to comment.