mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Add context store
This commit is contained in:
parent
c9714faab3
commit
09d82ed74b
2 changed files with 40 additions and 1 deletions
|
@ -40,4 +40,32 @@ describe "Context" do
|
|||
client_response = call_request_on_app(request)
|
||||
client_response.headers["Accept-Language"].should eq "tr"
|
||||
end
|
||||
end
|
||||
|
||||
it "can store variables" do
|
||||
before_get "/" do |env|
|
||||
env.set "before_get", "Kemal"
|
||||
env.set "before_get_int", 123
|
||||
env.set "before_get_float", 3.5
|
||||
end
|
||||
|
||||
get "/" do |env|
|
||||
env.set "key", "value"
|
||||
{
|
||||
key: env.get("key"),
|
||||
before_get: env.get("before_get"),
|
||||
before_get_int: env.get("before_get_int"),
|
||||
before_get_float: env.get("before_get_float")
|
||||
}
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/")
|
||||
io = MemoryIO.new
|
||||
response = HTTP::Server::Response.new(io)
|
||||
context = HTTP::Server::Context.new(request, response)
|
||||
Kemal::Middleware::Filter::INSTANCE.call(context)
|
||||
Kemal::RouteHandler::INSTANCE.call(context)
|
||||
context.store["key"].should eq "value"
|
||||
context.store["before_get"].should eq "Kemal"
|
||||
context.store["before_get_int"].should eq 123
|
||||
context.store["before_get_float"].should eq 3.5
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue