This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
372 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "./spec_helper" | ||
|
||
describe "Session" do | ||
describe ".start" do | ||
it "returns a Session instance" do | ||
typeof(Session.start(create_context("foo"))).should eq Session | ||
end | ||
end | ||
|
||
describe ".int" do | ||
it "can save a value" do | ||
session = Session.start(create_context("foo")) | ||
session.int("bar", 12) | ||
end | ||
|
||
it "can retrieve a saved value" do | ||
session = Session.start(create_context("foo")) | ||
session.int("bar").should eq 12 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "./spec_helper" | ||
|
||
describe "Session" do | ||
describe "::Config" do | ||
describe "::INSTANCE" do | ||
it "returns a Session::Config object" do | ||
typeof(Session::Config::INSTANCE).should eq Session::Config | ||
end | ||
end | ||
end | ||
|
||
describe ".config" do | ||
it "returns Session::Config::INSTANCE" do | ||
Session.config.should be Session::Config::INSTANCE | ||
end | ||
|
||
it "yields Session::Config::INSTANCE" do | ||
Session.config do |config| | ||
config.should be Session::Config::INSTANCE | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "./spec_helper.cr" | ||
|
||
describe "Session" do | ||
describe ".id_from_context" do | ||
it "returns a set session id from the context" do | ||
context = create_context("session id") | ||
Session.id_from_context(context).should eq "session id" | ||
end | ||
|
||
it "returns nil if there is no session cookie" do | ||
context = create_context("") | ||
Session.id_from_context(context).should be_nil | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "../spec_helper.cr" | ||
|
||
describe "Session::FileSystemEngine" do | ||
describe "options" do | ||
describe ":sessions_dir" do | ||
it "raises an ArgumentError if option not passed" do | ||
expect_raises(ArgumentError) do | ||
Session::FileSystemEngine.new({no: "option"}) | ||
end | ||
end | ||
|
||
it "raises an ArgumentError if the directory does not exist" do | ||
expect_raises(ArgumentError) do | ||
Session::FileSystemEngine.new({sessions_dir: "foobar"}) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
require "spec" | ||
require "kemal" | ||
require "../src/kemal-session" | ||
require "http" | ||
|
||
Spec.before_each do | ||
fake_context = HTTP::Server::Context.new(HTTP::Request.new("hello", nil), HTTP::Server::Response.new("ha")) | ||
$session = Session.start(fake_context) | ||
def create_context(session_id : String) | ||
response = HTTP::Server::Response.new(MemoryIO.new) | ||
headers = HTTP::Headers.new | ||
|
||
# I would rather pass nil if no cookie should be created | ||
# but that throws an error | ||
unless session_id == "" | ||
cookies = HTTP::Cookies.new | ||
cookies << HTTP::Cookie.new(Session.config.cookie_name, session_id) | ||
cookies.add_request_headers(headers) | ||
end | ||
|
||
request = HTTP::Request.new("GET", "/" , headers) | ||
return HTTP::Server::Context.new(request, response) | ||
end | ||
|
||
Session.config.engine = Session::FileSystemEngine.new({sessions_dir: "./spec/assets/sessions/"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require "./kemal-session/*" | ||
require "./kemal-session/engines/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.