rjspotter-innate 2009.06.29

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.
Files changed (128) hide show
  1. data/AUTHORS +10 -0
  2. data/CHANGELOG +3261 -0
  3. data/COPYING +18 -0
  4. data/MANIFEST +127 -0
  5. data/README.md +563 -0
  6. data/Rakefile +39 -0
  7. data/example/app/retro_games.rb +60 -0
  8. data/example/app/todo/layout/default.xhtml +11 -0
  9. data/example/app/todo/spec/todo.rb +63 -0
  10. data/example/app/todo/start.rb +51 -0
  11. data/example/app/todo/view/index.xhtml +39 -0
  12. data/example/app/whywiki_erb/layout/wiki.html.erb +15 -0
  13. data/example/app/whywiki_erb/spec/wiki.rb +19 -0
  14. data/example/app/whywiki_erb/start.rb +42 -0
  15. data/example/app/whywiki_erb/view/edit.erb +6 -0
  16. data/example/app/whywiki_erb/view/index.erb +12 -0
  17. data/example/custom_middleware.rb +35 -0
  18. data/example/hello.rb +11 -0
  19. data/example/howto_spec.rb +35 -0
  20. data/example/link.rb +27 -0
  21. data/example/provides.rb +31 -0
  22. data/example/session.rb +38 -0
  23. data/innate.gemspec +41 -0
  24. data/lib/innate.rb +269 -0
  25. data/lib/innate/action.rb +137 -0
  26. data/lib/innate/adapter.rb +76 -0
  27. data/lib/innate/cache.rb +134 -0
  28. data/lib/innate/cache/api.rb +128 -0
  29. data/lib/innate/cache/drb.rb +58 -0
  30. data/lib/innate/cache/file_based.rb +44 -0
  31. data/lib/innate/cache/marshal.rb +20 -0
  32. data/lib/innate/cache/memory.rb +21 -0
  33. data/lib/innate/cache/yaml.rb +20 -0
  34. data/lib/innate/current.rb +35 -0
  35. data/lib/innate/dynamap.rb +96 -0
  36. data/lib/innate/helper.rb +185 -0
  37. data/lib/innate/helper/aspect.rb +124 -0
  38. data/lib/innate/helper/cgi.rb +54 -0
  39. data/lib/innate/helper/flash.rb +36 -0
  40. data/lib/innate/helper/link.rb +94 -0
  41. data/lib/innate/helper/redirect.rb +85 -0
  42. data/lib/innate/helper/render.rb +152 -0
  43. data/lib/innate/helper/send_file.rb +26 -0
  44. data/lib/innate/log.rb +20 -0
  45. data/lib/innate/log/color_formatter.rb +49 -0
  46. data/lib/innate/log/hub.rb +77 -0
  47. data/lib/innate/middleware_compiler.rb +65 -0
  48. data/lib/innate/mock.rb +49 -0
  49. data/lib/innate/node.rb +1029 -0
  50. data/lib/innate/options.rb +37 -0
  51. data/lib/innate/options/dsl.rb +205 -0
  52. data/lib/innate/options/stub.rb +7 -0
  53. data/lib/innate/request.rb +141 -0
  54. data/lib/innate/response.rb +24 -0
  55. data/lib/innate/route.rb +114 -0
  56. data/lib/innate/session.rb +133 -0
  57. data/lib/innate/session/flash.rb +94 -0
  58. data/lib/innate/spec.rb +1 -0
  59. data/lib/innate/spec/bacon.rb +28 -0
  60. data/lib/innate/state.rb +26 -0
  61. data/lib/innate/state/accessor.rb +130 -0
  62. data/lib/innate/traited.rb +90 -0
  63. data/lib/innate/trinity.rb +18 -0
  64. data/lib/innate/version.rb +3 -0
  65. data/lib/innate/view.rb +97 -0
  66. data/lib/innate/view/erb.rb +14 -0
  67. data/lib/innate/view/etanni.rb +33 -0
  68. data/lib/innate/view/none.rb +9 -0
  69. data/spec/example/app/retro_games.rb +30 -0
  70. data/spec/example/hello.rb +13 -0
  71. data/spec/example/link.rb +25 -0
  72. data/spec/example/provides.rb +16 -0
  73. data/spec/example/session.rb +22 -0
  74. data/spec/helper.rb +10 -0
  75. data/spec/innate/action/layout.rb +121 -0
  76. data/spec/innate/action/layout/file_layout.xhtml +1 -0
  77. data/spec/innate/cache/common.rb +47 -0
  78. data/spec/innate/cache/marshal.rb +5 -0
  79. data/spec/innate/cache/memory.rb +5 -0
  80. data/spec/innate/cache/yaml.rb +5 -0
  81. data/spec/innate/dynamap.rb +22 -0
  82. data/spec/innate/helper.rb +86 -0
  83. data/spec/innate/helper/aspect.rb +75 -0
  84. data/spec/innate/helper/cgi.rb +37 -0
  85. data/spec/innate/helper/flash.rb +115 -0
  86. data/spec/innate/helper/link.rb +139 -0
  87. data/spec/innate/helper/redirect.rb +171 -0
  88. data/spec/innate/helper/render.rb +165 -0
  89. data/spec/innate/helper/send_file.rb +21 -0
  90. data/spec/innate/helper/view/aspect_hello.xhtml +1 -0
  91. data/spec/innate/helper/view/locals.xhtml +1 -0
  92. data/spec/innate/helper/view/loop.xhtml +4 -0
  93. data/spec/innate/helper/view/num.xhtml +1 -0
  94. data/spec/innate/helper/view/partial.xhtml +1 -0
  95. data/spec/innate/helper/view/recursive.xhtml +7 -0
  96. data/spec/innate/mock.rb +84 -0
  97. data/spec/innate/modes.rb +61 -0
  98. data/spec/innate/node/mapping.rb +37 -0
  99. data/spec/innate/node/node.rb +135 -0
  100. data/spec/innate/node/resolve.rb +82 -0
  101. data/spec/innate/node/view/another_layout/another_layout.xhtml +3 -0
  102. data/spec/innate/node/view/bar.xhtml +1 -0
  103. data/spec/innate/node/view/foo.html.xhtml +1 -0
  104. data/spec/innate/node/view/only_view.xhtml +1 -0
  105. data/spec/innate/node/view/with_layout.xhtml +1 -0
  106. data/spec/innate/node/wrap_action_call.rb +83 -0
  107. data/spec/innate/options.rb +123 -0
  108. data/spec/innate/parameter.rb +154 -0
  109. data/spec/innate/provides.rb +99 -0
  110. data/spec/innate/provides/list.html.xhtml +1 -0
  111. data/spec/innate/provides/list.txt.xhtml +1 -0
  112. data/spec/innate/request.rb +79 -0
  113. data/spec/innate/route.rb +135 -0
  114. data/spec/innate/session.rb +58 -0
  115. data/spec/innate/traited.rb +55 -0
  116. data/tasks/authors.rake +30 -0
  117. data/tasks/bacon.rake +66 -0
  118. data/tasks/changelog.rake +18 -0
  119. data/tasks/gem.rake +22 -0
  120. data/tasks/gem_setup.rake +99 -0
  121. data/tasks/grancher.rake +12 -0
  122. data/tasks/manifest.rake +4 -0
  123. data/tasks/rcov.rake +19 -0
  124. data/tasks/release.rake +53 -0
  125. data/tasks/reversion.rake +8 -0
  126. data/tasks/setup.rake +6 -0
  127. data/tasks/ycov.rake +84 -0
  128. metadata +218 -0
@@ -0,0 +1,171 @@
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
+
61
+ def redirect_with_cookie
62
+ response.set_cookie('user', :value => 'manveru')
63
+ redirect r(:noop)
64
+ end
65
+ end
66
+
67
+ describe Innate::Helper::Redirect do
68
+ behaves_like :rack_test
69
+
70
+ @uri = 'http://localhost:7000'
71
+
72
+ should 'retrieve index' do
73
+ get('/').body.should =='SpecRedirectHelper'
74
+ end
75
+
76
+ should 'redirect' do
77
+ get("#@uri/redirection")
78
+
79
+ last_response.status.should == 302
80
+ last_response.headers['Location'].should == "#@uri/index"
81
+ last_response.headers['Content-Type'].should == "text/html"
82
+ end
83
+
84
+ should 'redirect twice' do
85
+ get("#@uri/double_redirection")
86
+
87
+ last_response.status.should == 302
88
+ last_response.headers['Location'].should == "#@uri/redirection"
89
+ last_response.headers['Content-Type'].should == "text/html"
90
+ end
91
+
92
+ should 'redirect to referer' do
93
+ header 'HTTP_REFERER', '/index'
94
+ get("#@uri/redirect_referer_action")
95
+
96
+ last_response.status.should == 302
97
+ last_response.headers['Location'].should == "#@uri/index"
98
+ last_response.headers['Content-Type'].should == "text/html"
99
+ end
100
+
101
+ should 'redirect to fallback if referrer is identical' do
102
+ header 'HTTP_REFERER', "#@uri/redirect_referer_action"
103
+ get("#@uri/redirect_referer_action")
104
+
105
+ last_response.status.should == 302
106
+ last_response.headers['Location'].should == "#@uri/noop"
107
+ last_response.headers['Content-Type'].should == "text/html"
108
+ end
109
+
110
+ should 'use #r' do
111
+ get("#@uri/redirect_method")
112
+
113
+ last_response.status.should == 302
114
+ last_response.headers['Location'].should == "#@uri/noop"
115
+ last_response.headers['Content-Type'].should == "text/html"
116
+ end
117
+
118
+ should 'work with absolute uris' do
119
+ get("#@uri/absolute_redirect")
120
+
121
+ last_response.status.should == 302
122
+ last_response.headers['Location'].should == "#@uri/noop"
123
+ last_response.headers['Content-Type'].should == "text/html"
124
+ end
125
+
126
+ should 'support #respond' do
127
+ get("#@uri/loop")
128
+
129
+ last_response.status.should == 200
130
+ last_response.body.should == 'no loop'
131
+ end
132
+
133
+ should 'support #respond with status' do
134
+ get("#@uri/respond_with_status")
135
+
136
+ last_response.status.should == 404
137
+ last_response.body.should == 'not found'
138
+ end
139
+
140
+ should 'support #respond!' do
141
+ get("#@uri/destructive_respond")
142
+
143
+ last_response.status.should == 200
144
+ last_response.body.should == 'destructive'
145
+ end
146
+
147
+ should 'redirect without modifying the target' do
148
+ get("#@uri/redirect_unmodified")
149
+
150
+ last_response.status.should == 302
151
+ last_response.headers['Location'].should == '/noop'
152
+ end
153
+
154
+ should 'catch redirection' do
155
+ get("#@uri/no_actual_redirect")
156
+ last_response.status.should == 200
157
+ last_response.body.should == 'no actual redirect'
158
+ end
159
+
160
+ should 'catch double redirect' do
161
+ get("#@uri/no_actual_double_redirect")
162
+ last_response.status.should == 200
163
+ last_response.body.should == 'no actual double redirect'
164
+ end
165
+
166
+ should 'set cookie before redirect' do
167
+ get("#@uri/redirect_with_cookie")
168
+ follow_redirect!
169
+ last_request.cookies.should == {'user' => 'manveru'}
170
+ end
171
+ end
@@ -0,0 +1,165 @@
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
+ class SpecHelperRenderFile
78
+ Innate.node '/render_file'
79
+
80
+ layout :layout
81
+
82
+ def layout
83
+ '{ #{@content} }'
84
+ end
85
+
86
+ FILE = File.expand_path('../view/aspect_hello.xhtml', __FILE__)
87
+
88
+ def absolute
89
+ render_file(FILE)
90
+ end
91
+
92
+ def absolute_with(foo, bar)
93
+ render_file(FILE, :foo => foo, :bar => bar)
94
+ end
95
+ end
96
+
97
+ describe Innate::Helper::Render do
98
+ describe '#render_full' do
99
+ behaves_like :rack_test
100
+
101
+ it 'renders a full action' do
102
+ get('/render_full/standard').body.should == 'foo: []'
103
+ end
104
+
105
+ it 'renders full action with query parameters' do
106
+ get('/render_full/with_query').body.should == 'foo: [["a", "b"]]'
107
+ end
108
+
109
+ # this is an edge-case, we don't have a full session running if this is the
110
+ # first request from the client as Innate creates sessions only on demand
111
+ # at the end of the request/response cycle.
112
+ #
113
+ # So we have to make some request first, in this case we simply set some
114
+ # value in the session that we can get afterwards.
115
+
116
+ it 'renders full action inside a session' do
117
+ get('/render_full/set_session/user/manveru')
118
+ get('/render_full/with_session').body.should == '"manveru"'
119
+ end
120
+ end
121
+
122
+ describe '#render_partial' do
123
+ behaves_like :rack_test
124
+
125
+ it 'renders action with layout' do
126
+ get('/render_partial/standard').body.should == '{ hello }'
127
+ end
128
+
129
+ it 'renders partial action without layout' do
130
+ get('/render_partial/without_layout').body.should == '{ hello }'
131
+ end
132
+ end
133
+
134
+ describe '#render_view' do
135
+ behaves_like :rack_test
136
+
137
+ it 'renders action without calling the method or applying layout' do
138
+ get('/render_view/without_method_or_layout').body.should == '{ 42 }'
139
+ end
140
+ end
141
+
142
+ describe 'misc functionality' do
143
+ behaves_like :rack_test
144
+
145
+ it 'can render_partial in a loop' do
146
+ get('/misc/loop').body.scan(/\d+/).should == %w[1 2 3 4 5]
147
+ end
148
+
149
+ it 'can recursively render_partial' do
150
+ get('/misc/recursive').body.scan(/\S/).join.should == '{1{2{3{44}3}2}1}'
151
+ end
152
+ end
153
+
154
+ describe '#render_file' do
155
+ behaves_like :rack_test
156
+
157
+ it 'renders file from absolute path' do
158
+ get('/render_file/absolute').body.should == '{ ! }'
159
+ end
160
+
161
+ it 'renders file from absolute path with variables' do
162
+ get('/render_file/absolute_with/one/two').body.should == '{ one two! }'
163
+ end
164
+ end
165
+ 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,4 @@
1
+ <?r (1..5).each do |n| ?>
2
+ <?r @n = n ?>
3
+ #{ render_partial('num') }
4
+ <?r end ?>
@@ -0,0 +1 @@
1
+ #{@n}
@@ -0,0 +1 @@
1
+ From Partial #{@here}
@@ -0,0 +1,7 @@
1
+ {
2
+ #{@n}
3
+ <?r if @n < 4 ?>
4
+ #{ render_partial(:recursive, :n => @n + 1) }
5
+ <?r end ?>
6
+ #{@n}
7
+ }
@@ -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