rad_core 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. data/Rakefile +10 -0
  2. data/lib/rad/controller/abstract_controller/micelaneous.rb +31 -0
  3. data/lib/rad/controller/abstract_controller/render.rb +160 -0
  4. data/lib/rad/controller/abstract_controller/responder.rb +17 -0
  5. data/lib/rad/controller/abstract_controller.rb +64 -0
  6. data/lib/rad/controller/controller_context.rb +15 -0
  7. data/lib/rad/controller/http_controller.rb +48 -0
  8. data/lib/rad/controller/processors/controller_caller.rb +28 -0
  9. data/lib/rad/controller/processors/controller_error_handling.rb +51 -0
  10. data/lib/rad/controller/processors/controller_logger.rb +12 -0
  11. data/lib/rad/controller.rb +28 -0
  12. data/lib/rad/conveyor/conveyor.rb +74 -0
  13. data/lib/rad/conveyor/conveyors.rb +20 -0
  14. data/lib/rad/conveyor/params.rb +14 -0
  15. data/lib/rad/conveyor/processor.rb +68 -0
  16. data/lib/rad/conveyor/processors/conveyor_logger.rb +25 -0
  17. data/lib/rad/conveyor/workspace.rb +36 -0
  18. data/lib/rad/conveyor.rb +29 -0
  19. data/lib/rad/environment/config.rb +111 -0
  20. data/lib/rad/environment/dependency_resolver.rb +107 -0
  21. data/lib/rad/environment/environment.rb +29 -0
  22. data/lib/rad/environment/files_helper.rb +55 -0
  23. data/lib/rad/environment/logger.rb +21 -0
  24. data/lib/rad/environment.rb +55 -0
  25. data/lib/rad/html/flash.rb +42 -0
  26. data/lib/rad/html/helpers/basic_html_helper.rb +83 -0
  27. data/lib/rad/html/helpers/flash_helper.rb +5 -0
  28. data/lib/rad/html/helpers/form_helper.rb +115 -0
  29. data/lib/rad/html/helpers/html_helper.rb +5 -0
  30. data/lib/rad/html/helpers/javascript_helper.rb +18 -0
  31. data/lib/rad/html/helpers/model_helper.rb +135 -0
  32. data/lib/rad/html/include_into_controller.rb +0 -0
  33. data/lib/rad/html/processors/prepare_flash.rb +26 -0
  34. data/lib/rad/html/processors/scoped_params.rb +26 -0
  35. data/lib/rad/html.rb +26 -0
  36. data/lib/rad/http/http.rb +21 -0
  37. data/lib/rad/http/http_adapter.rb +36 -0
  38. data/lib/rad/http/middleware/static_files.rb +21 -0
  39. data/lib/rad/http/processors/evaluate_format.rb +22 -0
  40. data/lib/rad/http/processors/http_logger.rb +15 -0
  41. data/lib/rad/http/processors/http_writer.rb +30 -0
  42. data/lib/rad/http/processors/prepare_params.rb +22 -0
  43. data/lib/rad/http/support/rack/fixes.rb +36 -0
  44. data/lib/rad/http/support/rack/rack_adapter.rb +67 -0
  45. data/lib/rad/http/support/rack/request.rb +42 -0
  46. data/lib/rad/http/support/rack/response.rb +86 -0
  47. data/lib/rad/http.rb +48 -0
  48. data/lib/rad/integration/controller_micelaneous_helper.rb +19 -0
  49. data/lib/rad/integration/router/abstract_routing_helper.rb +22 -0
  50. data/lib/rad/integration/router/controller_routing_helper.rb +58 -0
  51. data/lib/rad/integration/router/view_routing_helper.rb +104 -0
  52. data/lib/rad/integration.rb +30 -0
  53. data/lib/rad/mail/letter.rb +30 -0
  54. data/lib/rad/mail/mail_controller.rb +31 -0
  55. data/lib/rad/mail/mailer.rb +23 -0
  56. data/lib/rad/mail/processors/letter_builder.rb +36 -0
  57. data/lib/rad/mail.rb +15 -0
  58. data/lib/rad/profiles/mail.rb +16 -0
  59. data/lib/rad/profiles/web.rb +68 -0
  60. data/lib/rad/profiles/web_require.rb +5 -0
  61. data/lib/rad/remote/processors/remote_caller.rb +54 -0
  62. data/lib/rad/remote/processors/remote_logger.rb +13 -0
  63. data/lib/rad/remote/remote.rb +15 -0
  64. data/lib/rad/remote.rb +9 -0
  65. data/lib/rad/router/core/configurator.rb +25 -0
  66. data/lib/rad/router/core/core_routing_helper.rb +41 -0
  67. data/lib/rad/router/core/default_format_processor.rb +12 -0
  68. data/lib/rad/router/core/processors/router.rb +29 -0
  69. data/lib/rad/router/core/router.rb +271 -0
  70. data/lib/rad/router/core/simple_router.rb +23 -0
  71. data/lib/rad/router/routers/abstract_router.rb +62 -0
  72. data/lib/rad/router/routers/alias_router.rb +113 -0
  73. data/lib/rad/router/routers/restful_router.rb +113 -0
  74. data/lib/rad/router.rb +29 -0
  75. data/lib/rad/spec/controller.rb +41 -0
  76. data/lib/rad/spec/environment.rb +51 -0
  77. data/lib/rad/spec/http.rb +93 -0
  78. data/lib/rad/spec/mail.rb +31 -0
  79. data/lib/rad/spec/remote.rb +9 -0
  80. data/lib/rad/spec/router.rb +18 -0
  81. data/lib/rad/spec/template.rb +12 -0
  82. data/lib/rad/spec/view.rb +10 -0
  83. data/lib/rad/spec/xhtml.rb +33 -0
  84. data/lib/rad/spec.rb +11 -0
  85. data/lib/rad/support/active_support/locales/en/actionpack.yml +154 -0
  86. data/lib/rad/support/active_support/locales/en/activesupport.yml +36 -0
  87. data/lib/rad/support/active_support/micelaneous.rb +2 -0
  88. data/lib/rad/support/active_support/time.rb +105 -0
  89. data/lib/rad/support/active_support.rb +49 -0
  90. data/lib/rad/support/addressable.rb +45 -0
  91. data/lib/rad/support/buffered_logger.rb +44 -0
  92. data/lib/rad/support/callbacks.rb +168 -0
  93. data/lib/rad/support/exception.rb +31 -0
  94. data/lib/rad/support/filters.rb +34 -0
  95. data/lib/rad/support/format.rb +17 -0
  96. data/lib/rad/support/hacks_and_fixes.rb +23 -0
  97. data/lib/rad/support/micon.rb +13 -0
  98. data/lib/rad/support/mime.rb +13 -0
  99. data/lib/rad/support/module.rb +48 -0
  100. data/lib/rad/support/rson.rb +53 -0
  101. data/lib/rad/support/ruby_ext_with_active_support.rb +4 -0
  102. data/lib/rad/support/string.rb +26 -0
  103. data/lib/rad/support.rb +63 -0
  104. data/lib/rad/template/support/tilt.rb +68 -0
  105. data/lib/rad/template/support/tilt_fixes.rb +17 -0
  106. data/lib/rad/template/template.rb +250 -0
  107. data/lib/rad/template/template_context.rb +62 -0
  108. data/lib/rad/template.rb +25 -0
  109. data/lib/rad_core/gems.rb +31 -0
  110. data/readme.md +33 -0
  111. data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
  112. data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +11 -0
  113. data/spec/controller/abstract_controller_spec.rb +132 -0
  114. data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
  115. data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
  116. data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
  117. data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
  118. data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
  119. data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
  120. data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
  121. data/spec/controller/controller_context_spec.rb +123 -0
  122. data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
  123. data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
  124. data/spec/controller/controller_helper_spec.rb +53 -0
  125. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
  126. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
  127. data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
  128. data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
  129. data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
  130. data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
  131. data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
  132. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
  133. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
  134. data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
  135. data/spec/controller/controller_render_spec/views/MultipleActions/actions.haml +7 -0
  136. data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
  137. data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
  138. data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
  139. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +1 -0
  140. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +1 -0
  141. data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
  142. data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
  143. data/spec/controller/controller_render_spec.rb +217 -0
  144. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
  145. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
  146. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
  147. data/spec/controller/error_handling_spec.rb +117 -0
  148. data/spec/controller/http_controller_spec.rb +130 -0
  149. data/spec/controller/spec_helper.rb +19 -0
  150. data/spec/conveyor/conveyor_spec.rb +124 -0
  151. data/spec/conveyor/spec_helper.rb +3 -0
  152. data/spec/environment/config_spec/config.default.yml +3 -0
  153. data/spec/environment/config_spec/config.development.yml +3 -0
  154. data/spec/environment/config_spec/config.yml +5 -0
  155. data/spec/environment/config_spec.rb +30 -0
  156. data/spec/environment/environment_spec/path1/file1 +0 -0
  157. data/spec/environment/environment_spec/path1/some_folder/some_file +0 -0
  158. data/spec/environment/environment_spec/path2/file2 +0 -0
  159. data/spec/environment/environment_spec/path2/some_folder/some_file +0 -0
  160. data/spec/environment/environment_spec.rb +65 -0
  161. data/spec/environment/logger_spec.rb +19 -0
  162. data/spec/environment/minimal_app_spec/app.rb +1 -0
  163. data/spec/environment/minimal_app_spec.rb +25 -0
  164. data/spec/environment/spec_helper.rb +1 -0
  165. data/spec/environment/standard_app_spec/app/lib/app/init.rb +3 -0
  166. data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -0
  167. data/spec/environment/standard_app_spec/plugin_b/lib/emptygit +0 -0
  168. data/spec/environment/standard_app_spec.rb +48 -0
  169. data/spec/html/basic_html_helper_spec.rb +29 -0
  170. data/spec/html/form_helper_spec.rb +63 -0
  171. data/spec/html/javascript_helper_spec.rb +15 -0
  172. data/spec/html/model_helper_spec.rb +81 -0
  173. data/spec/html/scoped_params_spec.rb +15 -0
  174. data/spec/html/spec_helper.rb +28 -0
  175. data/spec/http/http_spec/app/lib/app/init.rb +10 -0
  176. data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
  177. data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
  178. data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +5 -0
  179. data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
  180. data/spec/http/http_spec.rb +51 -0
  181. data/spec/http/micelaneous_spec.rb +13 -0
  182. data/spec/http/spec_helper.rb +5 -0
  183. data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
  184. data/spec/integration/basic_spec.rb +79 -0
  185. data/spec/integration/controller_routing_helper_spec.rb +84 -0
  186. data/spec/integration/flash_spec.rb +206 -0
  187. data/spec/integration/spec_helper.rb +5 -0
  188. data/spec/integration/spec_helper_spec.rb +63 -0
  189. data/spec/integration/view_routing_helper_spec.rb +134 -0
  190. data/spec/mail/mail_controller_spec/views/body_template_spec/signup.erb +1 -0
  191. data/spec/mail/mail_controller_spec.rb +61 -0
  192. data/spec/mail/spec_helper.rb +7 -0
  193. data/spec/remote/remote_spec.rb +75 -0
  194. data/spec/remote/spec_helper.rb +17 -0
  195. data/spec/router/alias_router_spec.rb +98 -0
  196. data/spec/router/basic_spec.rb +111 -0
  197. data/spec/router/configurator_spec.rb +18 -0
  198. data/spec/router/integration_spec.rb +42 -0
  199. data/spec/router/persistent_params_spec.rb +65 -0
  200. data/spec/router/restful_router_spec.rb +120 -0
  201. data/spec/router/routing_helper_spec.rb +55 -0
  202. data/spec/router/spec_helper.rb +20 -0
  203. data/spec/support/callbacks_spec.rb +157 -0
  204. data/spec/support/filters_spec.rb +60 -0
  205. data/spec/support/spec_helper.rb +4 -0
  206. data/spec/template/spec_helper.rb +6 -0
  207. data/spec/template/template_spec/file.erb +1 -0
  208. data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
  209. data/spec/template/template_spec/views/basic/extension.erb +1 -0
  210. data/spec/template/template_spec/views/basic/general.html.erb +5 -0
  211. data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
  212. data/spec/template/template_spec/views/format/format.erb +1 -0
  213. data/spec/template/template_spec/views/format/format.html.erb +1 -0
  214. data/spec/template/template_spec/views/format/format.js.erb +1 -0
  215. data/spec/template/template_spec/views/format_for_partials/_form.html.erb +1 -0
  216. data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -0
  217. data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
  218. data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
  219. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
  220. data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
  221. data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
  222. data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
  223. data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
  224. data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
  225. data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
  226. data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
  227. data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
  228. data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
  229. data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
  230. data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
  231. data/spec/template/template_spec/views/nested/format/a.erb +1 -0
  232. data/spec/template/template_spec/views/nested/format/b.erb +1 -0
  233. data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
  234. data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
  235. data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
  236. data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
  237. data/spec/template/template_spec/views/nesting_format/_edit.html.erb +1 -0
  238. data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
  239. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
  240. data/spec/template/template_spec/views/other/template.erb +1 -0
  241. data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
  242. data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
  243. data/spec/template/template_spec.rb +204 -0
  244. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
  245. data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
  246. data/spec/template/tilt_spec/views/encoding/erb.erb +1 -0
  247. data/spec/template/tilt_spec/views/encoding/haml.haml +1 -0
  248. data/spec/template/tilt_spec/views/errors.erb +3 -0
  249. data/spec/template/tilt_spec/views/errors.haml +3 -0
  250. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
  251. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
  252. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
  253. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
  254. data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
  255. data/spec/template/tilt_spec/views/ugly.haml +3 -0
  256. data/spec/template/tilt_spec/views/yield.erb +1 -0
  257. data/spec/template/tilt_spec.rb +98 -0
  258. metadata +531 -0
@@ -0,0 +1 @@
1
+ <%= some_controller_method %>
@@ -0,0 +1,53 @@
1
+ require "controller/spec_helper"
2
+
3
+ describe "AbstractController" do
4
+ with_environment
5
+ with_abstract_controller_spec
6
+ with_view_path "#{spec_dir}/views"
7
+
8
+ before :all do
9
+ AbstractController = Rad::AbstractController
10
+ end
11
+
12
+ after :all do
13
+ remove_constants %w(
14
+ SomeHelperSpec
15
+ HelperSpec
16
+ HelperMethodSpec
17
+ AbstractController
18
+ )
19
+ end
20
+
21
+ it "helper_method" do
22
+ class ::HelperMethodSpec
23
+ inherit AbstractController
24
+
25
+ def some_controller_method
26
+ "some controller value (rendered in cotext of #{self.class})"
27
+ end
28
+ helper_method :some_controller_method
29
+
30
+ def action; end
31
+ end
32
+
33
+ ccall(HelperMethodSpec, :action).should == "some controller value (rendered in cotext of HelperMethodSpec)"
34
+ end
35
+
36
+ it "helper" do
37
+ module ::SomeHelperSpec
38
+ def wiget
39
+ "some wighet (rendered in context of #{self.class.name})"
40
+ end
41
+ end
42
+
43
+ class ::HelperSpec
44
+ inherit AbstractController
45
+
46
+ helper SomeHelperSpec
47
+
48
+ def action; end
49
+ end
50
+
51
+ ccall(HelperSpec, :action).should == "some wighet (rendered in context of HelperSpec::HelperSpecControllerContext)"
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ another action (action_name: <%= action_name %>)
@@ -0,0 +1,7 @@
1
+ - case action_name
2
+ - when :increase
3
+ plus
4
+ - when :decrease
5
+ minus
6
+ - else
7
+ - must_be.never_called
@@ -0,0 +1 @@
1
+ Admin layout, <%= yield %>
@@ -0,0 +1 @@
1
+ Layout html, <%= yield %>
@@ -0,0 +1 @@
1
+ Layout js, <%= yield %>
@@ -0,0 +1 @@
1
+ standalone usage, <%= a %>
@@ -0,0 +1,217 @@
1
+ require "controller/spec_helper"
2
+
3
+ describe "Controller render" do
4
+ with_environment
5
+ with_abstract_controller_spec
6
+ with_view_path "#{spec_dir}/views"
7
+
8
+ before :all do
9
+ AbstractController = Rad::AbstractController
10
+ end
11
+
12
+ after :all do
13
+ remove_constants %w(
14
+ LayoutFiltersSpec
15
+ LayoutSpec
16
+ AnotherLayout
17
+ ExplicitRenderSpec
18
+ RenderInsideOfControllerSpec
19
+ ForbidPartialAsActionSpec
20
+ FormatSpec
21
+ AlreadyRenderedSpec
22
+ SpecialFormatSpec
23
+ AnotherActionSpec
24
+ InlineRenderSpec
25
+ AbstractController
26
+ InlineWithLayoutSpec
27
+ MultipleActions
28
+ )
29
+ end
30
+
31
+ describe 'layout' do
32
+ it "should use :except and :only in layout" do
33
+ class ::LayoutFiltersSpec
34
+ inherit AbstractController
35
+ layout '/layouts/app', only: :action_with_layout
36
+
37
+ def action_with_layout; end
38
+ def action_without_layout; end
39
+ end
40
+
41
+ ccall(LayoutFiltersSpec, :action_with_layout, format: 'html').should == "Layout html, content"
42
+ ccall(LayoutFiltersSpec, :action_without_layout).should == "content"
43
+ end
44
+
45
+ it "should apply formats to layout" do
46
+ class LayoutSpec
47
+ inherit AbstractController
48
+ layout '/layouts/app'
49
+
50
+ def action; end
51
+ end
52
+
53
+ ccall(LayoutSpec, :action, format: 'html').should == "Layout html, content"
54
+ ccall(LayoutSpec, :action, format: 'js').should == "Layout js, content"
55
+ end
56
+
57
+ it "should take layout: false or layout: '/another_layout'" do
58
+ class AnotherLayout
59
+ inherit AbstractController
60
+ layout '/layout/app'
61
+
62
+ def action; end
63
+
64
+ def without_layout
65
+ render action: :action, layout: false
66
+ end
67
+
68
+ def another_layout
69
+ render action: :action, layout: '/layouts/admin'
70
+ end
71
+ end
72
+
73
+ ccall(AnotherLayout, :without_layout).should == "action"
74
+ ccall(AnotherLayout, :another_layout).should == "Admin layout, action"
75
+ end
76
+
77
+
78
+ it "should take into account :layout when rendering template" do
79
+ class ::ExplicitRenderSpec
80
+ inherit AbstractController
81
+ layout '/layouts/app'
82
+
83
+ def with_layout
84
+ render '/some_template'
85
+ end
86
+
87
+ def without_layout
88
+ render '/some_template', layout: false
89
+ end
90
+ end
91
+
92
+ ccall(ExplicitRenderSpec, :with_layout, format: 'html').should == "Layout html, some template"
93
+ ccall(ExplicitRenderSpec, :without_layout, format: 'html').should == "some template"
94
+ end
95
+ end
96
+
97
+ it "should render template inside of controller" do
98
+ class ::RenderInsideOfControllerSpec
99
+ inherit AbstractController
100
+
101
+ def some_action
102
+ render '/some_template'
103
+ end
104
+ end
105
+
106
+ ccall(RenderInsideOfControllerSpec, 'some_action').should == "some template"
107
+ end
108
+
109
+ it "should not allow to render partials as actions" do
110
+ class ::ForbidPartialAsActionSpec
111
+ inherit AbstractController
112
+ def action; end
113
+ end
114
+
115
+ lambda{ccall ForbidPartialAsActionSpec, :action}.should raise_error(/No template/)
116
+ end
117
+
118
+ it "should render view with right format" do
119
+ class FormatSpec
120
+ inherit AbstractController
121
+ def action; end
122
+ end
123
+
124
+ ccall(FormatSpec, :action, format: 'html').should == "html format"
125
+ ccall(FormatSpec, :action, format: 'js').should == "js format"
126
+ end
127
+
128
+ it "should be able to use Template.render for different purposes (mail for example)" do
129
+ Rad::Template.render("/standalone", locals: {a: 'a'}).should == 'standalone usage, a'
130
+ end
131
+
132
+ it "should not rener if already rendered in controller" do
133
+ class ::AlreadyRenderedSpec
134
+ inherit AbstractController
135
+
136
+ def action
137
+ render '/AlreadyRenderedSpec/custom_template'
138
+ end
139
+ end
140
+
141
+ ccall(AlreadyRenderedSpec, :action).should == 'custom content'
142
+ end
143
+
144
+ it "should handle serialization obj ('xml', 'json')" do
145
+ class ::SpecialFormatSpec
146
+ inherit AbstractController
147
+
148
+ def json_action
149
+ render json: {a: "b"}
150
+ end
151
+
152
+ def xml_action
153
+ render xml: {a: "b"}
154
+ end
155
+ end
156
+
157
+ ccall(SpecialFormatSpec, :json_action, format: 'json').should == %({"a":"b"})
158
+ ccall(SpecialFormatSpec, :xml_action, format: 'xml').should =~ /<a>b<\/a>/
159
+ -> {
160
+ ccall(SpecialFormatSpec, :json_action, format: 'xml')
161
+ }.should raise_error(/responing with 'json' to the 'xml'/)
162
+ end
163
+
164
+ it "should render another action via action: :action_name" do
165
+ class ::AnotherActionSpec
166
+ inherit AbstractController
167
+
168
+ def another_action; end
169
+
170
+ def action
171
+ render action: :another_action
172
+ end
173
+ end
174
+
175
+ ccall(AnotherActionSpec, :action).should == "another action (action_name: another_action)"
176
+ end
177
+
178
+ it "should take :inline option" do
179
+ class ::InlineRenderSpec
180
+ inherit AbstractController
181
+
182
+ def action
183
+ render inline: "content"
184
+ end
185
+ end
186
+
187
+ ccall(InlineRenderSpec, :action).should == "content"
188
+ end
189
+
190
+ it ":inline option should render without layout" do
191
+ class ::InlineWithLayoutSpec
192
+ inherit AbstractController
193
+
194
+ layout '/layouts/app'
195
+
196
+ def action
197
+ render inline: "content"
198
+ end
199
+ end
200
+
201
+ ccall(InlineWithLayoutSpec, :action).should == "content"
202
+ end
203
+
204
+ it "should render correct action inside of special 'actions.xxx' template file" do
205
+ class ::MultipleActions
206
+ inherit AbstractController
207
+
208
+ def increase; end
209
+ def decrease; end
210
+ def action_without_template; end
211
+ end
212
+
213
+ ccall(MultipleActions, :increase).should == "plus\n"
214
+ ccall(MultipleActions, :decrease).should == "minus\n"
215
+ ccall(MultipleActions, :action_without_template).should == ""
216
+ end
217
+ end
@@ -0,0 +1 @@
1
+ <% raise 'error in template' %>
@@ -0,0 +1,117 @@
1
+ require "controller/spec_helper"
2
+
3
+ describe "Error handling" do
4
+ with_environment
5
+ with_view_path "#{spec_dir}/views"
6
+
7
+ before :all do
8
+ AbstractController = Rad::AbstractController
9
+
10
+ rad.before :environment do
11
+ rad.config.test_error_template = rad.config.development_error_template!
12
+ end
13
+
14
+ rad.after :environment do
15
+ rad.conveyors.web do |web|
16
+ web.use Rad::Processors::ControllerErrorHandling
17
+ web.use Rad::Processors::ControllerCaller
18
+ end
19
+ end
20
+ end
21
+
22
+ after :all do
23
+ remove_constants %w(
24
+ DisplayErrorWithFormat
25
+ DiferrentErrorHandlingSpec
26
+ AbstractController
27
+ ErrorInRedirectSpec
28
+ )
29
+ end
30
+
31
+ it "should correctly display error messages in :development (with correct format)" do
32
+ class ::DisplayErrorWithFormat
33
+ inherit AbstractController
34
+
35
+ def method
36
+ raise params.error
37
+ end
38
+ end
39
+
40
+ config.environment = :development
41
+ silence_logger!
42
+
43
+ error = StandardError.new('some error')
44
+
45
+ ccall(
46
+ DisplayErrorWithFormat, :method,
47
+ {error: error, format: 'html'}
48
+ ).should =~ /html.+some error/m
49
+
50
+ ccall(
51
+ DisplayErrorWithFormat, :method,
52
+ {error: error, format: 'js'}
53
+ ).should =~ /some error/
54
+
55
+ ccall(
56
+ DisplayErrorWithFormat, :method,
57
+ {error: error, format: :non_existing_mime}
58
+ ).should =~ /some error/
59
+ end
60
+
61
+ it "should catch errors with redirect (from error)" do
62
+ # if response.headers['Location'] has been set before redirect, it'll do redirect
63
+ # after error will be catched and no error message will be displayed
64
+
65
+ class ::ErrorInRedirectSpec
66
+ inherit AbstractController
67
+
68
+ def a
69
+ response.headers['Location'] = '/'
70
+ raise 'some error'
71
+ end
72
+ end
73
+
74
+ config.environment = :development
75
+ silence_logger!
76
+
77
+ ccall(ErrorInRedirectSpec, :a, format: 'html')
78
+ response.headers['Location'].should be_nil
79
+ end
80
+
81
+ describe "should be different in :test, :development and :production" do
82
+ before :all do
83
+ class ::DiferrentErrorHandlingSpec
84
+ inherit AbstractController
85
+
86
+ def a; end
87
+ def b
88
+ raise 'some error'
89
+ end
90
+ def c; end
91
+ end
92
+ end
93
+
94
+ it "in :production errors shouldn't be shown to user"
95
+
96
+ it "in development errors should be catched" do
97
+ config.environment = :development
98
+ silence_logger!
99
+
100
+ # with view
101
+ ccall(DiferrentErrorHandlingSpec, :a).should == 'a'
102
+ %w(html js).each do |format|
103
+ ccall(DiferrentErrorHandlingSpec, :b, format: format).should =~ /some error/
104
+ ccall(DiferrentErrorHandlingSpec, :c, format: format).should =~ /error in template/
105
+ end
106
+ end
107
+
108
+ it "should not catch errors in :test environment" do
109
+ config.environment = :test
110
+
111
+ # with render
112
+ ccall(DiferrentErrorHandlingSpec, :a).should == 'a'
113
+ lambda{ccall(DiferrentErrorHandlingSpec, :b)}.should raise_error(/some error/)
114
+ lambda{ccall(DiferrentErrorHandlingSpec, :c)}.should raise_error(/error in template/)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,130 @@
1
+ require "controller/spec_helper"
2
+
3
+ describe "HttpController" do
4
+ with_environment
5
+ with_http
6
+
7
+ before :all do
8
+ HttpController = Rad::HttpController
9
+
10
+ rad.after :environment do
11
+ rad.conveyors.web do |web|
12
+ web.use Rad::Processors::HttpWriter
13
+ web.use Rad::Processors::ControllerCaller
14
+ end
15
+ end
16
+ end
17
+
18
+ after :all do
19
+ remove_constants %w(
20
+ HttpController
21
+ ContentTypeSpec
22
+ StatusSpec
23
+ StatusShortcutsSpec
24
+ LocationSpec
25
+ RequestMethod
26
+ ForbidGetSpec
27
+ )
28
+ end
29
+
30
+ describe 'render' do
31
+ it "should take :content_type option" do
32
+ class ::ContentTypeSpec
33
+ inherit HttpController
34
+
35
+ def action
36
+ render inline: "some content", content_type: Mime.js
37
+ end
38
+ end
39
+
40
+ wcall(ContentTypeSpec, :action)
41
+ response.content_type.should == "application/javascript"
42
+ end
43
+
44
+ it "should take :status option" do
45
+ class ::StatusSpec
46
+ inherit HttpController
47
+
48
+ def action
49
+ render inline: "some content", status: 220
50
+ end
51
+ end
52
+
53
+ wcall(StatusSpec, :action)
54
+ response.status.should == 220
55
+ end
56
+
57
+ it "should take shortcuts to status codes" do
58
+ class ::StatusShortcutsSpec
59
+ inherit HttpController
60
+
61
+ def ok
62
+ render :ok
63
+ end
64
+
65
+ def failed
66
+ render :failed
67
+ end
68
+ end
69
+
70
+ wcall(StatusShortcutsSpec, :ok)
71
+ response.status.should == 200
72
+
73
+ wcall(StatusShortcutsSpec, :failed)
74
+ response.status.should == 500
75
+ end
76
+
77
+ it "should take :location option" do
78
+ class ::LocationSpec
79
+ inherit HttpController
80
+
81
+ def action
82
+ render location: "/"
83
+ end
84
+ end
85
+
86
+ # mock
87
+ class ::LocationSpec
88
+ def redirect_to location
89
+ self.class.location = location
90
+ end
91
+
92
+ class << self
93
+ attr_accessor :location
94
+ end
95
+ end
96
+
97
+ wcall(LocationSpec, :action, format: 'html')
98
+ LocationSpec.location.should == '/'
99
+ end
100
+ end
101
+
102
+ it "should specify request method" do
103
+ class ::RequestMethod
104
+ inherit HttpController
105
+ def action
106
+ workspace.request.post?.should == true
107
+ end
108
+ end
109
+
110
+ workspace, params = {env: {'REQUEST_METHOD' => 'POST'}}, {}
111
+ wcall(RequestMethod, :action, workspace, params)
112
+ end
113
+
114
+ it "should protect methods from GET request" do
115
+ class ::ForbidGetSpec
116
+ inherit HttpController
117
+ allow_get_for :get_action
118
+
119
+ def get_action; end
120
+ def post_action; end
121
+ end
122
+
123
+ workspace = {env: {'REQUEST_METHOD' => 'GET'}}
124
+
125
+ wcall(ForbidGetSpec, :get_action, workspace, {})
126
+ lambda{
127
+ wcall(ForbidGetSpec, :post_action, workspace, {})
128
+ }.should raise_error(/not allowed/)
129
+ end
130
+ end
@@ -0,0 +1,19 @@
1
+ require 'rspec_ext'
2
+
3
+ require 'rad/controller'
4
+ require 'rad/controller/http_controller'
5
+ require 'rad/http'
6
+
7
+ require 'rad/spec'
8
+
9
+ rspec do
10
+ def self.with_abstract_controller_spec
11
+ before :all do
12
+ rad.after :environment do
13
+ rad.conveyors.web do |web|
14
+ web.use Rad::Processors::ControllerCaller
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end