forked from rails/activerecord-session_store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_bypass_test.rb
75 lines (65 loc) · 2.1 KB
/
sql_bypass_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'helper'
require 'action_dispatch'
require 'active_record/session_store'
module ActiveRecord
module SessionStore
class SqlBypassTest < ActiveSupport::TestCase
def setup
super
Session.drop_table! if Session.table_exists?
end
def test_create_table
assert !Session.table_exists?
SqlBypass.create_table!
assert Session.table_exists?
SqlBypass.drop_table!
assert !Session.table_exists?
end
def test_new_record?
s = SqlBypass.new :data => 'foo', :session_id => 10
assert s.new_record?, 'this is a new record!'
end
def test_persisted?
s = SqlBypass.new :data => 'foo', :session_id => 10
assert !s.persisted?, 'this is a new record!'
end
def test_not_loaded?
s = SqlBypass.new({})
assert !s.loaded?, 'it is not loaded'
end
def test_loaded?
s = SqlBypass.new :data => 'hello'
assert s.loaded?, 'it is loaded'
end
def test_save
SqlBypass.create_table! unless Session.table_exists?
session_id = 20
s = SqlBypass.new :data => 'hello', :session_id => session_id
s.save
t = SqlBypass.find_by_session_id session_id
assert_equal s.session_id, t.session_id
assert_equal s.data, t.data
end
def test_destroy
SqlBypass.create_table! unless Session.table_exists?
session_id = 20
s = SqlBypass.new :data => 'hello', :session_id => session_id
s.save
s.destroy
assert_nil SqlBypass.find_by_session_id session_id
end
def test_data_column
SqlBypass.drop_table! if exists = Session.table_exists?
old, SqlBypass.data_column = SqlBypass.data_column, 'foo'
SqlBypass.create_table!
session_id = 20
SqlBypass.new(:data => 'hello', :session_id => session_id).save
assert_equal 'hello', SqlBypass.find_by_session_id(session_id).data
ensure
SqlBypass.drop_table!
SqlBypass.data_column = old
SqlBypass.create_table! if exists
end
end
end
end