User defined context store types (#339)

allow the context storage to handle any types
This commit is contained in:
Rimas Silkaitis 2017-04-06 11:43:41 -07:00 committed by Serdar Dogruyol
parent 48128696c6
commit 0b4856b741
4 changed files with 43 additions and 2 deletions

View file

@ -34,9 +34,14 @@ describe "Context" do
it "can store variables" do
before_get "/" do |env|
t = TestContextStorageType.new
t.id = 32
a = AnotherContextStorageType.new
env.set "key", "value"
env.set "before_get", "Kemal"
env.set "before_get_int", 123
env.set "before_get_context_test", t
env.set "another_context_test", a
env.set "before_get_float", 3.5
end
@ -47,6 +52,7 @@ describe "Context" do
before_get: env.get("before_get"),
before_get_int: env.get("before_get_int"),
before_get_float: env.get("before_get_float"),
before_get_context_test: env.get("before_get_context_test"),
}
end
request = HTTP::Request.new("GET", "/")
@ -59,5 +65,6 @@ describe "Context" do
context.store["before_get"].should eq "Kemal"
context.store["before_get_int"].should eq 123
context.store["before_get_float"].should eq 3.5
context.store["before_get_context_test"].as(TestContextStorageType).id.should eq 32
end
end