diff --git a/actix-session/CHANGES.md b/actix-session/CHANGES.md index b1ea34be11..9e833f8f09 100644 --- a/actix-session/CHANGES.md +++ b/actix-session/CHANGES.md @@ -1,6 +1,9 @@ # Changes -## Unreleased - 2021-xx-xx +## Unreleased - 2022-xx-xx + - Add an `empty()` function to `Session` for simple testing. [#253] + +[#253]: https://github.com/actix/actix-extras/pull/253 ## 0.7.0 - 2022-07-09 diff --git a/actix-session/src/session.rs b/actix-session/src/session.rs index 219cdde953..d2f263b011 100644 --- a/actix-session/src/session.rs +++ b/actix-session/src/session.rs @@ -80,6 +80,17 @@ struct SessionInner { } impl Session { + /// Create an empty session. Appropriate for testing. + /// + /// This session wraps an empty state map and status. It can be instantiated for testing purposes. + pub fn empty() -> Session { + let inner = SessionInner { + state: HashMap::new(), + status: SessionStatus::default(), + }; + Session(Rc::new(RefCell::new(inner))) + } + /// Get a `value` from the session. /// /// It returns an error if it fails to deserialize as `T` the JSON value associated with `key`.