renee-session 0.4.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/renee/session.rb +50 -0
- data/test/renee-session/session_test.rb +31 -0
- data/test/renee-session/test_helper.rb +9 -0
- data/test/test_helper.rb +70 -0
- metadata +133 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'renee/util'
|
2
|
+
require 'renee/version'
|
3
|
+
|
4
|
+
module Renee
|
5
|
+
module Session
|
6
|
+
module ClassMethods
|
7
|
+
attr_reader :store_type
|
8
|
+
|
9
|
+
def add_session_type(type, cls)
|
10
|
+
session_stores[type] = cls
|
11
|
+
end
|
12
|
+
|
13
|
+
def session(type, *args, &blk)
|
14
|
+
if session_stores.key?(type)
|
15
|
+
@store_type = [session_stores[type], args, blk]
|
16
|
+
else
|
17
|
+
raise "Store type #{type} is unknown, choose from #{session_stores.keys.map(&:inspect).join(', ')}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def disable_session
|
22
|
+
@store_type = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def session_enabled?
|
26
|
+
!@store_type.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
def session_stores
|
30
|
+
@session_stores ||= {}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.included(o)
|
35
|
+
o.extend(ClassMethods)
|
36
|
+
o.add_session_type :cookie, 'Rack::Session::Cookie'
|
37
|
+
o.add_session_type :pool, 'Rack::Session::Pool'
|
38
|
+
o.add_session_type :memcache, 'Rack::Session::Memcache'
|
39
|
+
o.on_init do
|
40
|
+
session_constant = Renee::Util.lookup_constant(store_type[0])
|
41
|
+
use session_constant, *store_type[1], &store_type[2]
|
42
|
+
define_method(:session) { env[Rack::Session::Abstract::ENV_SESSION_KEY] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def session
|
47
|
+
raise "Session not enabled"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Renee::Session do
|
4
|
+
before do
|
5
|
+
@app = Class.new(Renee::Core) do
|
6
|
+
include Renee::Session
|
7
|
+
session :cookie
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should create a session" do
|
12
|
+
@app.app do
|
13
|
+
session[:test] = 'hello'
|
14
|
+
path('test').get.halt "why #{session[:test]}"
|
15
|
+
end
|
16
|
+
get '/test'
|
17
|
+
assert_equal "why hello", response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should persist values across multiple calls" do
|
21
|
+
@app.app do
|
22
|
+
out = session[:test] || "first"
|
23
|
+
session[:test] = 'hello'
|
24
|
+
path('test').get.halt out
|
25
|
+
end
|
26
|
+
get '/test'
|
27
|
+
assert_equal "first", response.body
|
28
|
+
get '/test'
|
29
|
+
assert_equal "hello", response.body
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
$: << File.expand_path('../../../renee/core/lib', __FILE__)
|
2
|
+
$: << File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'renee/core'
|
4
|
+
require 'renee/session'
|
5
|
+
|
6
|
+
Renee::Core.send(:include, Renee::Session)
|
7
|
+
|
8
|
+
# Load shared test helpers
|
9
|
+
require File.expand_path('../../test_helper', __FILE__)
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'minitest'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
gem 'rack-test'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
class ColoredIO
|
8
|
+
ESC = "\e["
|
9
|
+
NND = "#{ESC}0m"
|
10
|
+
|
11
|
+
def initialize(io)
|
12
|
+
@io = io
|
13
|
+
end
|
14
|
+
|
15
|
+
def print(o)
|
16
|
+
case o
|
17
|
+
when "."
|
18
|
+
@io.send(:print, "#{ESC}32m#{o}#{NND}")
|
19
|
+
when "E"
|
20
|
+
@io.send(:print, "#{ESC}33m#{o}#{NND}")
|
21
|
+
when "F"
|
22
|
+
@io.send(:print, "#{ESC}31m#{o}#{NND}")
|
23
|
+
else
|
24
|
+
@io.send(:print, o)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def puts(*o)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
MiniTest::Unit.output = ColoredIO.new(MiniTest::Unit.output)
|
34
|
+
|
35
|
+
## TEST HELPERS
|
36
|
+
class MiniTest::Spec
|
37
|
+
include Rack::Test::Methods
|
38
|
+
|
39
|
+
# Sets up a Sinatra::Base subclass defined with the block
|
40
|
+
# given. Used in setup or individual spec methods to establish
|
41
|
+
# the application.
|
42
|
+
def mock_app(&block)
|
43
|
+
path = default_views_path
|
44
|
+
@app = Renee.core(&block).setup {
|
45
|
+
views_path(path) if respond_to?(:views_path)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def default_views_path
|
50
|
+
File.dirname(__FILE__) + "/views"
|
51
|
+
end
|
52
|
+
|
53
|
+
def app
|
54
|
+
Rack::Lint.new(@app)
|
55
|
+
end
|
56
|
+
|
57
|
+
alias :response :last_response
|
58
|
+
|
59
|
+
# create_view :index, "test", :haml
|
60
|
+
def create_view(name, content, engine=:erb)
|
61
|
+
FileUtils.mkdir_p(default_views_path)
|
62
|
+
file = File.join(default_views_path, name.to_s + ".#{engine}")
|
63
|
+
File.open(file, 'w') { |io| io.write content }
|
64
|
+
end
|
65
|
+
|
66
|
+
# Removes the view folder after the test
|
67
|
+
def remove_views
|
68
|
+
FileUtils.rm_rf(File.dirname(__FILE__) + "/views")
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: renee-session
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0.pre1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Hull
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70177309384880 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70177309384880
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: renee-core
|
27
|
+
requirement: &70177309384320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.0.pre1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70177309384320
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: minitest
|
38
|
+
requirement: &70177309383760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.6.1
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70177309383760
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70177309379120 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70177309379120
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &70177309378660 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70177309378660
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: &70177309378160 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.5.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70177309378160
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: haml
|
82
|
+
requirement: &70177309377660 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.2.0
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70177309377660
|
91
|
+
description: The super-friendly web framework session component.
|
92
|
+
email:
|
93
|
+
- joshbuddy@gmail.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- lib/renee/session.rb
|
99
|
+
- test/renee-session/session_test.rb
|
100
|
+
- test/renee-session/test_helper.rb
|
101
|
+
- test/test_helper.rb
|
102
|
+
homepage: http://reneerb.com
|
103
|
+
licenses: []
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -2598345540863933147
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>'
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.3.1
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project: renee-session
|
125
|
+
rubygems_version: 1.8.15
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: The super-friendly web framework session component
|
129
|
+
test_files:
|
130
|
+
- test/renee-session/session_test.rb
|
131
|
+
- test/renee-session/test_helper.rb
|
132
|
+
- test/test_helper.rb
|
133
|
+
has_rdoc:
|