innate 2009.04
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2981 -0
- data/COPYING +18 -0
- data/MANIFEST +127 -0
- data/README.md +563 -0
- data/Rakefile +35 -0
- data/example/app/retro_games.rb +60 -0
- data/example/app/todo/layout/default.xhtml +11 -0
- data/example/app/todo/spec/todo.rb +63 -0
- data/example/app/todo/start.rb +51 -0
- data/example/app/todo/view/index.xhtml +39 -0
- data/example/app/whywiki_erb/layout/wiki.html.erb +15 -0
- data/example/app/whywiki_erb/spec/wiki.rb +19 -0
- data/example/app/whywiki_erb/start.rb +42 -0
- data/example/app/whywiki_erb/view/edit.erb +6 -0
- data/example/app/whywiki_erb/view/index.erb +12 -0
- data/example/custom_middleware.rb +35 -0
- data/example/hello.rb +11 -0
- data/example/howto_spec.rb +35 -0
- data/example/link.rb +27 -0
- data/example/provides.rb +31 -0
- data/example/session.rb +38 -0
- data/innate.gemspec +29 -0
- data/lib/innate.rb +269 -0
- data/lib/innate/action.rb +150 -0
- data/lib/innate/adapter.rb +76 -0
- data/lib/innate/cache.rb +134 -0
- data/lib/innate/cache/api.rb +128 -0
- data/lib/innate/cache/drb.rb +58 -0
- data/lib/innate/cache/file_based.rb +41 -0
- data/lib/innate/cache/marshal.rb +17 -0
- data/lib/innate/cache/memory.rb +22 -0
- data/lib/innate/cache/yaml.rb +17 -0
- data/lib/innate/current.rb +37 -0
- data/lib/innate/dynamap.rb +96 -0
- data/lib/innate/helper.rb +183 -0
- data/lib/innate/helper/aspect.rb +124 -0
- data/lib/innate/helper/cgi.rb +54 -0
- data/lib/innate/helper/flash.rb +36 -0
- data/lib/innate/helper/link.rb +94 -0
- data/lib/innate/helper/redirect.rb +85 -0
- data/lib/innate/helper/render.rb +87 -0
- data/lib/innate/helper/send_file.rb +26 -0
- data/lib/innate/log.rb +20 -0
- data/lib/innate/log/color_formatter.rb +43 -0
- data/lib/innate/log/hub.rb +73 -0
- data/lib/innate/middleware_compiler.rb +65 -0
- data/lib/innate/mock.rb +49 -0
- data/lib/innate/node.rb +1025 -0
- data/lib/innate/options.rb +37 -0
- data/lib/innate/options/dsl.rb +202 -0
- data/lib/innate/options/stub.rb +7 -0
- data/lib/innate/request.rb +141 -0
- data/lib/innate/response.rb +23 -0
- data/lib/innate/route.rb +110 -0
- data/lib/innate/session.rb +121 -0
- data/lib/innate/session/flash.rb +94 -0
- data/lib/innate/spec.rb +23 -0
- data/lib/innate/state.rb +27 -0
- data/lib/innate/state/accessor.rb +130 -0
- data/lib/innate/state/fiber.rb +74 -0
- data/lib/innate/state/thread.rb +47 -0
- data/lib/innate/traited.rb +85 -0
- data/lib/innate/trinity.rb +18 -0
- data/lib/innate/version.rb +3 -0
- data/lib/innate/view.rb +60 -0
- data/lib/innate/view/erb.rb +15 -0
- data/lib/innate/view/etanni.rb +36 -0
- data/lib/innate/view/none.rb +9 -0
- data/spec/example/app/retro_games.rb +30 -0
- data/spec/example/hello.rb +13 -0
- data/spec/example/link.rb +25 -0
- data/spec/example/provides.rb +16 -0
- data/spec/example/session.rb +22 -0
- data/spec/helper.rb +10 -0
- data/spec/innate/action/layout.rb +107 -0
- data/spec/innate/action/layout/file_layout.xhtml +1 -0
- data/spec/innate/cache/common.rb +47 -0
- data/spec/innate/cache/marshal.rb +5 -0
- data/spec/innate/cache/memory.rb +5 -0
- data/spec/innate/cache/yaml.rb +5 -0
- data/spec/innate/dynamap.rb +22 -0
- data/spec/innate/helper.rb +86 -0
- data/spec/innate/helper/aspect.rb +75 -0
- data/spec/innate/helper/cgi.rb +37 -0
- data/spec/innate/helper/flash.rb +118 -0
- data/spec/innate/helper/link.rb +139 -0
- data/spec/innate/helper/redirect.rb +160 -0
- data/spec/innate/helper/render.rb +133 -0
- data/spec/innate/helper/send_file.rb +21 -0
- data/spec/innate/helper/view/aspect_hello.xhtml +1 -0
- data/spec/innate/helper/view/locals.xhtml +1 -0
- data/spec/innate/helper/view/loop.xhtml +4 -0
- data/spec/innate/helper/view/num.xhtml +1 -0
- data/spec/innate/helper/view/partial.xhtml +1 -0
- data/spec/innate/helper/view/recursive.xhtml +7 -0
- data/spec/innate/mock.rb +84 -0
- data/spec/innate/node/mapping.rb +37 -0
- data/spec/innate/node/node.rb +134 -0
- data/spec/innate/node/resolve.rb +82 -0
- data/spec/innate/node/view/another_layout/another_layout.xhtml +3 -0
- data/spec/innate/node/view/bar.xhtml +1 -0
- data/spec/innate/node/view/foo.html.xhtml +1 -0
- data/spec/innate/node/view/only_view.xhtml +1 -0
- data/spec/innate/node/view/with_layout.xhtml +1 -0
- data/spec/innate/node/wrap_action_call.rb +83 -0
- data/spec/innate/options.rb +115 -0
- data/spec/innate/parameter.rb +154 -0
- data/spec/innate/provides.rb +99 -0
- data/spec/innate/provides/list.html.xhtml +1 -0
- data/spec/innate/provides/list.txt.xhtml +1 -0
- data/spec/innate/request.rb +77 -0
- data/spec/innate/route.rb +135 -0
- data/spec/innate/session.rb +54 -0
- data/spec/innate/state/fiber.rb +58 -0
- data/spec/innate/state/thread.rb +40 -0
- data/spec/innate/traited.rb +55 -0
- data/tasks/bacon.rake +66 -0
- data/tasks/changelog.rake +18 -0
- data/tasks/gem.rake +22 -0
- data/tasks/gem_installer.rake +76 -0
- data/tasks/grancher.rake +12 -0
- data/tasks/install_dependencies.rake +4 -0
- data/tasks/manifest.rake +4 -0
- data/tasks/rcov.rake +19 -0
- data/tasks/release.rake +51 -0
- data/tasks/reversion.rake +8 -0
- data/tasks/setup.rake +28 -0
- metadata +181 -0
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecRedirectHelper
|
4
|
+
Innate.node '/'
|
5
|
+
|
6
|
+
def index
|
7
|
+
self.class.name
|
8
|
+
end
|
9
|
+
|
10
|
+
def noop
|
11
|
+
'noop'
|
12
|
+
end
|
13
|
+
|
14
|
+
def redirection
|
15
|
+
redirect :index
|
16
|
+
end
|
17
|
+
|
18
|
+
def double_redirection
|
19
|
+
redirect :redirection
|
20
|
+
end
|
21
|
+
|
22
|
+
def redirect_referer_action
|
23
|
+
redirect_referer(r(:noop))
|
24
|
+
end
|
25
|
+
|
26
|
+
def no_actual_redirect
|
27
|
+
catch(:redirect){ redirect(:index) }
|
28
|
+
'no actual redirect'
|
29
|
+
end
|
30
|
+
|
31
|
+
def no_actual_double_redirect
|
32
|
+
catch(:redirect){ double_redirection }
|
33
|
+
'no actual double redirect'
|
34
|
+
end
|
35
|
+
|
36
|
+
def redirect_method
|
37
|
+
redirect r(:noop)
|
38
|
+
end
|
39
|
+
|
40
|
+
def absolute_redirect
|
41
|
+
redirect 'http://localhost:7000/noop'
|
42
|
+
end
|
43
|
+
|
44
|
+
def loop
|
45
|
+
respond 'no loop'
|
46
|
+
'loop'
|
47
|
+
end
|
48
|
+
|
49
|
+
def respond_with_status
|
50
|
+
respond 'not found', 404
|
51
|
+
end
|
52
|
+
|
53
|
+
def destructive_respond
|
54
|
+
respond! 'destructive'
|
55
|
+
end
|
56
|
+
|
57
|
+
def redirect_unmodified
|
58
|
+
raw_redirect '/noop'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe Innate::Helper::Redirect do
|
63
|
+
behaves_like :mock
|
64
|
+
|
65
|
+
@uri = 'http://localhost:7000'
|
66
|
+
|
67
|
+
should 'retrieve index' do
|
68
|
+
get('/').body.should =='SpecRedirectHelper'
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'redirect' do
|
72
|
+
get("#@uri/redirection")
|
73
|
+
|
74
|
+
last_response.status.should == 302
|
75
|
+
last_response.headers['Location'].should == "#@uri/index"
|
76
|
+
last_response.headers['Content-Type'].should == "text/html"
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'redirect twice' do
|
80
|
+
get("#@uri/double_redirection")
|
81
|
+
|
82
|
+
last_response.status.should == 302
|
83
|
+
last_response.headers['Location'].should == "#@uri/redirection"
|
84
|
+
last_response.headers['Content-Type'].should == "text/html"
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'redirect to referer' do
|
88
|
+
header 'HTTP_REFERER', '/index'
|
89
|
+
get("#@uri/redirect_referer_action")
|
90
|
+
|
91
|
+
last_response.status.should == 302
|
92
|
+
last_response.headers['Location'].should == "#@uri/index"
|
93
|
+
last_response.headers['Content-Type'].should == "text/html"
|
94
|
+
end
|
95
|
+
|
96
|
+
should 'redirect to fallback if referrer is identical' do
|
97
|
+
header 'HTTP_REFERER', "#@uri/redirect_referer_action"
|
98
|
+
get("#@uri/redirect_referer_action")
|
99
|
+
|
100
|
+
last_response.status.should == 302
|
101
|
+
last_response.headers['Location'].should == "#@uri/noop"
|
102
|
+
last_response.headers['Content-Type'].should == "text/html"
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'use #r' do
|
106
|
+
get("#@uri/redirect_method")
|
107
|
+
|
108
|
+
last_response.status.should == 302
|
109
|
+
last_response.headers['Location'].should == "#@uri/noop"
|
110
|
+
last_response.headers['Content-Type'].should == "text/html"
|
111
|
+
end
|
112
|
+
|
113
|
+
should 'work with absolute uris' do
|
114
|
+
get("#@uri/absolute_redirect")
|
115
|
+
|
116
|
+
last_response.status.should == 302
|
117
|
+
last_response.headers['Location'].should == "#@uri/noop"
|
118
|
+
last_response.headers['Content-Type'].should == "text/html"
|
119
|
+
end
|
120
|
+
|
121
|
+
should 'support #respond' do
|
122
|
+
get("#@uri/loop")
|
123
|
+
|
124
|
+
last_response.status.should == 200
|
125
|
+
last_response.body.should == 'no loop'
|
126
|
+
end
|
127
|
+
|
128
|
+
should 'support #respond with status' do
|
129
|
+
get("#@uri/respond_with_status")
|
130
|
+
|
131
|
+
last_response.status.should == 404
|
132
|
+
last_response.body.should == 'not found'
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'support #respond!' do
|
136
|
+
get("#@uri/destructive_respond")
|
137
|
+
|
138
|
+
last_response.status.should == 200
|
139
|
+
last_response.body.should == 'destructive'
|
140
|
+
end
|
141
|
+
|
142
|
+
should 'redirect without modifying the target' do
|
143
|
+
get("#@uri/redirect_unmodified")
|
144
|
+
|
145
|
+
last_response.status.should == 302
|
146
|
+
last_response.headers['Location'].should == '/noop'
|
147
|
+
end
|
148
|
+
|
149
|
+
should 'catch redirection' do
|
150
|
+
get("#@uri/no_actual_redirect")
|
151
|
+
last_response.status.should == 200
|
152
|
+
last_response.body.should == 'no actual redirect'
|
153
|
+
end
|
154
|
+
|
155
|
+
should 'catch double redirect' do
|
156
|
+
get("#@uri/no_actual_double_redirect")
|
157
|
+
last_response.status.should == 200
|
158
|
+
last_response.body.should == 'no actual double redirect'
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecHelperRenderFull
|
4
|
+
Innate.node '/render_full'
|
5
|
+
|
6
|
+
def foo
|
7
|
+
"foo: %p" % [request.params.sort]
|
8
|
+
end
|
9
|
+
|
10
|
+
def standard
|
11
|
+
render_full(r(:foo))
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_query
|
15
|
+
render_full(r(:foo), 'a' => 'b')
|
16
|
+
end
|
17
|
+
|
18
|
+
def with_session
|
19
|
+
render_full(r(:get_session, :user))
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_session(key)
|
23
|
+
session[key].inspect
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_session(key, value)
|
27
|
+
session[key] = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class SpecHelperRenderPartial
|
32
|
+
Innate.node '/render_partial'
|
33
|
+
|
34
|
+
layout :layout
|
35
|
+
|
36
|
+
def standard
|
37
|
+
'hello'
|
38
|
+
end
|
39
|
+
|
40
|
+
def layout
|
41
|
+
'{ #{@content} }'
|
42
|
+
end
|
43
|
+
|
44
|
+
def without_layout
|
45
|
+
render_partial(:standard)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class SpecHelperRenderView
|
50
|
+
Innate.node '/render_view'
|
51
|
+
map_views '/'
|
52
|
+
|
53
|
+
layout :layout
|
54
|
+
|
55
|
+
def standard
|
56
|
+
'hello'
|
57
|
+
end
|
58
|
+
|
59
|
+
def layout
|
60
|
+
'{ #{@content} }'
|
61
|
+
end
|
62
|
+
|
63
|
+
def without_method_or_layout
|
64
|
+
render_view(:num, :n => 42)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class SpecHelperRenderMisc
|
69
|
+
Innate.node '/misc'
|
70
|
+
map_views '/'
|
71
|
+
|
72
|
+
def recursive
|
73
|
+
@n ||= 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe Innate::Helper::Render do
|
78
|
+
describe '#render_full' do
|
79
|
+
behaves_like :mock
|
80
|
+
|
81
|
+
it 'renders a full action' do
|
82
|
+
get('/render_full/standard').body.should == 'foo: []'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'renders full action with query parameters' do
|
86
|
+
get('/render_full/with_query').body.should == 'foo: [["a", "b"]]'
|
87
|
+
end
|
88
|
+
|
89
|
+
# this is an edge-case, we don't have a full session running if this is the
|
90
|
+
# first request from the client as Innate creates sessions only on demand
|
91
|
+
# at the end of the request/response cycle.
|
92
|
+
#
|
93
|
+
# So we have to make some request first, in this case we simply set some
|
94
|
+
# value in the session that we can get afterwards.
|
95
|
+
|
96
|
+
it 'renders full action inside a session' do
|
97
|
+
get('/render_full/set_session/user/manveru')
|
98
|
+
get('/render_full/with_session').body.should == '"manveru"'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#render_partial' do
|
103
|
+
behaves_like :mock
|
104
|
+
|
105
|
+
it 'renders action with layout' do
|
106
|
+
get('/render_partial/standard').body.should == '{ hello }'
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'renders partial action without layout' do
|
110
|
+
get('/render_partial/without_layout').body.should == '{ hello }'
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#render_view' do
|
115
|
+
behaves_like :mock
|
116
|
+
|
117
|
+
it 'renders action without calling the method or applying layout' do
|
118
|
+
get('/render_view/without_method_or_layout').body.should == '{ 42 }'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'misc functionality' do
|
123
|
+
behaves_like :mock
|
124
|
+
|
125
|
+
it 'can render_partial in a loop' do
|
126
|
+
get('/misc/loop').body.scan(/\d+/).should == %w[1 2 3 4 5]
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'can recursively render_partial' do
|
130
|
+
get('/misc/recursive').body.scan(/\S/).join.should == '{1{2{3{44}3}2}1}'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecSendFile
|
4
|
+
include Innate::Node
|
5
|
+
map '/'
|
6
|
+
|
7
|
+
def this
|
8
|
+
send_file(__FILE__)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Innate::Helper::SendFile do
|
13
|
+
should 'send __FILE__' do
|
14
|
+
got = Innate::Mock.get('/this')
|
15
|
+
|
16
|
+
got.body.should == File.read(__FILE__)
|
17
|
+
got.status.should == 200
|
18
|
+
got['Content-Length'].should == File.size(__FILE__).to_s
|
19
|
+
got['Content-Type'].should == 'text/x-script.ruby'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@foo} #{@bar}!
|
@@ -0,0 +1 @@
|
|
1
|
+
#{say}, #{to}!
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@n}
|
@@ -0,0 +1 @@
|
|
1
|
+
From Partial #{@here}
|
data/spec/innate/mock.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecMock
|
4
|
+
include Innate::Node
|
5
|
+
map '/'
|
6
|
+
|
7
|
+
def index
|
8
|
+
''
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class SpecMock2
|
13
|
+
include Innate::Node
|
14
|
+
map '/deep'
|
15
|
+
|
16
|
+
def index
|
17
|
+
'spec mock 2'
|
18
|
+
end
|
19
|
+
|
20
|
+
def foo
|
21
|
+
'spec mock 2 foo'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Innate::SpeckMock2' do
|
26
|
+
should 'handle get request' do
|
27
|
+
response = Innate::Mock.get('/deep/foo')
|
28
|
+
# '/foo/bar'
|
29
|
+
response.status.should == 200
|
30
|
+
response.body.should == 'spec mock 2 foo'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'Innate::SpecMock' do
|
35
|
+
should 'handle get request' do
|
36
|
+
response = Innate::Mock.get('/')
|
37
|
+
# '/one'
|
38
|
+
response.status.should == 200
|
39
|
+
response.body.should == ''
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'handle post request' do
|
43
|
+
response = Innate::Mock.post('/')
|
44
|
+
# '/'
|
45
|
+
response.status.should == 200
|
46
|
+
response.body.should == ''
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'handle head request' do
|
50
|
+
response = Innate::Mock.head('/')
|
51
|
+
response.status.should == 200
|
52
|
+
response.body.should == ''
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'handle delete request' do
|
56
|
+
response = Innate::Mock.delete('/')
|
57
|
+
response.status.should == 200
|
58
|
+
response.body.should == ''
|
59
|
+
end
|
60
|
+
|
61
|
+
should 'handle put request' do
|
62
|
+
response = Innate::Mock.put('/')
|
63
|
+
response.status.should == 200
|
64
|
+
response.body.should == ''
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'handle options request' do
|
68
|
+
response = Innate::Mock.options('/')
|
69
|
+
response.status.should == 200
|
70
|
+
response.body.should == ''
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'handle connect request' do
|
74
|
+
response = Innate::Mock.connect('/')
|
75
|
+
response.status.should == 200
|
76
|
+
response.body.should == ''
|
77
|
+
end
|
78
|
+
|
79
|
+
should 'handle trace request' do
|
80
|
+
response = Innate::Mock.trace('/')
|
81
|
+
response.status.should == 200
|
82
|
+
response.body.should == ''
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe 'Node::generate_mapping' do
|
4
|
+
def gen(const)
|
5
|
+
Innate::Node.generate_mapping(const)
|
6
|
+
end
|
7
|
+
|
8
|
+
should 'transform class names into snake_case locations' do
|
9
|
+
gen( 'O').should == '/o'
|
10
|
+
gen( 'Oo').should == '/oo'
|
11
|
+
gen( 'Ooo').should == '/ooo'
|
12
|
+
gen( 'OooO').should == '/oooo'
|
13
|
+
gen( 'OooOo').should == '/ooo_oo'
|
14
|
+
gen('OooOoo').should == '/ooo_ooo'
|
15
|
+
gen('OOOooo').should == '/oooooo'
|
16
|
+
gen('OooOOO').should == '/oooooo'
|
17
|
+
gen('OoOoOo').should == '/oo_oo_oo'
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'transform namespaces into leading parts of the location' do
|
21
|
+
gen('O::O').should == '/o/o'
|
22
|
+
gen('O::O::O').should == '/o/o/o'
|
23
|
+
gen('O::O::O::O').should == '/o/o/o/o'
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'transform leading parts just like standalone part' do
|
27
|
+
gen( 'O::O').should == '/o/o'
|
28
|
+
gen( 'Oo::O').should == '/oo/o'
|
29
|
+
gen( 'Ooo::O').should == '/ooo/o'
|
30
|
+
gen( 'OooO::O').should == '/oooo/o'
|
31
|
+
gen( 'OooOo::O').should == '/ooo_oo/o'
|
32
|
+
gen('OooOoo::O').should == '/ooo_ooo/o'
|
33
|
+
gen('OOOooo::O').should == '/oooooo/o'
|
34
|
+
gen('OooOOO::O').should == '/oooooo/o'
|
35
|
+
gen('OoOoOo::O').should == '/oo_oo_oo/o'
|
36
|
+
end
|
37
|
+
end
|