Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
---
language: ruby
before_install:
- gem install bundler
rvm:
- ree
- 1.8.7
- 1.9.3
- 2.0.0
notifications:
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Redis Session Store authors

- Ben Marini
- Dan Buch
- Daniel Alejandro Gaytán Valencia
- Donald Plummer
- Edwin Cruz
- Gonçalo Silva
Expand Down
11 changes: 11 additions & 0 deletions lib/redis-session-store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand Down
40 changes: 40 additions & 0 deletions test/redis_session_store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down