Skip to content

Commit

Permalink
Push kwargs onto middleware stack
Browse files Browse the repository at this point in the history
  • Loading branch information
cllns committed Jul 8, 2024
1 parent f1d4fa1 commit 403ad19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/hanami/api/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def initialize(prefix)

# @since 0.1.0
# @api private
def use(path, middleware, *args, &blk)
def use(path, middleware, *args, **kwargs, &blk)
# FIXME: test with prefix when Hanami::API.settings and prefix will be supported
@stack[path] ||= []
@stack[path].push([middleware, args, blk])
@stack[path].push([middleware, args, kwargs, blk])
end

# @since 0.1.1
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/hanami/api/middleware/stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

actual = subject.to_hash
expected = {
"/" => [["elapsed time", [], nil]],
"/admin" => [["elapsed time", [], nil], ["admin auth", [], nil]],
"/api" => [["elapsed time", [], nil], ["rate limiter", [4000], nil]],
"/api/v1" => [["elapsed time", [], nil], ["rate limiter", [4000], nil], ["api v1 auth", ["secret-token"], nil], ["api v1 deprecation", [Date.today], nil]],
"/api/v2" => [["elapsed time", [], nil], ["rate limiter", [4000], nil], ["api v2 auth", [], nil]],
"/:locale" => [["elapsed time", [], nil], ["set locale", [], nil]],
"/:locale/it" => [["elapsed time", [], nil], ["set locale", [], nil], ["analytics", [:it], nil]]
"/" => [["elapsed time", [], {}, nil]],
"/admin" => [["elapsed time", [], {}, nil], ["admin auth", [], {}, nil]],
"/api" => [["elapsed time", [], {}, nil], ["rate limiter", [4000], {}, nil]],
"/api/v1" => [["elapsed time", [], {}, nil], ["rate limiter", [4000], {}, nil], ["api v1 auth", ["secret-token"], {}, nil], ["api v1 deprecation", [Date.today], {}, nil]],
"/api/v2" => [["elapsed time", [], {}, nil], ["rate limiter", [4000], {}, nil], ["api v2 auth", [], {}, nil]],
"/:locale" => [["elapsed time", [], {}, nil], ["set locale", [], {}, nil]],
"/:locale/it" => [["elapsed time", [], {}, nil], ["set locale", [], {}, nil], ["analytics", [:it], {}, nil]]
}

expect(actual).to eq(expected)
Expand Down

0 comments on commit 403ad19

Please sign in to comment.