Forked from stevehodgkiss/native_columns_store.rb
Last active
December 14, 2015 04:28
-
-
Save mariovisic/5027968 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SSOServer::Application.config.session_store :active_record_store | |
ActiveRecord::SessionStore.session_class = UserSessionStore |
This file contains hidden or 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
require 'spec_helper' | |
describe UserSessionStore do | |
subject(:store) { UserSessionStore.new(session_id: '123') } | |
before do | |
store.data[:test] = 'test_data' | |
store.data[:sso_session_id] = '3' | |
store.save! | |
store.reload | |
end | |
it 'merges sso_session_id into #data' do | |
store.data[:sso_session_id].should eq '3' | |
end | |
it 'saves sso_session_id in separate column' do | |
store.sso_session_id.should eq '3' | |
end | |
it 'doesnt store sso_session_id in marshaled data column' do | |
marshaled_data = UserSessionStore.unmarshal(store.read_attribute(:data)) | |
marshaled_data.count.should eq 1 | |
marshaled_data.should have_key(:test) | |
end | |
end |
This file contains hidden or 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
class UserSessionStore < ActiveRecord::SessionStore::Session | |
def self.find_by_session_id(*args) | |
super | |
end | |
def data | |
@data ||= super.merge(:sso_session_id => sso_session_id) | |
end | |
private | |
def marshal_data! | |
return false unless loaded? | |
self.sso_session_id = data[:sso_session_id] if data[:sso_session_id].present? | |
write_attribute(@@data_column_name, self.class.marshal(data.except(:sso_session_id))) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment