redis-session-store 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -11
- data/.rubocop_todo.yml +11 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -0
- data/README.md +12 -3
- data/Rakefile +2 -1
- data/lib/redis-session-store.rb +10 -7
- data/redis-session-store.gemspec +2 -1
- data/spec/redis_session_store_spec.rb +109 -69
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43c209eb4dbc6cc3feedd7138dcc6cfbb6e4be35
|
4
|
+
data.tar.gz: e29f05d4800a9bf8453ad3f24504295d5fd21408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91de3d098790b0d015bb463ecf28a21d5b84ba1eee2d7a2e8b2b6646231e6265b2c1933d99e825aa0ac8fa03945409b5b3ef03429e1d1599d8239f471f2ce1f0
|
7
|
+
data.tar.gz: 5797ce680e25ccb54e48cb4b5e2720be2287e7facedec7c28940b54a7f8fb1aa1bac91553797a01a02176650058032c3708e89b53b3d8506511472667620f7b7
|
data/.rubocop.yml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
|
-
|
2
|
-
# on 2014-03-13 18:57:37 -0400 using RuboCop version 0.19.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses 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.
|
1
|
+
inherit_from: .rubocop_todo.yml
|
7
2
|
|
8
|
-
# Offense count: 1
|
9
3
|
FileName:
|
10
4
|
Enabled: false
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
ClassLength:
|
15
|
-
Max: 110
|
6
|
+
DoubleNegation:
|
7
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-08-28 08:17:48 -0400 using RuboCop version 0.25.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses 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
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: CountComments.
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 101
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
redis-session-store history
|
2
2
|
===========================
|
3
3
|
|
4
|
+
## v0.8.0 (2014-08-28)
|
5
|
+
|
6
|
+
* Allow for injection of custom redis client
|
7
|
+
* Explicitly declare actionpack dependency
|
8
|
+
* Spec updates for rspec 3
|
9
|
+
|
4
10
|
## v0.7.0 (2014-04-22)
|
5
11
|
|
6
12
|
* Fix issue #38, we now delay writing to redis until a session exists. This is
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,12 @@ see fit.
|
|
18
18
|
This library doesn't offer anything related to caching, and is
|
19
19
|
only suitable for Rails applications. For other frameworks or
|
20
20
|
drop-in support for caching, check out
|
21
|
-
[redis-store](http://github.com/jodosha/redis-store/)
|
21
|
+
[redis-store](http://github.com/jodosha/redis-store/).
|
22
22
|
|
23
23
|
Installation
|
24
24
|
------------
|
25
25
|
|
26
|
-
For Rails 3+, adding this to your Gemfile will do the trick.
|
26
|
+
For Rails 3+, adding this to your `Gemfile` will do the trick.
|
27
27
|
|
28
28
|
``` ruby
|
29
29
|
gem 'redis-session-store'
|
@@ -57,6 +57,9 @@ callable handler may be provided as `on_redis_down`:
|
|
57
57
|
My::Application.config.session_store :redis_session_store, {
|
58
58
|
# ... other options ...
|
59
59
|
on_redis_down: ->(e, env, sid) { do_something_will_ya!(e) }
|
60
|
+
redis: {
|
61
|
+
# ... redis options ...
|
62
|
+
}
|
60
63
|
}
|
61
64
|
```
|
62
65
|
|
@@ -74,11 +77,14 @@ custom serializer:
|
|
74
77
|
My::Application.config.session_store :redis_session_store, {
|
75
78
|
# ... other options ...
|
76
79
|
serializer: :hybrid
|
80
|
+
redis: {
|
81
|
+
# ... redis options ...
|
82
|
+
}
|
77
83
|
}
|
78
84
|
```
|
79
85
|
|
80
86
|
**Note**: Rails 4 is required for using the `:json` and `:hybrid` serializers
|
81
|
-
because the `Flash` object doesn't
|
87
|
+
because the `Flash` object doesn't serialize well in 3.2. See [Rails #13945](https://github.com/rails/rails/pull/13945) for more info.
|
82
88
|
|
83
89
|
### Session load error handling
|
84
90
|
|
@@ -90,6 +96,9 @@ will be given the error and the session ID.
|
|
90
96
|
My::Application.config.session_store :redis_session_store, {
|
91
97
|
# ... other options ...
|
92
98
|
on_session_load_error: ->(e, sid) { do_something_will_ya!(e) }
|
99
|
+
redis: {
|
100
|
+
# ... redis options ...
|
101
|
+
}
|
93
102
|
}
|
94
103
|
```
|
95
104
|
|
data/Rakefile
CHANGED
data/lib/redis-session-store.rb
CHANGED
@@ -4,7 +4,7 @@ require 'redis'
|
|
4
4
|
# Redis session storage for Rails, and for Rails only. Derived from
|
5
5
|
# the MemCacheStore code, simply dropping in Redis instead.
|
6
6
|
class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
7
|
-
VERSION = '0.
|
7
|
+
VERSION = '0.8.0'
|
8
8
|
# Rails 3.1 and beyond defines the constant elsewhere
|
9
9
|
unless defined?(ENV_SESSION_OPTIONS_KEY)
|
10
10
|
ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
|
@@ -18,6 +18,7 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
18
18
|
# * +:db+ - Database number, defaults to 0.
|
19
19
|
# * +:key_prefix+ - Prefix for keys used in Redis, e.g. +myapp:+
|
20
20
|
# * +:expire_after+ - A number in seconds for session timeout
|
21
|
+
# * +:client+ - Connect to Redis with given object rather than create one
|
21
22
|
# * +:on_redis_down:+ - Called with err, env, and SID on Errno::ECONNREFUSED
|
22
23
|
# * +:on_session_load_error:+ - Called with err and SID on Marshal.load fail
|
23
24
|
# * +:serializer:+ - Serializer to use on session data, default is :marshal.
|
@@ -44,7 +45,7 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
44
45
|
|
45
46
|
@default_options.merge!(namespace: 'rack:session')
|
46
47
|
@default_options.merge!(redis_options)
|
47
|
-
@redis = Redis.new(redis_options)
|
48
|
+
@redis = redis_options[:client] || Redis.new(redis_options)
|
48
49
|
@on_redis_down = options[:on_redis_down]
|
49
50
|
@serializer = determine_serializer(options[:serializer])
|
50
51
|
@on_session_load_error = options[:on_session_load_error]
|
@@ -64,8 +65,10 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
64
65
|
def session_exists?(env)
|
65
66
|
value = current_session_id(env)
|
66
67
|
|
67
|
-
|
68
|
-
|
68
|
+
!!(
|
69
|
+
value && !value.empty? &&
|
70
|
+
redis.exists(prefixed(value))
|
71
|
+
)
|
69
72
|
rescue Errno::ECONNREFUSED => e
|
70
73
|
on_redis_down.call(e, env, value) if on_redis_down
|
71
74
|
|
@@ -74,9 +77,9 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
74
77
|
|
75
78
|
def verify_handlers!
|
76
79
|
%w(on_redis_down on_session_load_error).each do |h|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
next unless (handler = public_send(h)) && !handler.respond_to?(:call)
|
81
|
+
|
82
|
+
fail ArgumentError, "#{h} handler is not callable"
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
data/redis-session-store.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
|
|
4
4
|
gem.name = 'redis-session-store'
|
5
5
|
gem.authors = ['Mathias Meyer']
|
6
6
|
gem.email = ['meyer@paperplanes.de']
|
7
|
-
gem.summary = 'A drop-in replacement for e.g. MemCacheStore to '
|
7
|
+
gem.summary = 'A drop-in replacement for e.g. MemCacheStore to ' \
|
8
8
|
'store Rails sessions (and Rails sessions only) in Redis.'
|
9
9
|
gem.description = gem.summary
|
10
10
|
gem.homepage = 'https://github.com/roidrage/redis-session-store'
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
.match(/^ VERSION = '(.*)'/)[1]
|
20
20
|
|
21
21
|
gem.add_runtime_dependency 'redis'
|
22
|
+
gem.add_runtime_dependency 'actionpack', '>= 3', '< 5'
|
22
23
|
|
23
24
|
gem.add_development_dependency 'fakeredis'
|
24
25
|
gem.add_development_dependency 'rake'
|
@@ -17,7 +17,7 @@ describe RedisSessionStore do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'assigns a :namespace to @default_options' do
|
20
|
-
default_options[:namespace].
|
20
|
+
expect(default_options[:namespace]).to eq('rack:session')
|
21
21
|
end
|
22
22
|
|
23
23
|
describe 'when initializing with the redis sub-hash options' do
|
@@ -36,27 +36,27 @@ describe RedisSessionStore do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'creates a redis instance' do
|
39
|
-
store.instance_variable_get(:@redis).
|
39
|
+
expect(store.instance_variable_get(:@redis)).to_not be_nil
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'assigns the :host option to @default_options' do
|
43
|
-
default_options[:host].
|
43
|
+
expect(default_options[:host]).to eq('hosty.local')
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'assigns the :port option to @default_options' do
|
47
|
-
default_options[:port].
|
47
|
+
expect(default_options[:port]).to eq(16_379)
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'assigns the :db option to @default_options' do
|
51
|
-
default_options[:db].
|
51
|
+
expect(default_options[:db]).to eq(2)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'assigns the :key_prefix option to @default_options' do
|
55
|
-
default_options[:key_prefix].
|
55
|
+
expect(default_options[:key_prefix]).to eq('myapp:session:')
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'assigns the :expire_after option to @default_options' do
|
59
|
-
default_options[:expire_after].
|
59
|
+
expect(default_options[:expire_after]).to eq(60 * 120)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -74,27 +74,59 @@ describe RedisSessionStore do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'creates a redis instance' do
|
77
|
-
store.instance_variable_get(:@redis).
|
77
|
+
expect(store.instance_variable_get(:@redis)).to_not be_nil
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'assigns the :host option to @default_options' do
|
81
|
-
default_options[:host].
|
81
|
+
expect(default_options[:host]).to eq('hostersons.local')
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'assigns the :port option to @default_options' do
|
85
|
-
default_options[:port].
|
85
|
+
expect(default_options[:port]).to eq(26_379)
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'assigns the :db option to @default_options' do
|
89
|
-
default_options[:db].
|
89
|
+
expect(default_options[:db]).to eq(4)
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'assigns the :key_prefix option to @default_options' do
|
93
|
-
default_options[:key_prefix].
|
93
|
+
expect(default_options[:key_prefix]).to eq('appydoo:session:')
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'assigns the :expire_after option to @default_options' do
|
97
|
-
default_options[:expire_after].
|
97
|
+
expect(default_options[:expire_after]).to eq(60 * 60)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'when initializing with existing redis object' do
|
102
|
+
let :options do
|
103
|
+
{
|
104
|
+
key: random_string,
|
105
|
+
secret: random_string,
|
106
|
+
redis: {
|
107
|
+
client: redis_client,
|
108
|
+
key_prefix: 'myapp:session:',
|
109
|
+
expire_after: 60 * 30
|
110
|
+
}
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
let(:redis_client) { double('redis_client') }
|
115
|
+
|
116
|
+
it 'assigns given redis object to @redis' do
|
117
|
+
expect(store.instance_variable_get(:@redis)).to be(redis_client)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'assigns the :client option to @default_options' do
|
121
|
+
expect(default_options[:client]).to be(redis_client)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'assigns the :key_prefix option to @default_options' do
|
125
|
+
expect(default_options[:key_prefix]).to eq('myapp:session:')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'assigns the :expire_after option to @default_options' do
|
129
|
+
expect(default_options[:expire_after]).to eq(60 * 30)
|
98
130
|
end
|
99
131
|
end
|
100
132
|
|
@@ -110,19 +142,19 @@ describe RedisSessionStore do
|
|
110
142
|
|
111
143
|
context 'when successfully persisting the session' do
|
112
144
|
it 'returns the session id' do
|
113
|
-
store.send(:set_session, env, session_id, session_data, options)
|
114
|
-
.
|
145
|
+
expect(store.send(:set_session, env, session_id, session_data, options))
|
146
|
+
.to eq(session_id)
|
115
147
|
end
|
116
148
|
end
|
117
149
|
|
118
150
|
context 'when unsuccessfully persisting the session' do
|
119
151
|
before do
|
120
|
-
store.
|
152
|
+
allow(store).to receive(:redis).and_raise(Errno::ECONNREFUSED)
|
121
153
|
end
|
122
154
|
|
123
155
|
it 'returns false' do
|
124
|
-
store.send(:set_session, env, session_id, session_data, options)
|
125
|
-
.
|
156
|
+
expect(store.send(:set_session, env, session_id, session_data, options))
|
157
|
+
.to eq(false)
|
126
158
|
end
|
127
159
|
end
|
128
160
|
|
@@ -130,25 +162,25 @@ describe RedisSessionStore do
|
|
130
162
|
let(:options) { {} }
|
131
163
|
|
132
164
|
it 'sets the session value without expiry' do
|
133
|
-
store.send(:set_session, env, session_id, session_data, options)
|
134
|
-
.
|
165
|
+
expect(store.send(:set_session, env, session_id, session_data, options))
|
166
|
+
.to eq(session_id)
|
135
167
|
end
|
136
168
|
end
|
137
169
|
|
138
170
|
context 'when redis is down' do
|
139
171
|
before do
|
140
|
-
store.
|
141
|
-
store.on_redis_down = ->(*
|
172
|
+
allow(store).to receive(:redis).and_raise(Errno::ECONNREFUSED)
|
173
|
+
store.on_redis_down = ->(*_a) { @redis_down_handled = true }
|
142
174
|
end
|
143
175
|
|
144
176
|
it 'returns false' do
|
145
|
-
store.send(:set_session, env, session_id, session_data, options)
|
146
|
-
.
|
177
|
+
expect(store.send(:set_session, env, session_id, session_data, options))
|
178
|
+
.to eq(false)
|
147
179
|
end
|
148
180
|
|
149
181
|
it 'calls the on_redis_down handler' do
|
150
182
|
store.send(:set_session, env, session_id, session_data, options)
|
151
|
-
expect(@redis_down_handled).to
|
183
|
+
expect(@redis_down_handled).to eq(true)
|
152
184
|
end
|
153
185
|
|
154
186
|
context 'when :on_redis_down re-raises' do
|
@@ -167,47 +199,52 @@ describe RedisSessionStore do
|
|
167
199
|
let(:session_id) { 'foo' }
|
168
200
|
|
169
201
|
before do
|
170
|
-
store.
|
202
|
+
allow(store).to receive(:current_session_id)
|
203
|
+
.with(:env).and_return(session_id)
|
171
204
|
end
|
172
205
|
|
173
206
|
context 'when session id is not provided' do
|
174
207
|
context 'when session id is nil' do
|
175
208
|
let(:session_id) { nil }
|
176
|
-
it '
|
177
|
-
store.send(:session_exists?, :env).
|
209
|
+
it 'returns false' do
|
210
|
+
expect(store.send(:session_exists?, :env)).to eq(false)
|
178
211
|
end
|
179
212
|
end
|
180
213
|
|
181
214
|
context 'when session id is empty string' do
|
182
215
|
let(:session_id) { '' }
|
183
|
-
it '
|
184
|
-
store.
|
185
|
-
store.send(:session_exists?, :env).
|
216
|
+
it 'returns false' do
|
217
|
+
allow(store).to receive(:current_session_id).with(:env).and_return('')
|
218
|
+
expect(store.send(:session_exists?, :env)).to eq(false)
|
186
219
|
end
|
187
220
|
end
|
188
221
|
end
|
189
222
|
|
190
223
|
context 'when session id is provided' do
|
191
|
-
let(:redis)
|
224
|
+
let(:redis) do
|
225
|
+
double('redis').tap do |o|
|
226
|
+
allow(store).to receive(:redis).and_return(o)
|
227
|
+
end
|
228
|
+
end
|
192
229
|
|
193
230
|
context 'when session id does not exist in redis' do
|
194
|
-
it '
|
195
|
-
redis.
|
196
|
-
store.send(:session_exists?, :env).
|
231
|
+
it 'returns false' do
|
232
|
+
expect(redis).to receive(:exists).with('foo').and_return(false)
|
233
|
+
expect(store.send(:session_exists?, :env)).to eq(false)
|
197
234
|
end
|
198
235
|
end
|
199
236
|
|
200
237
|
context 'when session id exists in redis' do
|
201
|
-
it '
|
202
|
-
redis.
|
203
|
-
store.send(:session_exists?, :env).
|
238
|
+
it 'returns true' do
|
239
|
+
expect(redis).to receive(:exists).with('foo').and_return(true)
|
240
|
+
expect(store.send(:session_exists?, :env)).to eq(true)
|
204
241
|
end
|
205
242
|
end
|
206
243
|
|
207
244
|
context 'when redis is down' do
|
208
|
-
it '
|
209
|
-
store.
|
210
|
-
store.send(:session_exists?, :env).
|
245
|
+
it 'returns true (fallback to old behavior)' do
|
246
|
+
allow(store).to receive(:redis).and_raise(Errno::ECONNREFUSED)
|
247
|
+
expect(store.send(:session_exists?, :env)).to eq(true)
|
211
248
|
end
|
212
249
|
end
|
213
250
|
end
|
@@ -222,10 +259,10 @@ describe RedisSessionStore do
|
|
222
259
|
|
223
260
|
let(:fake_key) { 'thisisarediskey' }
|
224
261
|
|
225
|
-
it '
|
262
|
+
it 'retrieves the prefixed key from redis' do
|
226
263
|
redis = double('redis')
|
227
|
-
store.
|
228
|
-
store.
|
264
|
+
allow(store).to receive(:redis).and_return(redis)
|
265
|
+
allow(store).to receive(:generate_sid).and_return(fake_key)
|
229
266
|
expect(redis).to receive(:get).with("#{options[:key_prefix]}#{fake_key}")
|
230
267
|
|
231
268
|
store.send(:get_session, double('env'), fake_key)
|
@@ -233,8 +270,8 @@ describe RedisSessionStore do
|
|
233
270
|
|
234
271
|
context 'when redis is down' do
|
235
272
|
before do
|
236
|
-
store.
|
237
|
-
store.
|
273
|
+
allow(store).to receive(:redis).and_raise(Errno::ECONNREFUSED)
|
274
|
+
allow(store).to receive(:generate_sid).and_return('foop')
|
238
275
|
end
|
239
276
|
|
240
277
|
it 'returns an empty session hash' do
|
@@ -266,12 +303,12 @@ describe RedisSessionStore do
|
|
266
303
|
let(:fake_key) { 'thisisarediskey' }
|
267
304
|
|
268
305
|
before do
|
269
|
-
cookie_hash.
|
306
|
+
allow(cookie_hash).to receive(:[]).and_return(fake_key)
|
270
307
|
end
|
271
308
|
|
272
309
|
it 'deletes the prefixed key from redis' do
|
273
310
|
redis = double('redis')
|
274
|
-
store.
|
311
|
+
allow(store).to receive(:redis).and_return(redis)
|
275
312
|
expect(redis).to receive(:del)
|
276
313
|
.with("#{options[:key_prefix]}#{fake_key}")
|
277
314
|
|
@@ -279,10 +316,12 @@ describe RedisSessionStore do
|
|
279
316
|
end
|
280
317
|
|
281
318
|
context 'when redis is down' do
|
282
|
-
before
|
319
|
+
before do
|
320
|
+
allow(store).to receive(:redis).and_raise(Errno::ECONNREFUSED)
|
321
|
+
end
|
283
322
|
|
284
|
-
it '
|
285
|
-
expect(store.send(:destroy, env)).to
|
323
|
+
it 'returns false' do
|
324
|
+
expect(store.send(:destroy, env)).to eq(false)
|
286
325
|
end
|
287
326
|
|
288
327
|
context 'when :on_redis_down re-raises' do
|
@@ -300,7 +339,7 @@ describe RedisSessionStore do
|
|
300
339
|
context 'when destroyed via #destroy_session' do
|
301
340
|
it 'deletes the prefixed key from redis' do
|
302
341
|
redis = double('redis', setnx: true)
|
303
|
-
store.
|
342
|
+
allow(store).to receive(:redis).and_return(redis)
|
304
343
|
sid = store.send(:generate_sid)
|
305
344
|
expect(redis).to receive(:del).with("#{options[:key_prefix]}#{sid}")
|
306
345
|
|
@@ -319,12 +358,12 @@ describe RedisSessionStore do
|
|
319
358
|
let(:expected_encoding) { encoded_data }
|
320
359
|
|
321
360
|
before do
|
322
|
-
store.
|
361
|
+
allow(store).to receive(:redis).and_return(redis)
|
323
362
|
end
|
324
363
|
|
325
364
|
shared_examples_for 'serializer' do
|
326
365
|
it 'encodes correctly' do
|
327
|
-
redis.
|
366
|
+
expect(redis).to receive(:set).with('12345', expected_encoding)
|
328
367
|
store.send(:set_session, env, session_id, session_data, options)
|
329
368
|
end
|
330
369
|
|
@@ -364,11 +403,11 @@ describe RedisSessionStore do
|
|
364
403
|
context 'custom' do
|
365
404
|
let :custom_serializer do
|
366
405
|
Class.new do
|
367
|
-
def self.load(
|
406
|
+
def self.load(_value)
|
368
407
|
{ 'some' => 'data' }
|
369
408
|
end
|
370
409
|
|
371
|
-
def self.dump(
|
410
|
+
def self.dump(_value)
|
372
411
|
'somedata'
|
373
412
|
end
|
374
413
|
end
|
@@ -384,10 +423,10 @@ describe RedisSessionStore do
|
|
384
423
|
describe 'handling decode errors' do
|
385
424
|
context 'when a class is serialized that does not exist' do
|
386
425
|
before do
|
387
|
-
store.
|
388
|
-
|
389
|
-
|
390
|
-
|
426
|
+
allow(store).to receive(:redis)
|
427
|
+
.and_return(double('redis',
|
428
|
+
get: "\x04\bo:\nNonExistentClass\x00",
|
429
|
+
del: true))
|
391
430
|
end
|
392
431
|
|
393
432
|
it 'returns an empty session' do
|
@@ -395,7 +434,8 @@ describe RedisSessionStore do
|
|
395
434
|
end
|
396
435
|
|
397
436
|
it 'destroys and drops the session' do
|
398
|
-
store.
|
437
|
+
expect(store).to receive(:destroy_session_from_sid)
|
438
|
+
.with('wut', drop: true)
|
399
439
|
store.send(:load_session_from_redis, 'wut')
|
400
440
|
end
|
401
441
|
|
@@ -410,16 +450,15 @@ describe RedisSessionStore do
|
|
410
450
|
it 'passes the error and the sid to the handler' do
|
411
451
|
store.send(:load_session_from_redis, 'foo')
|
412
452
|
expect(@e).to be_kind_of(StandardError)
|
413
|
-
expect(@sid).to
|
453
|
+
expect(@sid).to eq('foo')
|
414
454
|
end
|
415
455
|
end
|
416
456
|
end
|
417
457
|
|
418
458
|
context 'when the encoded data is invalid' do
|
419
459
|
before do
|
420
|
-
store.
|
421
|
-
|
422
|
-
)
|
460
|
+
allow(store).to receive(:redis)
|
461
|
+
.and_return(double('redis', get: "\x00\x00\x00\x00", del: true))
|
423
462
|
end
|
424
463
|
|
425
464
|
it 'returns an empty session' do
|
@@ -427,7 +466,8 @@ describe RedisSessionStore do
|
|
427
466
|
end
|
428
467
|
|
429
468
|
it 'destroys and drops the session' do
|
430
|
-
store.
|
469
|
+
expect(store).to receive(:destroy_session_from_sid)
|
470
|
+
.with('wut', drop: true)
|
431
471
|
store.send(:load_session_from_redis, 'wut')
|
432
472
|
end
|
433
473
|
|
@@ -442,7 +482,7 @@ describe RedisSessionStore do
|
|
442
482
|
it 'passes the error and the sid to the handler' do
|
443
483
|
store.send(:load_session_from_redis, 'foo')
|
444
484
|
expect(@e).to be_kind_of(StandardError)
|
445
|
-
expect(@sid).to
|
485
|
+
expect(@sid).to eq('foo')
|
446
486
|
end
|
447
487
|
end
|
448
488
|
end
|
@@ -478,7 +518,7 @@ describe RedisSessionStore do
|
|
478
518
|
it 'allows changing the session' do
|
479
519
|
env = { 'rack.session.options' => {} }
|
480
520
|
sid = 1234
|
481
|
-
store.
|
521
|
+
allow(store).to receive(:redis).and_return(Redis.new)
|
482
522
|
data1 = { 'foo' => 'bar' }
|
483
523
|
store.send(:set_session, env, sid, data1)
|
484
524
|
data2 = { 'baz' => 'wat' }
|
@@ -490,7 +530,7 @@ describe RedisSessionStore do
|
|
490
530
|
it 'allows changing the session when the session has an expiry' do
|
491
531
|
env = { 'rack.session.options' => { expire_after: 60 } }
|
492
532
|
sid = 1234
|
493
|
-
store.
|
533
|
+
allow(store).to receive(:redis).and_return(Redis.new)
|
494
534
|
data1 = { 'foo' => 'bar' }
|
495
535
|
store.send(:set_session, env, sid, data1)
|
496
536
|
data2 = { 'baz' => 'wat' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-session-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: fakeredis
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +128,7 @@ files:
|
|
108
128
|
- ".gitignore"
|
109
129
|
- ".rspec"
|
110
130
|
- ".rubocop.yml"
|
131
|
+
- ".rubocop_todo.yml"
|
111
132
|
- ".simplecov"
|
112
133
|
- ".travis.yml"
|
113
134
|
- AUTHORS.md
|
@@ -148,4 +169,3 @@ specification_version: 4
|
|
148
169
|
summary: A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and
|
149
170
|
Rails sessions only) in Redis.
|
150
171
|
test_files: []
|
151
|
-
has_rdoc: true
|