Skip to content

Commit a3b09fb

Browse files
committed
Refactor session store configuration; add session method to retrieve store and ensure proper setup
1 parent 3609930 commit a3b09fb

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

spec/spec_helper.cr

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ class UserSession < Session::Base
2222
property username : String? = "example"
2323
end
2424

25-
# Crystal 1.19+ needs a concrete type for @store since the library
26-
# declares `property store = nil` (no type annotation).
27-
# Provide the type so specs compile.
28-
class Session::Configuration
29-
@store : Session::MemoryStore(UserSession)? = nil
30-
end
25+
Session.use_store(Session::MemoryStore(UserSession))
3126

3227
# Reset configuration to defaults before each test
3328
def reset_config

src/session.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ module Session
125125
macro use_store(store_type)
126126
class Session::Configuration
127127
property store : {{store_type}}? = nil
128+
129+
def session : {{store_type}}
130+
@store || raise "Session store not configured. Call Session.configure and set c.store before using Session.session."
131+
end
128132
end
129133
end
130134

0 commit comments

Comments
 (0)