diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2019-04-24 17:50:00 +0700 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2019-05-02 12:28:26 +0700 |
commit | 5faa98f481e0f5e0ccb1758c34a104f523ab21d2 (patch) | |
tree | 3119efc05e2ecc91cc0d91217c0869b69f656ea6 /spec/lib/gitlab/session_spec.rb | |
parent | 0f863c68bb8bc5054a22e0c553a933c83bea4df6 (diff) | |
download | gitlab-ce-5faa98f481e0f5e0ccb1758c34a104f523ab21d2.tar.gz |
Session stored globally per requestjej/session-stored-globaly
- This can be accessed with Session.current and is restored after.
- Data can be stored under a key with NamespacedSessionStore
Diffstat (limited to 'spec/lib/gitlab/session_spec.rb')
-rw-r--r-- | spec/lib/gitlab/session_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/lib/gitlab/session_spec.rb b/spec/lib/gitlab/session_spec.rb new file mode 100644 index 00000000000..8db73f0ec7b --- /dev/null +++ b/spec/lib/gitlab/session_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Session do + it 'uses the current thread as a data store' do + Thread.current[:session_storage] = { a: :b } + + expect(described_class.current).to eq(a: :b) + ensure + Thread.current[:session_storage] = nil + end + + describe '#with_session' do + it 'sets session hash' do + described_class.with_session(one: 1) do + expect(described_class.current).to eq(one: 1) + end + end + + it 'restores current store after' do + described_class.with_session(two: 2) { } + + expect(described_class.current).to eq nil + end + end +end |