2019-04-24 06:50:00 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::NamespacedSessionStore do
|
|
|
|
let(:key) { :some_key }
|
|
|
|
|
2019-07-05 02:12:29 -04:00
|
|
|
context 'current session' do
|
|
|
|
subject { described_class.new(key) }
|
2019-04-24 06:50:00 -04:00
|
|
|
|
2019-07-05 02:12:29 -04:00
|
|
|
it 'stores data under the specified key' do
|
|
|
|
Gitlab::Session.with_session({}) do
|
|
|
|
subject[:new_data] = 123
|
|
|
|
|
|
|
|
expect(Thread.current[:session_storage][key]).to eq(new_data: 123)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves data from the given key' do
|
|
|
|
Thread.current[:session_storage] = { key => { existing_data: 123 } }
|
|
|
|
|
|
|
|
expect(subject[:existing_data]).to eq 123
|
2019-04-24 06:50:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-05 02:12:29 -04:00
|
|
|
context 'passed in session' do
|
|
|
|
let(:data) { { 'data' => 42 } }
|
|
|
|
let(:session) { { 'some_key' => data } }
|
|
|
|
|
|
|
|
subject { described_class.new(key, session.with_indifferent_access) }
|
2019-04-24 06:50:00 -04:00
|
|
|
|
2019-07-05 02:12:29 -04:00
|
|
|
it 'retrieves data from the given key' do
|
|
|
|
expect(subject['data']).to eq 42
|
|
|
|
end
|
2019-04-24 06:50:00 -04:00
|
|
|
end
|
|
|
|
end
|