forked from rails/activerecord-session_store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy_session_test.rb
53 lines (40 loc) · 1.5 KB
/
destroy_session_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
if ActiveRecord::VERSION::MAJOR > 4
require 'action_dispatch/middleware/session/abstract_store'
module ActionDispatch
class Request
class DestroySessionTest < ActiveSupport::TestCase
attr_reader :req
def setup
@req = ActionDispatch::Request.empty
ActionDispatch::Session::ActiveRecordStore.session_class.drop_table! rescue nil
ActionDispatch::Session::ActiveRecordStore.session_class.create_table!
end
def record_key
ActionDispatch::Session::ActiveRecordStore::SESSION_RECORD_KEY
end
def test_destroy_without_renew
s = Session.create(store, req, { :renew => false })
s['set_something_so_it_loads'] = true
session_model = req.env[record_key]
session_model.update(:data => {'rails' => 'ftw'})
s.destroy
renewed_session_model = req.env[record_key]
assert_nil renewed_session_model.data['rails']
end
def test_destroy_with_renew
s = Session.create(store, req, { :renew => true })
s['set_something_so_it_loads'] = true
session_model = req.env[record_key]
session_model.update(:data => {'rails' => 'ftw'})
s.destroy
renewed_session_model = req.env[record_key]
assert_equal 'ftw', renewed_session_model.data['rails']
end
private
def store
ActionDispatch::Session::ActiveRecordStore.new(req.env, {})
end
end
end
end
end