renee 0.3.11 → 0.4.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. data/Gemfile +17 -0
  2. data/Gemfile-renee +8 -0
  3. data/Gemfile-renee-core +8 -0
  4. data/Gemfile-renee-render +9 -0
  5. data/Gemfile-renee-session +9 -0
  6. data/Gemfile-renee-url-generation +8 -0
  7. data/MIT-LICENSE.txt +7 -0
  8. data/README-renee-core.md +242 -0
  9. data/README-renee-render.md +38 -0
  10. data/README-renee-session.md +3 -0
  11. data/README-renee-url-generation.md +3 -0
  12. data/README.md +131 -6
  13. data/Rakefile +109 -9
  14. data/TODO.txt +45 -0
  15. data/config.ru +26 -0
  16. data/examples/blog/blog.rb +3 -1
  17. data/examples/blog/config.ru +24 -19
  18. data/examples/blog/views/edit.erb +10 -1
  19. data/examples/blog/views/show.erb +5 -0
  20. data/lib/renee.rb +11 -4
  21. data/lib/renee/core.rb +98 -0
  22. data/lib/renee/core/chaining.rb +66 -0
  23. data/lib/renee/core/env_accessors.rb +72 -0
  24. data/lib/renee/core/exceptions.rb +15 -0
  25. data/lib/renee/core/matcher.rb +61 -0
  26. data/lib/renee/core/plugins.rb +31 -0
  27. data/lib/renee/core/rack_interaction.rb +50 -0
  28. data/lib/renee/core/request_context.rb +56 -0
  29. data/lib/renee/core/responding.rb +112 -0
  30. data/lib/renee/core/response.rb +78 -0
  31. data/lib/renee/core/routing.rb +319 -0
  32. data/lib/renee/core/transform.rb +18 -0
  33. data/lib/renee/render.rb +221 -0
  34. data/lib/renee/session.rb +50 -0
  35. data/lib/renee/url_generation.rb +117 -0
  36. data/lib/renee/util.rb +7 -0
  37. data/lib/renee/version.rb +2 -4
  38. data/plan.txt +19 -0
  39. data/renee-core.gemspec +26 -0
  40. data/renee-render.gemspec +30 -0
  41. data/renee-session.gemspec +28 -0
  42. data/renee-url-generation.gemspec +24 -0
  43. data/renee.gemspec +5 -6
  44. data/site/MIT-LICENSE.txt +7 -0
  45. data/site/public/css/app.css +75 -0
  46. data/site/public/docs/renee-core/Renee.html +208 -0
  47. data/site/public/docs/renee-core/Renee/Core.html +366 -0
  48. data/site/public/docs/renee-core/Renee/Core/Chaining.html +192 -0
  49. data/site/public/docs/renee-core/Renee/Core/ClassMethods.html +725 -0
  50. data/site/public/docs/renee-core/Renee/Core/ClientError.html +317 -0
  51. data/site/public/docs/renee-core/Renee/Core/EnvAccessors.html +152 -0
  52. data/site/public/docs/renee-core/Renee/Core/EnvAccessors/ClassMethods.html +354 -0
  53. data/site/public/docs/renee-core/Renee/Core/Matcher.html +675 -0
  54. data/site/public/docs/renee-core/Renee/Core/Plugins.html +475 -0
  55. data/site/public/docs/renee-core/Renee/Core/RackInteraction.html +488 -0
  56. data/site/public/docs/renee-core/Renee/Core/RequestContext.html +511 -0
  57. data/site/public/docs/renee-core/Renee/Core/Responding.html +877 -0
  58. data/site/public/docs/renee-core/Renee/Core/Response.html +691 -0
  59. data/site/public/docs/renee-core/Renee/Core/Routing.html +1589 -0
  60. data/site/public/docs/renee-core/Renee/Core/Transform.html +249 -0
  61. data/site/public/docs/renee-core/Renee/Core/URLGeneration.html +597 -0
  62. data/site/public/docs/renee-core/_index.html +244 -0
  63. data/site/public/docs/renee-core/class_list.html +47 -0
  64. data/site/public/docs/renee-core/css/common.css +1 -0
  65. data/site/public/docs/renee-core/css/full_list.css +55 -0
  66. data/site/public/docs/renee-core/css/style.css +322 -0
  67. data/site/public/docs/renee-core/file.README-renee-core.html +341 -0
  68. data/site/public/docs/renee-core/file.README.html +212 -0
  69. data/site/public/docs/renee-core/file_list.html +49 -0
  70. data/site/public/docs/renee-core/frames.html +13 -0
  71. data/site/public/docs/renee-core/index.html +341 -0
  72. data/site/public/docs/renee-core/js/app.js +205 -0
  73. data/site/public/docs/renee-core/js/full_list.js +167 -0
  74. data/site/public/docs/renee-core/js/jquery.js +16 -0
  75. data/site/public/docs/renee-core/method_list.html +590 -0
  76. data/site/public/docs/renee-core/top-level-namespace.html +103 -0
  77. data/site/public/docs/renee-render/Renee.html +116 -0
  78. data/site/public/docs/renee-render/Renee/Core.html +346 -0
  79. data/site/public/docs/renee-render/Renee/Core/Chaining.html +125 -0
  80. data/site/public/docs/renee-render/Renee/Core/ClassMethods.html +620 -0
  81. data/site/public/docs/renee-render/Renee/Core/ClientError.html +317 -0
  82. data/site/public/docs/renee-render/Renee/Core/EnvAccessors.html +152 -0
  83. data/site/public/docs/renee-render/Renee/Core/EnvAccessors/ClassMethods.html +354 -0
  84. data/site/public/docs/renee-render/Renee/Core/Matcher.html +675 -0
  85. data/site/public/docs/renee-render/Renee/Core/RackInteraction.html +488 -0
  86. data/site/public/docs/renee-render/Renee/Core/RequestContext.html +421 -0
  87. data/site/public/docs/renee-render/Renee/Core/Responding.html +873 -0
  88. data/site/public/docs/renee-render/Renee/Core/Response.html +691 -0
  89. data/site/public/docs/renee-render/Renee/Core/Routing.html +1682 -0
  90. data/site/public/docs/renee-render/Renee/Core/Transform.html +249 -0
  91. data/site/public/docs/renee-render/Renee/Core/URLGeneration.html +597 -0
  92. data/site/public/docs/renee-render/Renee/Render.html +873 -0
  93. data/site/public/docs/renee-render/Renee/Render/ClassMethods.html +382 -0
  94. data/site/public/docs/renee-render/Renee/Render/TemplateNotFound.html +126 -0
  95. data/site/public/docs/renee-render/_index.html +143 -0
  96. data/site/public/docs/renee-render/class_list.html +47 -0
  97. data/site/public/docs/renee-render/css/common.css +1 -0
  98. data/site/public/docs/renee-render/css/full_list.css +55 -0
  99. data/site/public/docs/renee-render/css/style.css +322 -0
  100. data/site/public/docs/renee-render/file.README-renee-render.html +104 -0
  101. data/site/public/docs/renee-render/file.README.html +212 -0
  102. data/site/public/docs/renee-render/file_list.html +49 -0
  103. data/site/public/docs/renee-render/frames.html +13 -0
  104. data/site/public/docs/renee-render/index.html +104 -0
  105. data/site/public/docs/renee-render/js/app.js +205 -0
  106. data/site/public/docs/renee-render/js/full_list.js +167 -0
  107. data/site/public/docs/renee-render/js/jquery.js +16 -0
  108. data/site/public/docs/renee-render/method_list.html +110 -0
  109. data/site/public/docs/renee-render/top-level-namespace.html +103 -0
  110. data/site/public/docs/renee-session/Renee.html +106 -0
  111. data/site/public/docs/renee-session/Renee/Session.html +173 -0
  112. data/site/public/docs/renee-session/Renee/Session/ClassMethods.html +470 -0
  113. data/site/public/docs/renee-session/_index.html +136 -0
  114. data/site/public/docs/renee-session/class_list.html +47 -0
  115. data/site/public/docs/renee-session/css/common.css +1 -0
  116. data/site/public/docs/renee-session/css/full_list.css +55 -0
  117. data/site/public/docs/renee-session/css/style.css +322 -0
  118. data/site/public/docs/renee-session/file.README-renee-core.html +341 -0
  119. data/site/public/docs/renee-session/file.README-renee-session.html +69 -0
  120. data/site/public/docs/renee-session/file_list.html +49 -0
  121. data/site/public/docs/renee-session/frames.html +13 -0
  122. data/site/public/docs/renee-session/index.html +69 -0
  123. data/site/public/docs/renee-session/js/app.js +205 -0
  124. data/site/public/docs/renee-session/js/full_list.js +167 -0
  125. data/site/public/docs/renee-session/js/jquery.js +16 -0
  126. data/site/public/docs/renee-session/method_list.html +102 -0
  127. data/site/public/docs/renee-session/top-level-namespace.html +103 -0
  128. data/site/public/docs/renee-url-generation/Renee.html +208 -0
  129. data/site/public/docs/renee-url-generation/Renee/Core.html +366 -0
  130. data/site/public/docs/renee-url-generation/Renee/Core/Chaining.html +192 -0
  131. data/site/public/docs/renee-url-generation/Renee/Core/ClassMethods.html +725 -0
  132. data/site/public/docs/renee-url-generation/Renee/Core/ClientError.html +317 -0
  133. data/site/public/docs/renee-url-generation/Renee/Core/EnvAccessors.html +152 -0
  134. data/site/public/docs/renee-url-generation/Renee/Core/EnvAccessors/ClassMethods.html +354 -0
  135. data/site/public/docs/renee-url-generation/Renee/Core/Matcher.html +675 -0
  136. data/site/public/docs/renee-url-generation/Renee/Core/Plugins.html +475 -0
  137. data/site/public/docs/renee-url-generation/Renee/Core/RackInteraction.html +488 -0
  138. data/site/public/docs/renee-url-generation/Renee/Core/RequestContext.html +511 -0
  139. data/site/public/docs/renee-url-generation/Renee/Core/Responding.html +877 -0
  140. data/site/public/docs/renee-url-generation/Renee/Core/Response.html +691 -0
  141. data/site/public/docs/renee-url-generation/Renee/Core/Routing.html +1589 -0
  142. data/site/public/docs/renee-url-generation/Renee/Core/Transform.html +249 -0
  143. data/site/public/docs/renee-url-generation/_index.html +244 -0
  144. data/site/public/docs/renee-url-generation/class_list.html +47 -0
  145. data/site/public/docs/renee-url-generation/css/common.css +1 -0
  146. data/site/public/docs/renee-url-generation/css/full_list.css +55 -0
  147. data/site/public/docs/renee-url-generation/css/style.css +322 -0
  148. data/site/public/docs/renee-url-generation/file.README-renee-url-generation.html +69 -0
  149. data/site/public/docs/renee-url-generation/file_list.html +49 -0
  150. data/site/public/docs/renee-url-generation/frames.html +13 -0
  151. data/site/public/docs/renee-url-generation/index.html +69 -0
  152. data/site/public/docs/renee-url-generation/js/app.js +205 -0
  153. data/site/public/docs/renee-url-generation/js/full_list.js +167 -0
  154. data/site/public/docs/renee-url-generation/js/jquery.js +16 -0
  155. data/site/public/docs/renee-url-generation/method_list.html +590 -0
  156. data/site/public/docs/renee-url-generation/top-level-namespace.html +103 -0
  157. data/site/public/docs/renee/Renee.html +232 -0
  158. data/site/public/docs/renee/Renee/Application.html +367 -0
  159. data/site/public/docs/renee/Renee/Core.html +370 -0
  160. data/site/public/docs/renee/Renee/Core/Chaining.html +192 -0
  161. data/site/public/docs/renee/Renee/Core/ClassMethods.html +725 -0
  162. data/site/public/docs/renee/Renee/Core/ClientError.html +317 -0
  163. data/site/public/docs/renee/Renee/Core/EnvAccessors.html +152 -0
  164. data/site/public/docs/renee/Renee/Core/EnvAccessors/ClassMethods.html +354 -0
  165. data/site/public/docs/renee/Renee/Core/Matcher.html +675 -0
  166. data/site/public/docs/renee/Renee/Core/Plugins.html +475 -0
  167. data/site/public/docs/renee/Renee/Core/RackInteraction.html +488 -0
  168. data/site/public/docs/renee/Renee/Core/RequestContext.html +511 -0
  169. data/site/public/docs/renee/Renee/Core/Responding.html +877 -0
  170. data/site/public/docs/renee/Renee/Core/Response.html +691 -0
  171. data/site/public/docs/renee/Renee/Core/Routing.html +1589 -0
  172. data/site/public/docs/renee/Renee/Core/Transform.html +249 -0
  173. data/site/public/docs/renee/Renee/Core/URLGeneration.html +597 -0
  174. data/site/public/docs/renee/Renee/Render.html +877 -0
  175. data/site/public/docs/renee/Renee/Render/ClassMethods.html +382 -0
  176. data/site/public/docs/renee/Renee/Render/TemplateNotFound.html +126 -0
  177. data/site/public/docs/renee/Renee/Session.html +177 -0
  178. data/site/public/docs/renee/Renee/Session/ClassMethods.html +470 -0
  179. data/site/public/docs/renee/Renee/URLGeneration.html +142 -0
  180. data/site/public/docs/renee/Renee/URLGeneration/ClassMethods.html +593 -0
  181. data/site/public/docs/renee/Renee/Util.html +163 -0
  182. data/site/public/docs/renee/_index.html +336 -0
  183. data/site/public/docs/renee/class_list.html +47 -0
  184. data/site/public/docs/renee/css/common.css +1 -0
  185. data/site/public/docs/renee/css/full_list.css +55 -0
  186. data/site/public/docs/renee/css/style.css +322 -0
  187. data/site/public/docs/renee/file.README.html +212 -0
  188. data/site/public/docs/renee/file_list.html +49 -0
  189. data/site/public/docs/renee/frames.html +13 -0
  190. data/site/public/docs/renee/index.html +212 -0
  191. data/site/public/docs/renee/js/app.js +205 -0
  192. data/site/public/docs/renee/js/full_list.js +167 -0
  193. data/site/public/docs/renee/js/jquery.js +16 -0
  194. data/site/public/docs/renee/method_list.html +758 -0
  195. data/site/public/docs/renee/top-level-namespace.html +202 -0
  196. data/site/public/img/favicon.ico +0 -0
  197. data/site/public/img/reneeclean.png +0 -0
  198. data/site/public/img/russiangithub.png +0 -0
  199. data/site/public/img/stoneposter.png +0 -0
  200. data/site/public/img/vospit.jpeg +0 -0
  201. data/site/views/chaining.md +32 -0
  202. data/site/views/index.md +219 -0
  203. data/site/views/layouts/app.haml +16 -0
  204. data/site/views/rack-integration.md +51 -0
  205. data/site/views/responding.md +103 -0
  206. data/site/views/route-generation.md +82 -0
  207. data/site/views/routing.md +261 -0
  208. data/site/views/settings.md +19 -0
  209. data/site/views/team-renee.md +13 -0
  210. data/site/views/tutorial.md +57 -0
  211. data/site/views/variable-types.md +57 -0
  212. data/test.watchr +61 -0
  213. data/test/renee-core/chaining_test.rb +33 -0
  214. data/test/renee-core/env_accessors_test.rb +43 -0
  215. data/test/renee-core/include_test.rb +14 -0
  216. data/test/renee-core/request_context_test.rb +70 -0
  217. data/test/renee-core/responding_test.rb +128 -0
  218. data/test/renee-core/routing_test.rb +443 -0
  219. data/test/renee-core/test_helper.rb +4 -0
  220. data/test/renee-core/variable_type_test.rb +57 -0
  221. data/test/renee-render/render_test.rb +162 -0
  222. data/test/renee-render/test_helper.rb +9 -0
  223. data/test/renee-session/session_test.rb +31 -0
  224. data/test/renee-session/test_helper.rb +9 -0
  225. data/test/renee-url-generation/test_helper.rb +10 -0
  226. data/test/renee-url-generation/url_generation_test.rb +63 -0
  227. data/test/{blog_test.rb → renee/blog_test.rb} +10 -5
  228. data/test/renee/test_helper.rb +56 -0
  229. data/test/test_helper.rb +23 -10
  230. metadata +333 -156
  231. data/.yardopts +0 -6
@@ -0,0 +1,19 @@
1
+ # Settings
2
+
3
+ Configuration in Renee is simply using the `#setup` command to set
4
+ the appropriate options within a Renee application:
5
+
6
+ :::ruby
7
+ Renee { ... }.setup do
8
+ views_path "./views"
9
+ include Some::Module
10
+ end
11
+
12
+ The available configuration options are:
13
+
14
+ * `views_path`: The path to the templates within an application.
15
+ * `include`: Register a module within an application.
16
+ * `register_variable_type`: Allows [registration of arbitrary param types](/variable-types).
17
+
18
+ More options are to come based on Renee configuration needs as they arise.
19
+
@@ -0,0 +1,13 @@
1
+ # Team Renee
2
+
3
+ * [Arthur](https://github.com/achiu)
4
+ * [Josh](https://github.com/joshbuddy)
5
+ * [Nathan](https://github.com/nesquena)
6
+
7
+ Josh thought this up when he started working on a new routing DSL for Goliath.
8
+ Once you combine the controller and the router, everything is easy!
9
+ Nathan did the rendering, lots of ideas and amazing documentation.
10
+ Arthur mumbles things and makes test pass. Before he makes them pass, he first makes them exist.
11
+
12
+ Oh yeah, and there is also Renee. She didn't write any of this, just keeps handing me
13
+ cups of really strong tea while I work on it. Thank you.
@@ -0,0 +1,57 @@
1
+ # Tutorial
2
+
3
+ This is the most basic ever tutorial, and admittedly, a lot of it is boilerplate setup. But hopefully, this demonstrates how easy it is to get up and running with Renee.
4
+
5
+ ## Create a project and install your gems
6
+
7
+ :::terminal
8
+ $> mkdir renee-tutorial
9
+ $> cd renee-tutorial
10
+ $> bundle init
11
+ Writing new Gemfile to /Users/joshbuddy/Gemfile/renee-tutorial
12
+ $> mate .
13
+
14
+ Now in your editor, type:
15
+
16
+ :::ruby
17
+ source "http://rubygems.org"
18
+
19
+ gem 'renee', '~> 0.3.0'
20
+ gem 'shotgun'
21
+
22
+ Go back to your tutorial and install that dog!
23
+
24
+ :::terminal
25
+ $> bundle
26
+ Installing bundler (1.0.21)
27
+ Installing callsite (0.0.6)
28
+ Installing rack (1.3.5)
29
+ Installing renee-core (0.2.0)
30
+ Installing tilt (1.3.3)
31
+ Installing renee-render (0.2.0)
32
+ Installing renee (0.2.0)
33
+ Installing shotgun (0.9)
34
+ Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
35
+
36
+ ## Write a hello world
37
+
38
+ In your editor, create the file `config.ru`. Now, edit that file.
39
+
40
+ :::ruby
41
+ require 'renee'
42
+
43
+ run Renee {
44
+ halt "hello world!"
45
+ }
46
+
47
+ Back in your terminal, run:
48
+
49
+ :::terminal
50
+ $> bundle exec shotgun
51
+ == Shotgun/WEBrick on http://127.0.0.1:9393/
52
+ [2011-10-19 21:53:26] INFO WEBrick 1.3.1
53
+ [2011-10-19 21:53:26] INFO ruby 1.8.7 (2011-06-30) [i686-darwin11.2.0]
54
+ [2011-10-19 21:53:26] INFO WEBrick::HTTPServer#start: pid=4312 port=9393
55
+
56
+ Now, point your browser to `http://localhost:9393/`! Enjoy!
57
+
@@ -0,0 +1,57 @@
1
+ # Variable types
2
+
3
+ Renee makes it easy to add variable types and use them!
4
+
5
+ ## Registering
6
+
7
+ To create a variable type, in your [setup block](/settings), add a #register_variable_type call. Example:
8
+
9
+ :::ruby
10
+ register_variable_type(:hex, # The name
11
+ /[0-9a-f]{6}/). # Part to capture
12
+ on_transform { |v| v.to_i(16) }. # How to transform
13
+ raise_on_error! # What to do when you can't
14
+ # capture
15
+
16
+ First, a registered type needs to have a name. Then, a regexp specifying what to match needs to be provided. If you want to transform the result, use `#on_transform` to pass a block to be called when this type is being used. If a type is attempted to be used, and the regexp doesn't manage to capture anything, the error handler is used to determine what to do. By default, there is no error handler, and so, your programs execution will continue normally. However, if you use`#on_error`, you can supply a block to be called in the event of an error. As a convenience, there is a `#raise_on_error!` method that will halt with a 400, or, if you choose, any HTTP error code you wish (which is an optional parameter to `#raise_on_error!`).
17
+
18
+ ## Default types
19
+
20
+ By default, `:int` and `:integer` will ensure your variable is an `Integer`.
21
+
22
+ ## Errors
23
+
24
+ The `#on_error` handler will accept a block. This block will then be executed in the context of your application. Feel free to `#render`, `#halt`, or do anything else you desire.
25
+
26
+ ## Compound types
27
+
28
+ Types can also be composed from other defined types by supplying a list of other types. Here is an example:
29
+
30
+ :::ruby
31
+ regster_variable_type(:hex, /0x[0-9a-f]+/).on_transform{|v| v.to_i(16)}
32
+ regster_variable_type(:octal, /0[0-7]+/) .on_transform{|v| v.to_i(8)}
33
+ regster_variable_type(:number, [:hex, :octal])
34
+
35
+ Now, `:number` will attempt to use the `:hex` matcher, then, the `:octal` matcher. Compound types can even have their own error matching.
36
+
37
+ ## Aliasing types
38
+
39
+ As well, you can create as many type aliases as you want. Just do this:
40
+
41
+ :::ruby
42
+ regster_variable_type(:num, :int)
43
+
44
+ Now, you can refer to `:num` wherever you'd like.
45
+
46
+ ## Using variable types outside of path variables
47
+
48
+ Sometimes, it would be nice to have access to the these variable types outside of the context of your path variables. If you wish, you can use `#transform` to recognize and transform an arbitrary `String`. Here is an example:
49
+
50
+ :::ruby
51
+ run Renee {
52
+ get.halt "It turns out octal 0123 is #{transform(:octal, "0123")} in decimal."
53
+ }.setup {
54
+ register_variable_type(:octal, /0[0-7]+/).on_transform{|v| v.to_i(8)}
55
+ }
56
+
57
+ You'll get `It turns out octal 0123 is 83 in decimal.` What fun!
data/test.watchr ADDED
@@ -0,0 +1,61 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ if not growlnotify.empty?
7
+ title = "Watchr Test Results"
8
+ image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
9
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
10
+ system %(#{growlnotify} #{options} &)
11
+ else
12
+ puts message
13
+ end
14
+ end
15
+
16
+ def run(cmd)
17
+ puts(cmd); `#{cmd}`
18
+ end
19
+
20
+ def run_test_file(file)
21
+ system('clear')
22
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
23
+ growl result.split("\n").last rescue nil
24
+ puts result
25
+ end
26
+
27
+ def run_all_tests
28
+ system('clear')
29
+ result = run "rake test"
30
+ growl result.split("\n").last rescue nil
31
+ puts result
32
+ end
33
+
34
+ def related_test_files(path)
35
+ Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ }
36
+ end
37
+
38
+ watch('.*/test/test_helper\.rb') { run_all_tests }
39
+ watch('.*/test/(.*).*_test\.rb') { |m| run_test_file(m[0]) }
40
+ watch('.*/lib/(.*)\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
41
+
42
+ # Ctrl-\
43
+ Signal.trap 'QUIT' do
44
+ puts " --- Running all tests ---\n\n"
45
+ run_all_tests
46
+ end
47
+
48
+ @interrupted = false
49
+
50
+ # Ctrl-C
51
+ Signal.trap 'INT' do
52
+ if @interrupted then
53
+ @wants_to_quit = true
54
+ abort("\n")
55
+ else
56
+ puts "Interrupt a second time to quit"
57
+ @interrupted = true
58
+ Kernel.sleep 1.5
59
+ run_all_tests
60
+ end
61
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe "Route chaining" do
4
+
5
+ it "should chaining" do
6
+ type = { 'Content-Type' => 'text/plain' }
7
+ mock_app do
8
+ path('/').get { halt [200,type,['foo']] }
9
+ continue_routing.path('bar').put { halt [200,type,['bar']] }
10
+ continue_routing.path('bar').var.put { |id| halt [200,type,[id]] }
11
+ continue_routing.path('bar').var.get.halt { |id| "wow, nice to meet you " }
12
+ end
13
+ get '/'
14
+ assert_equal 200, response.status
15
+ assert_equal 'foo', response.body
16
+ put '/bar'
17
+ assert_equal 200, response.status
18
+ assert_equal 'bar', response.body
19
+ put '/bar/asd'
20
+ assert_equal 200, response.status
21
+ assert_equal 'asd', response.body
22
+ end
23
+
24
+ it "should chain and halt with a non-routing method" do
25
+ type = { 'Content-Type' => 'text/plain' }
26
+ mock_app do
27
+ path('/').get.halt "hi"
28
+ end
29
+ get '/'
30
+ assert_equal 200, response.status
31
+ assert_equal 'hi', response.body
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.expand_path('../test_helper', __FILE__)
4
+
5
+ describe Renee::Core::EnvAccessors do
6
+ it "should allow accessing the env" do
7
+ @app = Renee.core {
8
+ self.test = 'hello'
9
+ path('test').get do
10
+ halt "test is #{test}"
11
+ end
12
+ }.setup {
13
+ env_accessor :test
14
+ }
15
+ get '/test'
16
+ assert_equal 200, response.status
17
+ assert_equal 'test is hello', response.body
18
+ end
19
+
20
+ it "should raise when you try to access weird env keys" do
21
+ assert_raises(Renee::Core::EnvAccessors::InvalidEnvNameError) {
22
+ @app = Renee.core {
23
+ self.test_test = 'hello'
24
+ }.setup {
25
+ env_accessor "test.test"
26
+ }
27
+ }
28
+ end
29
+
30
+ it "should allow weird env keys if you map them" do
31
+ @app = Renee.core {
32
+ self.test_test = 'hello'
33
+ path('test').get do
34
+ halt "test is #{test_test}"
35
+ end
36
+ }.setup {
37
+ env_accessor "test.test" => :test_test
38
+ }
39
+ get '/test'
40
+ assert_equal 200, response.status
41
+ assert_equal 'test is hello', response.body
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe "Route::Settings#include" do
4
+ it "should allow the inclusion of arbitrary modules" do
5
+ type = { 'Content-Type' => 'text/plain' }
6
+ @app = Renee.core {
7
+ halt :ok if respond_to?(:hi)
8
+ }.setup {
9
+ include Module.new { def hi; end }
10
+ }
11
+ get '/'
12
+ assert_equal 200, response.status
13
+ end
14
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class AddHelloThereMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ if env['hello']
10
+ env['hello'] << "there"
11
+ else
12
+ env['hello'] = 'hello'
13
+ end
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ class AddWhatsThatMiddleware
19
+ def initialize(app)
20
+ @app = app
21
+ end
22
+
23
+ def call(env)
24
+ if env['hello']
25
+ env['hello'] << "that"
26
+ else
27
+ env['hello'] = 'whats'
28
+ end
29
+ @app.call(env)
30
+ end
31
+ end
32
+
33
+ describe "Route::Core::RequestContext#use" do
34
+ it "should allow the inclusion of arbitrary middlewares" do
35
+ type = { 'Content-Type' => 'text/plain' }
36
+ @app = Renee.core {
37
+ halt env['hello']
38
+ }.setup {
39
+ use AddHelloThereMiddleware
40
+ }
41
+ get '/'
42
+ assert_equal 200, response.status
43
+ assert_equal 'hello', response.body
44
+ end
45
+
46
+ it "should call middlewares in sequence (1)" do
47
+ type = { 'Content-Type' => 'text/plain' }
48
+ @app = Renee.core {
49
+ halt env['hello']
50
+ }.setup {
51
+ use AddHelloThereMiddleware
52
+ use AddWhatsThatMiddleware
53
+ }
54
+ get '/'
55
+ assert_equal 200, response.status
56
+ assert_equal 'hellothat', response.body
57
+ end
58
+
59
+ it "should call middlewares in sequence (2)" do
60
+ @app = Renee.core {
61
+ halt env['hello']
62
+ }.setup {
63
+ use AddWhatsThatMiddleware
64
+ use AddHelloThereMiddleware
65
+ }
66
+ get '/'
67
+ assert_equal 200, response.status
68
+ assert_equal 'whatsthere', response.body
69
+ end
70
+ end
@@ -0,0 +1,128 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ describe Renee::Core::Responding do
4
+ describe "#interpret_response" do
5
+ it "should render from a number" do
6
+ mock_app do
7
+ path('/') { halt 200 }
8
+ end
9
+ get '/'
10
+ assert_equal 200, response.status
11
+ assert_equal 'Status code 200', response.body
12
+ end
13
+
14
+ it "should render from a symbol" do
15
+ mock_app do
16
+ path('/') { halt :not_found }
17
+ end
18
+ get '/'
19
+ assert_equal 404, response.status
20
+ assert_equal 'Status code 404', response.body
21
+ end
22
+
23
+ it "should render from a string" do
24
+ mock_app do
25
+ path('/') { halt "hello!" }
26
+ end
27
+ get '/'
28
+ assert_equal 200, response.status
29
+ assert_equal 'hello!', response.body
30
+ end
31
+
32
+ it "should render from an array" do
33
+ mock_app do
34
+ path('/') { halt 500, "hello!" }
35
+ end
36
+ get '/'
37
+ assert_equal 500, response.status
38
+ assert_equal 'hello!', response.body
39
+ end
40
+
41
+ it "should render from an array with a symbol" do
42
+ mock_app do
43
+ path('/') { halt :payment_required, "hello!" }
44
+ end
45
+ get '/'
46
+ assert_equal 403, response.status
47
+ assert_equal 'hello!', response.body
48
+ end
49
+
50
+ it "should render a rack-sized array as a rack response" do
51
+ mock_app do
52
+ path('/') { halt [200, {'Content-Type' => 'text/plain'}, []] }
53
+ end
54
+ get '/'
55
+ assert_equal 200, response.status
56
+ end
57
+ end
58
+
59
+ describe "#respond" do
60
+ it "should allow respond! with response init arguments" do
61
+ mock_app do
62
+ get do
63
+ respond!("hello!", 403, "foo" => "bar")
64
+ end
65
+ end
66
+ get "/"
67
+ assert_equal 403, response.status
68
+ assert_equal "bar", response.headers["foo"]
69
+ assert_equal "hello!", response.body
70
+ end # respond!
71
+
72
+ it "should allow respond!" do
73
+ mock_app do
74
+ get do
75
+ respond! { status 403; headers :foo => "bar"; body "hello!" }
76
+ end
77
+ end
78
+ get "/"
79
+ assert_equal 403, response.status
80
+ assert_equal "bar", response.headers["foo"]
81
+ assert_equal "hello!", response.body
82
+ end # respond!
83
+
84
+ it "should allow respond" do
85
+ mock_app do
86
+ get do
87
+ halt(respond { status 403; headers :foo => "bar"; body "hello!" })
88
+ end
89
+ end
90
+ get "/"
91
+ assert_equal 403, response.status
92
+ assert_equal "bar", response.headers["foo"]
93
+ assert_equal "hello!", response.body
94
+ end # respond
95
+ end
96
+
97
+ describe "#redirect" do
98
+ it "should allow redirects" do
99
+ mock_app do
100
+ get { halt redirect('/hello') }
101
+ end
102
+
103
+ get '/'
104
+ assert_equal 302, response.status
105
+ assert_equal "/hello", response.headers['Location']
106
+ end
107
+
108
+ it "should accept custom status codes" do
109
+ mock_app do
110
+ get { halt redirect('/hello', 303) }
111
+ end
112
+
113
+ get '/'
114
+ assert_equal 303, response.status
115
+ assert_equal "/hello", response.headers['Location']
116
+ end
117
+
118
+ it "should allow redirect!" do
119
+ mock_app do
120
+ get { redirect!('/hello') }
121
+ end
122
+
123
+ get '/'
124
+ assert_equal 302, response.status
125
+ assert_equal "/hello", response.headers['Location']
126
+ end
127
+ end
128
+ end