diff --git a/.travis.yml b/.travis.yml index 5845967..7b5cb0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ --- language: ruby +before_install: + - gem install bundler rvm: - ree +- 1.8.7 - 1.9.3 - 2.0.0 notifications: diff --git a/AUTHORS.md b/AUTHORS.md index dc9d92f..d750ca5 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -3,6 +3,7 @@ Redis Session Store authors - Ben Marini - Dan Buch +- Daniel Alejandro Gaytán Valencia - Donald Plummer - Edwin Cruz - Gonçalo Silva diff --git a/lib/redis-session-store.rb b/lib/redis-session-store.rb index 8b4e3be..d127e4f 100644 --- a/lib/redis-session-store.rb +++ b/lib/redis-session-store.rb @@ -18,6 +18,9 @@ class RedisSessionStore < ActionController::Session::AbstractStore def initialize(app, options = {}) super + options = symbolize_keys(options) + options[:redis] = symbolize_keys(options[:redis]) if options[:redis] + redis_options = options[:redis] || {} @default_options.merge!(:namespace => 'rack:session') @@ -26,6 +29,14 @@ def initialize(app, options = {}) end private + + def symbolize_keys(hash) + hash.inject({}) do |options, (key, value)| + options[(key.to_sym rescue key) || key] = value + options + end + end + def prefixed(sid) "#{@default_options[:key_prefix]}#{sid}" end diff --git a/test/redis_session_store_test.rb b/test/redis_session_store_test.rb index 3252b97..1443bcb 100644 --- a/test/redis_session_store_test.rb +++ b/test/redis_session_store_test.rb @@ -63,6 +63,46 @@ def options end end + describe 'when initializing with the redis sub-hash options with string keys' do + def options + { + 'key' => random_string, + 'secret' => random_string, + 'redis' => { + 'host' => 'hosty.local', + 'port' => 16379, + 'db' => 2, + 'key_prefix' => 'myapp:session:', + 'expire_after' => 60 * 120 + } + } + end + + it 'creates a redis instance' do + store.instance_variable_get(:@redis).wont_equal nil + end + + it 'assigns the :host option to @default_options' do + default_options[:host].must_equal 'hosty.local' + end + + it 'assigns the :port option to @default_options' do + default_options[:port].must_equal 16379 + end + + it 'assigns the :db option to @default_options' do + default_options[:db].must_equal 2 + end + + it 'assigns the :key_prefix option to @default_options' do + default_options[:key_prefix].must_equal 'myapp:session:' + end + + it 'assigns the :expire_after option to @default_options' do + default_options[:expire_after].must_equal 60 * 120 + end + end + describe 'when initializing with top-level redis options' do def options {