manveru-innate 2009.02.06
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1409 -0
- data/COPYING +18 -0
- data/MANIFEST +100 -0
- data/README.md +485 -0
- data/Rakefile +139 -0
- data/example/app/retro_games.rb +57 -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 +45 -0
- data/example/app/whywiki_erb/view/edit.html.erb +6 -0
- data/example/app/whywiki_erb/view/index.html.erb +10 -0
- data/example/custom_middleware.rb +43 -0
- data/example/error_handling.rb +31 -0
- data/example/hello.rb +12 -0
- data/example/howto_spec.rb +60 -0
- data/example/link.rb +35 -0
- data/example/providing_hash.rb +46 -0
- data/example/session.rb +42 -0
- data/innate.gemspec +118 -0
- data/lib/innate.rb +191 -0
- data/lib/innate/action.rb +156 -0
- data/lib/innate/adapter.rb +89 -0
- data/lib/innate/cache.rb +117 -0
- data/lib/innate/cache/api.rb +106 -0
- data/lib/innate/cache/drb.rb +58 -0
- data/lib/innate/cache/file_based.rb +39 -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/core_compatibility/basic_object.rb +9 -0
- data/lib/innate/core_compatibility/string.rb +3 -0
- data/lib/innate/current.rb +37 -0
- data/lib/innate/dynamap.rb +81 -0
- data/lib/innate/helper.rb +195 -0
- data/lib/innate/helper/aspect.rb +62 -0
- data/lib/innate/helper/cgi.rb +39 -0
- data/lib/innate/helper/flash.rb +36 -0
- data/lib/innate/helper/link.rb +55 -0
- data/lib/innate/helper/partial.rb +90 -0
- data/lib/innate/helper/redirect.rb +85 -0
- data/lib/innate/helper/send_file.rb +18 -0
- data/lib/innate/log.rb +23 -0
- data/lib/innate/log/color_formatter.rb +43 -0
- data/lib/innate/log/hub.rb +72 -0
- data/lib/innate/mock.rb +49 -0
- data/lib/innate/node.rb +471 -0
- data/lib/innate/options.rb +91 -0
- data/lib/innate/options/dsl.rb +155 -0
- data/lib/innate/request.rb +165 -0
- data/lib/innate/response.rb +18 -0
- data/lib/innate/route.rb +109 -0
- data/lib/innate/session.rb +104 -0
- data/lib/innate/session/flash.rb +94 -0
- data/lib/innate/setup.rb +23 -0
- data/lib/innate/spec.rb +42 -0
- data/lib/innate/state.rb +22 -0
- data/lib/innate/state/accessor.rb +130 -0
- data/lib/innate/state/fiber.rb +68 -0
- data/lib/innate/state/thread.rb +39 -0
- data/lib/innate/traited.rb +20 -0
- data/lib/innate/trinity.rb +22 -0
- data/lib/innate/version.rb +3 -0
- data/lib/innate/view.rb +67 -0
- data/lib/innate/view/erb.rb +17 -0
- data/lib/innate/view/none.rb +9 -0
- data/lib/rack/middleware_compiler.rb +62 -0
- data/lib/rack/reloader.rb +192 -0
- data/spec/example/hello.rb +14 -0
- data/spec/example/link.rb +29 -0
- data/spec/helper.rb +2 -0
- data/spec/innate/cache/common.rb +45 -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 +66 -0
- data/spec/innate/helper/aspect.rb +80 -0
- data/spec/innate/helper/cgi.rb +37 -0
- data/spec/innate/helper/flash.rb +148 -0
- data/spec/innate/helper/link.rb +82 -0
- data/spec/innate/helper/partial.rb +66 -0
- data/spec/innate/helper/redirect.rb +148 -0
- data/spec/innate/helper/send_file.rb +21 -0
- data/spec/innate/helper/view/aspect_hello.erb +1 -0
- data/spec/innate/helper/view/locals.erb +1 -0
- data/spec/innate/helper/view/loop.erb +4 -0
- data/spec/innate/helper/view/num.erb +1 -0
- data/spec/innate/helper/view/partial.erb +1 -0
- data/spec/innate/helper/view/recursive.erb +8 -0
- data/spec/innate/mock.rb +84 -0
- data/spec/innate/node.rb +180 -0
- data/spec/innate/node/bar.html +1 -0
- data/spec/innate/node/foo.html.erb +1 -0
- data/spec/innate/node/with_layout.erb +3 -0
- data/spec/innate/options.rb +90 -0
- data/spec/innate/parameter.rb +154 -0
- data/spec/innate/request.rb +73 -0
- data/spec/innate/route.rb +129 -0
- data/spec/innate/session.rb +59 -0
- data/spec/innate/traited.rb +55 -0
- metadata +160 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class One
|
4
|
+
include Innate::Node
|
5
|
+
map '/'
|
6
|
+
end
|
7
|
+
|
8
|
+
class Two
|
9
|
+
include Innate::Node
|
10
|
+
map '/two'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Innate::Helper::Link do
|
14
|
+
describe '#route' do
|
15
|
+
should 'respond with URI for node' do
|
16
|
+
One.route.should == URI('/')
|
17
|
+
Two.route.should == URI('/two/')
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'respond with URI for node with path /' do
|
21
|
+
One.route('/').should == URI('/')
|
22
|
+
Two.route('/').should == URI('/two/')
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'respond with URI for node with path /foo' do
|
26
|
+
One.route('/foo').should == URI('/foo')
|
27
|
+
One.route(:foo).should == URI('/foo')
|
28
|
+
|
29
|
+
Two.route('/foo').should == URI('/two/foo')
|
30
|
+
Two.route(:foo).should == URI('/two/foo')
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'respond with URI for node with path /foo/bar' do
|
34
|
+
One.route('/foo/bar').should == URI('/foo/bar')
|
35
|
+
One.route(:foo, :bar).should == URI('/foo/bar')
|
36
|
+
|
37
|
+
Two.route('/foo/bar').should == URI('/two/foo/bar')
|
38
|
+
Two.route(:foo, :bar).should == URI('/two/foo/bar')
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'respond with URI for node with GET params' do
|
42
|
+
One.route('/', :a => :b).should == URI('/?a=b')
|
43
|
+
|
44
|
+
One.route('/foo', :a => :b).should == URI('/foo?a=b')
|
45
|
+
One.route(:foo, :a => :b ).should == URI('/foo?a=b')
|
46
|
+
|
47
|
+
One.route('/foo/bar', :a => :b).should == URI('/foo/bar?a=b')
|
48
|
+
One.route(:foo, :bar, :a => :b).should == URI('/foo/bar?a=b')
|
49
|
+
|
50
|
+
Two.route('/', :a => :b).should == URI('/two/?a=b')
|
51
|
+
|
52
|
+
Two.route('foo', :a => :b).should == URI('/two/foo?a=b')
|
53
|
+
Two.route(:foo, :a => :b ).should == URI('/two/foo?a=b')
|
54
|
+
Two.route('/foo/bar', :a => :b).should == URI('/two/foo/bar?a=b')
|
55
|
+
Two.route(:foo, :bar, :a => :b).should == URI('/two/foo/bar?a=b')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#anchor' do
|
60
|
+
should 'respond with a tag with default text' do
|
61
|
+
One.anchor('hello').should == '<a href="/hello">hello</a>'
|
62
|
+
Two.anchor('hello').should == '<a href="/two/hello">hello</a>'
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'respond with a tag with explicit text' do
|
66
|
+
One.anchor('hello', :foo).should == '<a href="/foo">hello</a>'
|
67
|
+
Two.anchor('hello', :foo).should == '<a href="/two/foo">hello</a>'
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'pass parameters to #route' do
|
71
|
+
One.anchor('hello', :foo, :a => :b).
|
72
|
+
should == '<a href="/foo?a=b">hello</a>'
|
73
|
+
Two.anchor('hello', :foo, :a => :b).
|
74
|
+
should == '<a href="/two/foo?a=b">hello</a>'
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'escape text' do
|
78
|
+
One.anchor('<blink> & <a>', :foo).
|
79
|
+
should == '<a href="/foo"><blink> & <a></a>'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecHelperPartial
|
4
|
+
include Innate::Node
|
5
|
+
map '/'
|
6
|
+
|
7
|
+
def index
|
8
|
+
'<html><head><title><%= render_partial("/title") %></title></head></html>'
|
9
|
+
end
|
10
|
+
|
11
|
+
def title
|
12
|
+
"Title"
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_params
|
16
|
+
'<html><head><title><%= render_partial("/message", :msg => "hello") %></title></head></html>'
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
"Message: #{request[:msg]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def composed
|
24
|
+
@here = 'there'
|
25
|
+
'From Action | ' << render_template("partial.erb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def recursive(locals = false)
|
29
|
+
respond render_template('recursive_locals.erb', :n => 1) if locals
|
30
|
+
@n = 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def without_ext
|
34
|
+
render_template('title')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Innate.options.app.root = File.dirname(__FILE__)
|
39
|
+
|
40
|
+
describe Innate::Helper::Partial do
|
41
|
+
behaves_like :mock
|
42
|
+
|
43
|
+
should 'render partials' do
|
44
|
+
get('/').body.should == '<html><head><title>Title</title></head></html>'
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'render partials with params' do
|
48
|
+
get('/with_params').body.should == '<html><head><title>Message: hello</title></head></html>'
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'be able to render a template in the current scope' do
|
52
|
+
get('/composed').body.strip.should == "From Action | From Partial there"
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'render_template in a loop' do
|
56
|
+
get('/loop').body.gsub(/\s/,'').should == '12345'
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'work recursively' do
|
60
|
+
get('/recursive').body.gsub(/\s/,'').should == '{1{2{3{44}4}3}2}'
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'not require file extension' do
|
64
|
+
get('/without_ext').body.should == 'Title'
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
class SpecRedirectHelper
|
4
|
+
include 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
|
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
|
+
Innate.setup_dependencies
|
63
|
+
Innate.setup_middleware
|
64
|
+
|
65
|
+
describe Innate::Helper::Redirect do
|
66
|
+
behaves_like :mock
|
67
|
+
|
68
|
+
@uri = 'http://localhost:7000'
|
69
|
+
|
70
|
+
should 'retrieve index' do
|
71
|
+
get('/').body.should =='SpecRedirectHelper'
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'redirect' do
|
75
|
+
got = get("#@uri/redirection")
|
76
|
+
got.status.should == 302
|
77
|
+
got.headers['Location'].should == "#@uri/index"
|
78
|
+
got.headers['Content-Type'].should == "text/html"
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'redirect twice' do
|
82
|
+
got = get("#@uri/double_redirection")
|
83
|
+
got.status.should == 302
|
84
|
+
got.headers['Location'].should == "#@uri/redirection"
|
85
|
+
got.headers['Content-Type'].should == "text/html"
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'redirect to referer' do
|
89
|
+
got = get("#@uri/redirect_referer_action", 'HTTP_REFERER' => '/noop')
|
90
|
+
got.status.should == 302
|
91
|
+
got.headers['Location'].should == "#@uri/noop"
|
92
|
+
got.headers['Content-Type'].should == "text/html"
|
93
|
+
got = get("#@uri/redirect_referer_action", 'HTTP_REFERER' => "#@uri/redirect_referer_action")
|
94
|
+
got.status.should == 302
|
95
|
+
got.headers['Location'].should == "#@uri/"
|
96
|
+
got.headers['Content-Type'].should == "text/html"
|
97
|
+
end
|
98
|
+
|
99
|
+
should 'use #r' do
|
100
|
+
got = get("#@uri/redirect_method")
|
101
|
+
got.status.should == 302
|
102
|
+
got.headers['Location'].should == "#@uri/noop"
|
103
|
+
got.headers['Content-Type'].should == "text/html"
|
104
|
+
end
|
105
|
+
|
106
|
+
should 'work with absolute uris' do
|
107
|
+
got = get("#@uri/absolute_redirect")
|
108
|
+
got.status.should == 302
|
109
|
+
got.headers['Location'].should == "#@uri/noop"
|
110
|
+
got.headers['Content-Type'].should == "text/html"
|
111
|
+
end
|
112
|
+
|
113
|
+
should 'support #respond' do
|
114
|
+
got = get("#@uri/loop")
|
115
|
+
got.status.should == 200
|
116
|
+
got.body.should == 'no loop'
|
117
|
+
end
|
118
|
+
|
119
|
+
should 'support #respond with status' do
|
120
|
+
got = get("#@uri/respond_with_status")
|
121
|
+
got.status.should == 404
|
122
|
+
got.body.should == 'not found'
|
123
|
+
end
|
124
|
+
|
125
|
+
should 'support #respond!' do
|
126
|
+
got = get("#@uri/destructive_respond")
|
127
|
+
got.status.should == 200
|
128
|
+
got.body.should == 'destructive'
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'redirect without modifying the target' do
|
132
|
+
got = get("#@uri/redirect_unmodified")
|
133
|
+
got.status.should == 302
|
134
|
+
got.headers['Location'].should == '/noop'
|
135
|
+
end
|
136
|
+
|
137
|
+
should 'catch redirection' do
|
138
|
+
got = get("#@uri/no_actual_redirect")
|
139
|
+
got.status.should == 200
|
140
|
+
got.body.should == 'no actual redirect'
|
141
|
+
end
|
142
|
+
|
143
|
+
should 'catch double redirect' do
|
144
|
+
got = get("#@uri/no_actual_double_redirect")
|
145
|
+
got.status.should == 200
|
146
|
+
got.body.should == 'no actual double redirect'
|
147
|
+
end
|
148
|
+
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
|
data/spec/innate/node.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
Innate.options.app.root = File.dirname(__FILE__)
|
4
|
+
Innate.options.app.view = ''
|
5
|
+
Innate.options.app.layout = 'node'
|
6
|
+
|
7
|
+
class SpecNode
|
8
|
+
include Innate::Node
|
9
|
+
map '/'
|
10
|
+
provide :html => :erb, :erb => :none
|
11
|
+
|
12
|
+
def foo; end
|
13
|
+
def bar; end
|
14
|
+
def one(arg) end
|
15
|
+
def two(arg1, arg2) end
|
16
|
+
def more(*args) end
|
17
|
+
def default(arg = nil) end
|
18
|
+
end
|
19
|
+
|
20
|
+
class SpecNodeProvide
|
21
|
+
include Innate::Node
|
22
|
+
map '/provide'
|
23
|
+
|
24
|
+
provide :html => :erb, :erb => :none
|
25
|
+
|
26
|
+
def foo
|
27
|
+
'<%= 21 * 2 %>'
|
28
|
+
end
|
29
|
+
|
30
|
+
def bar
|
31
|
+
'<%= 84 / 2 %>'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class SpecNodeProvideTemplate
|
36
|
+
include Innate::Node
|
37
|
+
map '/provide_template'
|
38
|
+
|
39
|
+
provide :html => :erb, :erb => :none
|
40
|
+
|
41
|
+
view_root 'node'
|
42
|
+
end
|
43
|
+
|
44
|
+
class SpecNodeSub < SpecNode
|
45
|
+
map '/sub'
|
46
|
+
|
47
|
+
def bar(arg) end
|
48
|
+
end
|
49
|
+
|
50
|
+
class SpecNodeWithLayout < SpecNodeProvide
|
51
|
+
layout 'with_layout'
|
52
|
+
map '/layout'
|
53
|
+
end
|
54
|
+
|
55
|
+
class SpecNodeIndex
|
56
|
+
include Innate::Node
|
57
|
+
map '/spec_index'
|
58
|
+
|
59
|
+
def index
|
60
|
+
"I have no parameters"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'Innate::Node' do
|
65
|
+
behaves_like :mock
|
66
|
+
|
67
|
+
def compare(url, hash)
|
68
|
+
result = SpecNode.resolve(url)
|
69
|
+
result.should.not.be.nil
|
70
|
+
hash.each do |key, value|
|
71
|
+
result[key.to_s].should == value
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'resolve actions with methods' do
|
76
|
+
SpecNode.resolve('/').should.be.nil
|
77
|
+
SpecNode.resolve('/index').should.be.nil
|
78
|
+
|
79
|
+
compare '/foo', :method => 'foo', :params => []
|
80
|
+
SpecNode.resolve('/foo/one/two').should.be.nil
|
81
|
+
|
82
|
+
compare '/bar', :method => 'bar', :params => []
|
83
|
+
SpecNode.resolve('/bar/one').should.be.nil
|
84
|
+
|
85
|
+
SpecNode.resolve('/one').should.be.nil
|
86
|
+
compare '/one/1', :method => 'one', :params => ['1']
|
87
|
+
SpecNode.resolve('/one/1/2').should.be.nil
|
88
|
+
SpecNode.resolve('/one/1/2/3').should.be.nil
|
89
|
+
|
90
|
+
SpecNode.resolve('/two').should.be.nil
|
91
|
+
SpecNode.resolve('/two/1').should.be.nil
|
92
|
+
compare '/two/1/2', :method => 'two', :params => %w[1 2]
|
93
|
+
SpecNode.resolve('/two/1/2/3').should.be.nil
|
94
|
+
|
95
|
+
compare '/more', :method => 'more', :params => []
|
96
|
+
compare '/more/1', :method => 'more', :params => %w[1]
|
97
|
+
compare '/more/1/2', :method => 'more', :params => %w[1 2]
|
98
|
+
compare '/more/1/2/3', :method => 'more', :params => %w[1 2 3]
|
99
|
+
|
100
|
+
compare '/default', :method => 'default', :params => []
|
101
|
+
compare '/default/1', :method => 'default', :params => %w[1]
|
102
|
+
|
103
|
+
# NOTE: these are actually bound to fail when called, but we cannot
|
104
|
+
# introspect enough to anticipate this failure
|
105
|
+
compare '/default/1/2', :method => 'default', :params => %w[1 2]
|
106
|
+
compare '/default/1/2/3', :method => 'default', :params => %w[1 2 3]
|
107
|
+
end
|
108
|
+
|
109
|
+
should 'inherit action methods from superclasses' do
|
110
|
+
SpecNodeSub.resolve('/foo').should.not.be.nil
|
111
|
+
SpecNodeSub.resolve('/foo/one/two').should.be.nil
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'select correct method from subclasses' do
|
115
|
+
SpecNodeSub.resolve('/bar/one').should.not.be.nil
|
116
|
+
SpecNodeSub.resolve('/bar').should.be.nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def assert_wish(url, body, content_type)
|
120
|
+
got = get(url)
|
121
|
+
got.body.strip.should == body
|
122
|
+
got.headers['Content-Type'].should == content_type
|
123
|
+
end
|
124
|
+
|
125
|
+
should 'provide html if no wish given' do
|
126
|
+
assert_wish('/provide/foo', '42', 'text/html')
|
127
|
+
assert_wish('/provide/bar', '42', 'text/html')
|
128
|
+
end
|
129
|
+
|
130
|
+
should 'provide html as wished' do
|
131
|
+
assert_wish('/provide/foo.html', '42', 'text/html')
|
132
|
+
assert_wish('/provide/bar.html', '42', 'text/html')
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'provide erb as wished' do
|
136
|
+
assert_wish('/provide/foo.erb', "<%= 21 * 2 %>", 'text/html')
|
137
|
+
assert_wish('/provide/bar.erb', "<%= 84 / 2 %>", 'text/html')
|
138
|
+
end
|
139
|
+
|
140
|
+
should 'fulfill wish with templates' do
|
141
|
+
assert_wish('/provide_template/bar.html', "<h1>Hello, World!</h1>",
|
142
|
+
'text/html')
|
143
|
+
assert_wish('/provide_template/bar.erb', "<h1>Hello, World!</h1>",
|
144
|
+
'text/html')
|
145
|
+
|
146
|
+
expected = (0..9).to_a.join
|
147
|
+
assert_wish('/provide_template/foo.html', expected, 'text/html')
|
148
|
+
# assert_wish('/provide_template/foo.erb', expected, 'text/plain')
|
149
|
+
end
|
150
|
+
|
151
|
+
should 'respond with 404 if no action was found' do
|
152
|
+
got = Innate::Mock.get('/does_not_exist')
|
153
|
+
got.status.should == 404
|
154
|
+
got.body.should == 'Action not found at: "/does_not_exist"'
|
155
|
+
got['Content-Type'].should == 'text/plain'
|
156
|
+
end
|
157
|
+
|
158
|
+
should 'respond with yaml' do
|
159
|
+
assert_wish('/provide_template/bar.yaml', "--- |\n<h1>Hello, World!</h1>",
|
160
|
+
'text/yaml')
|
161
|
+
end
|
162
|
+
|
163
|
+
should 'respond with json' do
|
164
|
+
assert_wish('/provide_template/bar.json', '"<h1>Hello, World!<\\/h1>\\n"',
|
165
|
+
'application/json')
|
166
|
+
end
|
167
|
+
|
168
|
+
should 'wrap with layout' do
|
169
|
+
got = Innate::Mock.get('/layout/bar')
|
170
|
+
got.status.should == 200
|
171
|
+
got.body.should == %(<div class="content">\n 42\n</div>\n)
|
172
|
+
got['Content-Type'].should == 'text/html'
|
173
|
+
end
|
174
|
+
|
175
|
+
should 'not get an action with wrong parameters' do
|
176
|
+
got = Innate::Mock.get('/spec_index/bar')
|
177
|
+
got.status.should == 404
|
178
|
+
got.body.should == 'Action not found at: "/bar"'
|
179
|
+
end
|
180
|
+
end
|