redis-session-store 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e789857c8192df4657d8e3f853d863c82e47931
4
- data.tar.gz: cbc1244aac8ddaa92a9248e070499d3a1aa17ba8
3
+ metadata.gz: add0c6376d9ff344003c7d062c3844bbe2400037
4
+ data.tar.gz: 7cd9506424bad86542695fc97f4072d91703ab0c
5
5
  SHA512:
6
- metadata.gz: b71a5a59e1522f06578b476e2b82503f86b66f2996a06a22ecb565fd2b9376d64c3bffe04d841f956152ded974bdfd8f9fbaad1bf1547b1ec29f634fb5906888
7
- data.tar.gz: 5ceadbf4b2c47cabe2b23960d60c0ab258459428cc9cecdc91277b525e22a50cebcde50e48463c0ebb3c5c24c27adf19d39d51ca1ecb4c3acf90014b52e50e02
6
+ metadata.gz: 0c3cb9bde3e6cc1b979575615b91a19870c4570d3cc2d543f9d38120574f4275df6eab9fdac52779d5a8ec9432e8b95e3f58642c9f1266d27ff442fab915634e
7
+ data.tar.gz: 7dc45a9772b50b2b9ee73faa38ea34ae4784f979966d8a034be9a5193c5f34a904f3862563f09894f76bcc172d2534411bc80af6f1ffe795ed453229031a1163
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-02-07 09:24:00 -0500 using RuboCop version 0.18.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offences are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ Documentation:
9
+ Enabled: false
10
+
11
+ # Offence count: 6
12
+ LineLength:
13
+ Max: 124
14
+
15
+ # Offence count: 2
16
+ # Configuration parameters: CountComments.
17
+ MethodLength:
18
+ Max: 12
data/.simplecov ADDED
@@ -0,0 +1,5 @@
1
+ if ENV['COVERAGE']
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ end
5
+ end
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ notifications:
8
+ email: false
9
+ deploy:
10
+ provider: rubygems
11
+ api_key:
12
+ secure: jL1lH/wfeRa5MoZRHvkXcZP/Ch7huFxqzbvhEV7UZhiDUBnApcJWkb346jeLEDYnFObUhqhaCZ1/l4fDeSFg2GgatSfEnoWATFVkIf1e4TTGAePlS+4qqsGOcr+XrjP6CEf4o4JACdLuSoT9dtUFj0xkFLnDWILxneXIrqDE9VU=
13
+ gem: redis-session-store
14
+ on:
15
+ tags: true
16
+ repo: roidrage/redis-session-store
17
+ branch: master
18
+ rvm: 2.0.0
data/AUTHORS.md CHANGED
@@ -6,6 +6,7 @@ Redis Session Store authors
6
6
  - Donald Plummer
7
7
  - Edwin Cruz
8
8
  - Gonçalo Silva
9
+ - Ian C. Anderson
9
10
  - Jorge Pardiñas
10
11
  - Mathias Meyer
11
12
  - Michael Fields
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in redis-session-store.gemspec
4
3
  gemspec
5
-
6
- gem 'rake', :group => :test
7
- gem 'minitest', :group => :test, :platform => :ruby_18
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Redis Session Store
2
2
  ===================
3
3
 
4
+ [![Build Status](https://travis-ci.org/roidrage/redis-session-store.png?branch=master)](https://travis-ci.org/roidrage/redis-session-store)
5
+
4
6
  A simple Redis-based session store for Rails. But why, you ask,
5
7
  when there's [redis-store](http://github.com/jodosha/redis-store/)?
6
8
  redis-store is a one-size-fits-all solution, and I found it not to work
@@ -16,6 +18,16 @@ only suitable for Rails applications. For other frameworks or
16
18
  drop-in support for caching, check out
17
19
  [redis-store](http://github.com/jodosha/redis-store/)
18
20
 
21
+ Compatibility
22
+ -------------
23
+
24
+ This gem is currently only compatible with Rails 3+. If you need
25
+ Rails 2 compatibility, be sure to pin to a lower version like so:
26
+
27
+ ``` ruby
28
+ gem 'redis-session-store', '< 0.3'
29
+ ```
30
+
19
31
  Installation
20
32
  ------------
21
33
 
@@ -27,28 +39,22 @@ Configuration
27
39
  -------------
28
40
 
29
41
  See `lib/redis-session-store.rb` for a list of valid options.
30
- Set them using:
42
+ In your Rails app, throw in an initializer with the following contents:
31
43
 
32
44
  ``` ruby
33
- ActionController::Base.session = {
45
+ My::Application.config.session_store = :redis_session_store, {
34
46
  :key => 'your_session_key',
35
- :secret => 'your_long_secret',
36
47
  :redis => {
37
48
  :db => 2,
38
49
  :expire_after => 120.minutes,
39
- :key_prefix => "myapp:session:"
50
+ :key_prefix => "myapp:session:",
51
+ :host => 'host', # Redis host name, default is localhost
52
+ :port => 12345 # Redis port, default is 6379
40
53
  }
41
54
  }
42
55
  ```
43
56
 
44
57
 
45
- In your Rails app, throw in an initializer with the following contents
46
- and the configuration above:
47
-
48
- ``` ruby
49
- ActionController::Base.session_store = RedisSessionStore
50
- ```
51
-
52
58
  Contributing, Authors, & License
53
59
  --------------------------------
54
60
 
data/Rakefile CHANGED
@@ -1,11 +1,15 @@
1
- #!/usr/bin/env rake
2
1
  require 'bundler/gem_tasks'
3
- require 'rake/testtask'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
4
 
5
- task :default => :test
5
+ task default: [:rubocop, :coverage]
6
6
 
7
- Rake::TestTask.new do |t|
8
- t.pattern = 'test/*_test.rb'
9
- t.verbose = true
10
- t.options = '-v'
7
+ RSpec::Core::RakeTask.new
8
+
9
+ desc 'Run specs with coverage'
10
+ task :coverage do
11
+ ENV['COVERAGE'] = '1'
12
+ Rake::Task['spec'].invoke
11
13
  end
14
+
15
+ Rubocop::RakeTask.new
@@ -1,3 +1,4 @@
1
+ # vim:fileencoding=utf-8
1
2
  require 'redis'
2
3
 
3
4
  # Redis session storage for Rails, and for Rails only. Derived from
@@ -5,7 +6,6 @@ require 'redis'
5
6
  #
6
7
  # Options:
7
8
  # :key => Same as with the other cookie stores, key name
8
- # :secret => Encryption secret for the key
9
9
  # :redis => {
10
10
  # :host => Redis host name, default is localhost
11
11
  # :port => Redis port, default is 6379
@@ -13,65 +13,59 @@ require 'redis'
13
13
  # :key_prefix => Prefix for keys used in Redis, e.g. myapp-. Useful to separate session storage keys visibly from others
14
14
  # :expire_after => A number in seconds to set the timeout interval for the session. Will map directly to expiry in Redis
15
15
  # }
16
- class RedisSessionStore < ActionController::Session::AbstractStore
16
+ class RedisSessionStore < ActionDispatch::Session::AbstractStore
17
+ VERSION = '0.3.0'
17
18
 
18
19
  def initialize(app, options = {})
19
20
  super
20
21
 
21
22
  redis_options = options[:redis] || {}
22
23
 
23
- @default_options.merge!(:namespace => 'rack:session')
24
+ @default_options.merge!(namespace: 'rack:session')
24
25
  @default_options.merge!(redis_options)
25
26
  @redis = Redis.new(redis_options)
26
27
  end
27
28
 
28
29
  private
29
- def prefixed(sid)
30
- "#{@default_options[:key_prefix]}#{sid}"
31
- end
32
30
 
33
- def generate_sid
34
- loop do
35
- sid = super
36
- break sid unless @redis.get(prefixed(sid))
37
- end
38
- end
31
+ attr_reader :redis, :key, :default_options
39
32
 
40
- def get_session(env, sid)
41
- unless sid && (session = load_session_from_redis(sid))
42
- sid = generate_sid
43
- session = {}
44
- end
33
+ def prefixed(sid)
34
+ "#{default_options[:key_prefix]}#{sid}"
35
+ end
45
36
 
46
- [sid, session]
37
+ def get_session(env, sid)
38
+ sid ||= generate_sid
39
+ begin
40
+ data = redis.get(prefixed(sid))
41
+ session = data.nil? ? {} : Marshal.load(data)
47
42
  rescue Errno::ECONNREFUSED
48
- [generate_sid, {}]
43
+ session = {}
49
44
  end
45
+ [sid, session]
46
+ end
50
47
 
51
- def load_session_from_redis(sid)
52
- data = @redis.get(prefixed(sid))
53
-
54
- data ? Marshal.load(data) : nil
48
+ def set_session(env, sid, session_data, options)
49
+ expiry = options[:expire_after] || nil
50
+ if expiry
51
+ redis.setex(prefixed(sid), expiry, Marshal.dump(session_data))
52
+ else
53
+ redis.set(prefixed(sid), Marshal.dump(session_data))
55
54
  end
55
+ return sid
56
+ rescue Errno::ECONNREFUSED
57
+ return false
58
+ end
56
59
 
57
- def set_session(env, sid, session_data)
58
- options = env['rack.session.options']
59
- expiry = options[:expire_after] || nil
60
- if expiry
61
- @redis.setex(prefixed(sid), expiry, Marshal.dump(session_data))
62
- else
63
- @redis.set(prefixed(sid), Marshal.dump(session_data))
64
- end
65
- return true
66
- rescue Errno::ECONNREFUSED
67
- return false
60
+ def destroy(env)
61
+ if env['rack.request.cookie_hash'] && env['rack.request.cookie_hash'][key]
62
+ redis.del(prefixed(env['rack.request.cookie_hash'][key]))
68
63
  end
69
-
70
- def destroy(env)
71
- if env['rack.request.cookie_hash'] && env['rack.request.cookie_hash'][@key]
72
- @redis.del( prefixed(env['rack.request.cookie_hash'][@key]) )
73
- end
74
- rescue Errno::ECONNREFUSED
75
- Rails.logger.warn("RedisSessionStore#destroy: Connection to redis refused")
64
+ rescue Errno::ECONNREFUSED
65
+ if defined?(Rails)
66
+ Rails.logger.warn('RedisSessionStore#destroy: Connection to redis refused')
67
+ else
68
+ warn('RedisSessionStore#destroy: Connection to redis refused')
76
69
  end
70
+ end
77
71
  end
@@ -0,0 +1,29 @@
1
+ # vim:fileencoding=utf-8
2
+ require 'English'
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'redis-session-store'
6
+ gem.authors = ['Mathias Meyer']
7
+ gem.email = ['meyer@paperplanes.de']
8
+ gem.summary = 'A drop-in replacement for e.g. MemCacheStore to ' <<
9
+ 'store Rails sessions (and Rails sessions only) in Redis.'
10
+ gem.description = gem.summary
11
+ gem.homepage = 'https://github.com/roidrage/redis-session-store'
12
+ gem.license = 'MIT'
13
+
14
+ gem.has_rdoc = true
15
+ gem.extra_rdoc_files = %w(LICENSE AUTHORS.md CONTRIBUTING.md)
16
+
17
+ gem.files = `git ls-files`.split($RS)
18
+ gem.require_paths = ['lib']
19
+ gem.version = File.read('lib/redis-session-store.rb')
20
+ .match(/^ VERSION = '(.*)'/)[1]
21
+
22
+ gem.add_runtime_dependency 'redis'
23
+
24
+ gem.add_development_dependency 'fakeredis'
25
+ gem.add_development_dependency 'rake'
26
+ gem.add_development_dependency 'rspec'
27
+ gem.add_development_dependency 'rubocop'
28
+ gem.add_development_dependency 'simplecov'
29
+ end
@@ -1,17 +1,19 @@
1
- unless defined?(ActionController::Session::AbstractStore)
2
- module ActionController
1
+ # vim:fileencoding=utf-8
2
+
3
+ unless defined?(ActionDispatch::Session::AbstractStore)
4
+ module ActionDispatch
3
5
  module Session
4
6
  class AbstractStore
5
7
  def initialize(app, options = {})
6
8
  @app = app
7
9
  @default_options = {
8
- :key => '_session_id',
9
- :path => '/',
10
- :domain => nil,
11
- :expire_after => nil,
12
- :secure => false,
13
- :httponly => true,
14
- :cookie_only => true
10
+ key: '_session_id',
11
+ path: '/',
12
+ domain: nil,
13
+ expire_after: nil,
14
+ secure: false,
15
+ httponly: true,
16
+ cookie_only: true
15
17
  }.merge(options)
16
18
  @key = @default_options[:key]
17
19
  @cookie_only = @default_options[:cookie_only]
@@ -0,0 +1,176 @@
1
+ # vim:fileencoding=utf-8
2
+
3
+ describe RedisSessionStore do
4
+ let :random_string do
5
+ "#{rand}#{rand}#{rand}"
6
+ end
7
+
8
+ let :options do
9
+ {}
10
+ end
11
+
12
+ subject(:store) { RedisSessionStore.new(nil, options) }
13
+
14
+ let :default_options do
15
+ store.instance_variable_get(:@default_options)
16
+ end
17
+
18
+ it 'assigns a :namespace to @default_options' do
19
+ default_options[:namespace].should == 'rack:session'
20
+ end
21
+
22
+ describe 'when initializing with the redis sub-hash options' do
23
+ let :options do
24
+ {
25
+ key: random_string,
26
+ secret: random_string,
27
+ redis: {
28
+ host: 'hosty.local',
29
+ port: 16_379,
30
+ db: 2,
31
+ key_prefix: 'myapp:session:',
32
+ expire_after: 60 * 120
33
+ }
34
+ }
35
+ end
36
+
37
+ it 'creates a redis instance' do
38
+ store.instance_variable_get(:@redis).should_not be_nil
39
+ end
40
+
41
+ it 'assigns the :host option to @default_options' do
42
+ default_options[:host].should == 'hosty.local'
43
+ end
44
+
45
+ it 'assigns the :port option to @default_options' do
46
+ default_options[:port].should == 16_379
47
+ end
48
+
49
+ it 'assigns the :db option to @default_options' do
50
+ default_options[:db].should == 2
51
+ end
52
+
53
+ it 'assigns the :key_prefix option to @default_options' do
54
+ default_options[:key_prefix].should == 'myapp:session:'
55
+ end
56
+
57
+ it 'assigns the :expire_after option to @default_options' do
58
+ default_options[:expire_after].should == 60 * 120
59
+ end
60
+ end
61
+
62
+ describe 'when initializing with top-level redis options' do
63
+ let :options do
64
+ {
65
+ key: random_string,
66
+ secret: random_string,
67
+ host: 'hostersons.local',
68
+ port: 26_379,
69
+ db: 4,
70
+ key_prefix: 'appydoo:session:',
71
+ expire_after: 60 * 60
72
+ }
73
+ end
74
+
75
+ it 'creates a redis instance' do
76
+ store.instance_variable_get(:@redis).should_not be_nil
77
+ end
78
+
79
+ it 'assigns the :host option to @default_options' do
80
+ default_options[:host].should == 'hostersons.local'
81
+ end
82
+
83
+ it 'assigns the :port option to @default_options' do
84
+ default_options[:port].should == 26_379
85
+ end
86
+
87
+ it 'assigns the :db option to @default_options' do
88
+ default_options[:db].should == 4
89
+ end
90
+
91
+ it 'assigns the :key_prefix option to @default_options' do
92
+ default_options[:key_prefix].should == 'appydoo:session:'
93
+ end
94
+
95
+ it 'assigns the :expire_after option to @default_options' do
96
+ default_options[:expire_after].should == 60 * 60
97
+ end
98
+ end
99
+
100
+ describe 'rack 1.45 compatibility' do
101
+ # Rack 1.45 (which Rails 3.2.x depends on) uses the return value of set_session to set the cookie value
102
+ # See https://github.com/rack/rack/blob/1.4.5/lib/rack/session/abstract/id.rb
103
+
104
+ let(:env) { double('env') }
105
+ let(:session_id) { 12_345 }
106
+ let(:session_data) { double('session_data') }
107
+ let(:options) { { expire_after: 123 } }
108
+
109
+ context 'when successfully persisting the session' do
110
+
111
+ it 'returns the session id' do
112
+ store.send(:set_session, env, session_id, session_data, options).should eq(session_id)
113
+ end
114
+
115
+ end
116
+
117
+ context 'when unsuccessfully persisting the session' do
118
+ before do
119
+ store.stub(:redis).and_raise(Errno::ECONNREFUSED)
120
+ end
121
+
122
+ it 'returns false' do
123
+ store.send(:set_session, env, session_id, session_data, options).should eq(false)
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ describe 'fetching a session' do
130
+ let :options do
131
+ {
132
+ key_prefix: 'customprefix::'
133
+ }
134
+ end
135
+ let(:fake_key) { 'thisisarediskey' }
136
+
137
+ it 'should retrieve the prefixed key from redis' do
138
+ redis = double('redis')
139
+ store.stub(redis: redis)
140
+ expect(redis).to receive(:get).with("#{options[:key_prefix]}#{fake_key}")
141
+
142
+ store.send(:get_session, double('env'), fake_key)
143
+ end
144
+
145
+ context 'when redis is down' do
146
+
147
+ it 'should return an empty session hash' do
148
+ store.stub(:redis).and_raise(Errno::ECONNREFUSED)
149
+
150
+ expect(store.send(:get_session, double('env'), fake_key)).to eq([fake_key, {}])
151
+ end
152
+ end
153
+ end
154
+
155
+ describe 'destroying a session' do
156
+ context 'when the key is in the cookie hash' do
157
+ let(:env) { { 'rack.request.cookie_hash' => cookie_hash } }
158
+ let(:cookie_hash) { double('cookie hash') }
159
+ let(:fake_key) { 'thisisarediskey' }
160
+
161
+ before do
162
+ cookie_hash.stub(:[] => fake_key)
163
+ end
164
+
165
+ it 'should delete the prefixed key from redis' do
166
+ redis = double('redis')
167
+ store.stub(redis: redis)
168
+ expect(redis).to receive(:del).with("#{options[:key_prefix]}#{fake_key}")
169
+
170
+ store.send(:destroy, env)
171
+ end
172
+
173
+ end
174
+
175
+ end
176
+ end
@@ -0,0 +1,6 @@
1
+ # vim:fileencoding=utf-8
2
+
3
+ require 'simplecov'
4
+ require_relative 'fake_action_dispatch_session_abstract_store'
5
+ require 'fakeredis/rspec'
6
+ require 'redis-session-store'
metadata CHANGED
@@ -1,27 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-session-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fakeredis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
25
95
  - !ruby/object:Gem::Version
26
96
  version: '0'
27
97
  description: A drop-in replacement for e.g. MemCacheStore to store Rails sessions
@@ -35,6 +105,11 @@ extra_rdoc_files:
35
105
  - AUTHORS.md
36
106
  - CONTRIBUTING.md
37
107
  files:
108
+ - .gitignore
109
+ - .rspec
110
+ - .rubocop.yml
111
+ - .simplecov
112
+ - .travis.yml
38
113
  - AUTHORS.md
39
114
  - CONTRIBUTING.md
40
115
  - Gemfile
@@ -42,8 +117,10 @@ files:
42
117
  - README.md
43
118
  - Rakefile
44
119
  - lib/redis-session-store.rb
45
- - test/fake_action_controller_session_abstract_store.rb
46
- - test/redis_session_store_test.rb
120
+ - redis-session-store.gemspec
121
+ - spec/fake_action_dispatch_session_abstract_store.rb
122
+ - spec/redis_session_store_spec.rb
123
+ - spec/spec_helper.rb
47
124
  homepage: https://github.com/roidrage/redis-session-store
48
125
  licenses:
49
126
  - MIT
@@ -54,17 +131,17 @@ require_paths:
54
131
  - lib
55
132
  required_ruby_version: !ruby/object:Gem::Requirement
56
133
  requirements:
57
- - - ">="
134
+ - - '>='
58
135
  - !ruby/object:Gem::Version
59
136
  version: '0'
60
137
  required_rubygems_version: !ruby/object:Gem::Requirement
61
138
  requirements:
62
- - - ">="
139
+ - - '>='
63
140
  - !ruby/object:Gem::Version
64
141
  version: '0'
65
142
  requirements: []
66
143
  rubyforge_project:
67
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.0.3
68
145
  signing_key:
69
146
  specification_version: 4
70
147
  summary: A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and
@@ -1,103 +0,0 @@
1
- require 'minitest/autorun'
2
- require File.expand_path('../fake_action_controller_session_abstract_store', __FILE__)
3
- require 'redis-session-store'
4
-
5
- describe RedisSessionStore do
6
- def random_string
7
- "#{rand}#{rand}#{rand}"
8
- end
9
-
10
- def options
11
- {}
12
- end
13
-
14
- def store
15
- RedisSessionStore.new(nil, options)
16
- end
17
-
18
- def default_options
19
- store.instance_variable_get(:@default_options)
20
- end
21
-
22
- it 'assigns a :namespace to @default_options' do
23
- default_options[:namespace].must_equal 'rack:session'
24
- end
25
-
26
- describe 'when initializing with the redis sub-hash options' do
27
- def options
28
- {
29
- :key => random_string,
30
- :secret => random_string,
31
- :redis => {
32
- :host => 'hosty.local',
33
- :port => 16379,
34
- :db => 2,
35
- :key_prefix => 'myapp:session:',
36
- :expire_after => 60 * 120
37
- }
38
- }
39
- end
40
-
41
- it 'creates a redis instance' do
42
- store.instance_variable_get(:@redis).wont_equal nil
43
- end
44
-
45
- it 'assigns the :host option to @default_options' do
46
- default_options[:host].must_equal 'hosty.local'
47
- end
48
-
49
- it 'assigns the :port option to @default_options' do
50
- default_options[:port].must_equal 16379
51
- end
52
-
53
- it 'assigns the :db option to @default_options' do
54
- default_options[:db].must_equal 2
55
- end
56
-
57
- it 'assigns the :key_prefix option to @default_options' do
58
- default_options[:key_prefix].must_equal 'myapp:session:'
59
- end
60
-
61
- it 'assigns the :expire_after option to @default_options' do
62
- default_options[:expire_after].must_equal 60 * 120
63
- end
64
- end
65
-
66
- describe 'when initializing with top-level redis options' do
67
- def options
68
- {
69
- :key => random_string,
70
- :secret => random_string,
71
- :host => 'hostersons.local',
72
- :port => 26379,
73
- :db => 4,
74
- :key_prefix => 'appydoo:session:',
75
- :expire_after => 60 * 60
76
- }
77
- end
78
-
79
- it 'creates a redis instance' do
80
- store.instance_variable_get(:@redis).wont_equal nil
81
- end
82
-
83
- it 'assigns the :host option to @default_options' do
84
- default_options[:host].must_equal 'hostersons.local'
85
- end
86
-
87
- it 'assigns the :port option to @default_options' do
88
- default_options[:port].must_equal 26379
89
- end
90
-
91
- it 'assigns the :db option to @default_options' do
92
- default_options[:db].must_equal 4
93
- end
94
-
95
- it 'assigns the :key_prefix option to @default_options' do
96
- default_options[:key_prefix].must_equal 'appydoo:session:'
97
- end
98
-
99
- it 'assigns the :expire_after option to @default_options' do
100
- default_options[:expire_after].must_equal 60 * 60
101
- end
102
- end
103
- end