From a8e53fb94e51f534e418c9b4dc83b85087713dc9 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Thu, 29 Sep 2016 22:48:19 +0300 Subject: [PATCH] Session also supports arrays --- spec/session_spec.cr | 33 +++++++++++++++++++++++++++++++++ src/kemal/session.cr | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/spec/session_spec.cr b/spec/session_spec.cr index 3414def..8d86cf8 100644 --- a/spec/session_spec.cr +++ b/spec/session_spec.cr @@ -53,4 +53,37 @@ describe "Session" do Kemal::Sessions.prune! s.size.should eq(0) end + + it "supports many types" do + who = nil + age = nil + awesome = nil + velocity = nil + arr = nil + get "/" do |env| + sess = env.session + who = sess["who"]? + age = sess["age"]? + velocity = sess["velocity"]? + awesome = sess["awesome"]? + arr = sess["arr"]? + sess["who"] = "Kemal" + sess["age"] = 2016 + sess["velocity"] = 9999.9 + sess["awesome"] = true + sess["arr"] = [1, "Serdar", true, 90000.0] + "Hello" + end + + request = HTTP::Request.new("GET", "/") + response = call_request_on_app(request) + request = HTTP::Request.new("GET", "/", response.headers) + response = call_request_on_app(request) + + who.should eq "Kemal" + age.should eq 2016 + velocity.should eq 9999.9 + awesome.should eq true + arr.should eq [1, "Serdar", true, 90000.0] + end end diff --git a/src/kemal/session.cr b/src/kemal/session.cr index cc21938..96d86bc 100644 --- a/src/kemal/session.cr +++ b/src/kemal/session.cr @@ -16,7 +16,7 @@ module Kemal # Sessions are pruned hourly after 48 hours of inactivity. class Sessions # Session Types are String, Integer, Float and Boolean - alias SessionTypes = String | Int64 | Float64 | Bool + alias SessionTypes = String | Int32 | Float64 | Bool | Array(String | Int32 | Float64 | Bool) # In-memory, ephemeral datastore only. #