rad_core 0.0.13

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 (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,157 @@
1
+ require 'support/spec_helper'
2
+
3
+ require "rad/support/callbacks"
4
+
5
+ describe "Callbacks" do
6
+ before :all do
7
+ class BasicCallbacksSpec
8
+ inherit Rad::Callbacks
9
+
10
+ set_callback :callback_name, :before, :before_callback
11
+ set_callback :callback_name, :after, :after_callback
12
+ set_callback :callback_name, :around, :around_callback
13
+
14
+ protected
15
+ def around_callback
16
+ around_callback_called
17
+ yield
18
+ end
19
+ end
20
+ end
21
+
22
+ it "basic" do
23
+ o = BasicCallbacksSpec.new
24
+ o.should_receive :before_callback
25
+ o.should_receive :around_callback_called
26
+ o.should_receive :after_callback
27
+ o.run_callbacks(:callback_name){"result"}.should == "result"
28
+ end
29
+
30
+ it "blocks" do
31
+ class BlockCallbacksSpec
32
+ inherit Rad::Callbacks
33
+
34
+ set_callback(:callback_name, :before){|controller| controller.result << :before}
35
+ set_callback :callback_name, :around do |controller, block|
36
+ begin
37
+ controller.result << :around_begin
38
+ block.call
39
+ ensure
40
+ controller.result << :around_end
41
+ end
42
+ end
43
+ set_callback(:callback_name, :after){|controller| controller.result << :after}
44
+
45
+ def result
46
+ @result ||= []
47
+ end
48
+ end
49
+
50
+ o = BlockCallbacksSpec.new
51
+ o.run_callbacks(:callback_name){"result"}.should == "result"
52
+ o.result.should == [:before, :around_begin, :after, :around_end]
53
+ end
54
+
55
+ it "inheritance" do
56
+ class InheritedCallbacksSpec < BasicCallbacksSpec
57
+ set_callback :callback_name, :before, :before_callback2
58
+ end
59
+
60
+ o = InheritedCallbacksSpec.new
61
+ o.should_receive :before_callback
62
+ o.should_receive :before_callback2
63
+ o.should_receive :around_callback_called
64
+ o.should_receive :after_callback
65
+ o.run_callbacks(:callback_name){"result"}.should == "result"
66
+ end
67
+
68
+ it 'terminator' do
69
+ class CallbackTerminatorSpec
70
+ inherit Rad::Callbacks
71
+
72
+ set_callback :callback_name, :before, :before_callback, terminator: false
73
+ set_callback :callback_name, :before, :before_callback2
74
+
75
+ def method
76
+ run_callbacks :callback_name do
77
+ "result"
78
+ end
79
+ end
80
+
81
+ protected
82
+ def before_callback
83
+ false
84
+ end
85
+ end
86
+
87
+ o = CallbackTerminatorSpec.new
88
+ o.should_not_receive :before_callback2
89
+ o.run_callbacks(:callback_name){"result"}.should_not == "result"
90
+ end
91
+
92
+ it 'conditions' do
93
+ class CallbackConditionsSpec
94
+ inherit Rad::Callbacks
95
+
96
+ set_callback :callback_name, :before, :before_callback, only: :another_method
97
+ end
98
+
99
+ o = CallbackConditionsSpec.new
100
+ o.should_not_receive :before_callback
101
+ o.run_callbacks(:callback_name, method: :method){"result"}.should == 'result'
102
+
103
+ o = CallbackConditionsSpec.new
104
+ o.should_receive :before_callback
105
+ o.run_callbacks(:callback_name, method: :another_method){"result"}.should == 'result'
106
+ end
107
+
108
+ it "if, unless conditions" do
109
+ c = Rad::Callbacks::AbstractCallback.new
110
+ c.conditions = {if: lambda{|target, inf| true}}
111
+ c.run?(nil, {}).should be_true
112
+
113
+ c.conditions = {if: lambda{|target, inf| false}}
114
+ c.run?(nil, {}).should be_false
115
+
116
+ c.conditions = {unless: lambda{|target, inf| true}}
117
+ c.run?(nil, {}).should be_false
118
+
119
+ c.conditions = {unless: lambda{|target, inf| false}}
120
+ c.run?(nil, {}).should be_true
121
+ end
122
+
123
+ it "only, except conditions" do
124
+ c = Rad::Callbacks::AbstractCallback.new
125
+ c.conditions = {only: :a}
126
+ c.run?(nil, {method: :a}).should be_true
127
+
128
+ c.conditions = {only: :b}
129
+ c.run?(nil, {method: :a}).should be_false
130
+
131
+ c.conditions = {except: :a}
132
+ c.run?(nil, {method: :a}).should be_false
133
+
134
+ c.conditions = {except: :b}
135
+ c.run?(nil, {method: :a}).should be_true
136
+
137
+ c.conditions = {only: :a}
138
+ c.run?(nil, {method: :a}).should be_true
139
+ end
140
+
141
+
142
+ it "around callback should be able to change result value" do
143
+ class ChangeResultValueSpec
144
+ inherit Rad::Callbacks
145
+
146
+ set_callback :callback_name, :around, :around_callback
147
+
148
+ def around_callback
149
+ yield
150
+ 'another result'
151
+ end
152
+ end
153
+
154
+ o = ChangeResultValueSpec.new
155
+ o.run_callbacks(:callback_name){"result"}.should == 'another result'
156
+ end
157
+ end
@@ -0,0 +1,60 @@
1
+ require 'support/spec_helper'
2
+
3
+ require "rad/support/callbacks"
4
+ require "rad/support/filters"
5
+
6
+ describe "Filters" do
7
+ module ARemote
8
+ inherit Rad::Filters
9
+ end
10
+
11
+ class FiltersBasic
12
+ inherit ARemote
13
+
14
+ before :set_user
15
+
16
+ def action
17
+ 'result'
18
+ end
19
+
20
+ attr_reader :user
21
+ def set_user
22
+ @user = 'some user'
23
+ end
24
+ end
25
+
26
+ class FilterInheritance < FiltersBasic
27
+ before :set_model
28
+
29
+ attr_reader :model
30
+ def set_model
31
+ @model = 'some model'
32
+ end
33
+ end
34
+
35
+ class FilterOverrideAction < FiltersBasic
36
+ def action
37
+ 'overriden result'
38
+ end
39
+ end
40
+
41
+ it 'basic' do
42
+ r = FiltersBasic.new
43
+ r.run_callbacks(:action){r.send :action}.should == 'result'
44
+ r.user.should == 'some user'
45
+ end
46
+
47
+ it 'inheritance' do
48
+ r = FilterInheritance.new
49
+ r.run_callbacks(:action){r.send :action}.should == 'result'
50
+ r.user.should == 'some user'
51
+ r.model.should == 'some model'
52
+ end
53
+
54
+ it "overriding action" do
55
+ r = FilterOverrideAction.new
56
+ r.run_callbacks(:action){r.send :action}.should == 'overriden result'
57
+ r.user.should == 'some user'
58
+ end
59
+
60
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec_ext'
2
+
3
+ require 'rad/support/active_support'
4
+ require 'ruby_ext'
@@ -0,0 +1,6 @@
1
+ require 'rspec_ext'
2
+
3
+ require 'rad/template'
4
+
5
+ require 'rad/spec/environment'
6
+ require 'rad/spec/template'
@@ -0,0 +1 @@
1
+ file template
@@ -0,0 +1 @@
1
+ content from <%= custom_helper %>
@@ -0,0 +1 @@
1
+ some content
@@ -0,0 +1,5 @@
1
+ Instance variable: <%= @ivariable %>
2
+ Instance variable 2: <%= @ivariable2 %>
3
+ Object value: <%= object.value %>
4
+ Locals value: <%= lvariable %>
5
+ Yield: <%= yield :content %>
@@ -0,0 +1 @@
1
+ universal format
@@ -0,0 +1 @@
1
+ $.showDialog(<%= render 'form' %>)
@@ -0,0 +1 @@
1
+ layotu begin <%= yield %> end
@@ -0,0 +1,3 @@
1
+ <% content_for :head do %>head<% end %>
2
+ content
3
+ <% content_for :bottom, 'bottom' %>
@@ -0,0 +1,3 @@
1
+ <%= yield :head %>
2
+ <%= yield %>
3
+ <%= yield :bottom %>
@@ -0,0 +1 @@
1
+ html layout begin <%= yield %> end
@@ -0,0 +1 @@
1
+ js layout begin <%= yield %> end
@@ -0,0 +1 @@
1
+ <%= render 'layout_b' %>
@@ -0,0 +1 @@
1
+ content a <%= @ivariable %> <%= render('b') %>
@@ -0,0 +1 @@
1
+ content b <%= @ivariable %>
@@ -0,0 +1 @@
1
+ layout <%= @ivariable %> <%= yield %>
@@ -0,0 +1 @@
1
+ <%= options.format %> format, <%= render 'b' %>
@@ -0,0 +1 @@
1
+ <%= options.format %> format
@@ -0,0 +1 @@
1
+ template a, <%= render 'b' %>
@@ -0,0 +1 @@
1
+ template c, <%= render '../shared/c' %>
@@ -0,0 +1 @@
1
+ shared template
@@ -0,0 +1 @@
1
+ dialog, <%= render 'form' %>
@@ -0,0 +1 @@
1
+ $.showDialog(<%= render 'edit', format: 'html' %>)
@@ -0,0 +1 @@
1
+ <% "ruby code" %> content
@@ -0,0 +1,204 @@
1
+ require 'template/spec_helper'
2
+
3
+ describe "Template" do
4
+ Template = Rad::Template
5
+
6
+ delegate :render, to: Template
7
+
8
+ with_environment environment: :development
9
+ with_view_path "#{spec_dir}/views"
10
+
11
+ before :all do
12
+ ::RenderResult = OpenObject.new
13
+
14
+ class ::SomeObject
15
+ attr_accessor :ivariable
16
+ end
17
+ end
18
+
19
+ after :all do
20
+ remove_constants %w(SomeObject RenderResult)
21
+ end
22
+
23
+ describe 'special' do
24
+ it "read" do
25
+ Template.read('/other/template').should == %{<% "ruby code" %> content}
26
+ end
27
+
28
+ it "exist?" do
29
+ Template.should exist('/other/template')
30
+ Template.should_not exist('/other/non-existing-template')
31
+ end
32
+
33
+ it "template prefixes" do
34
+ Template.exist?('/prefixes/underscored', prefixes: ['']).should be_false
35
+ render('/prefixes/underscored', prefixes: ['_', '']).should == "underscored"
36
+ render('/prefixes/underscored.erb', prefixes: ['_', '']).should == "underscored"
37
+
38
+ Template.exist?('/prefixes/without_prefix', prefixes: ['_']).should be_false
39
+ render('/prefixes/without_prefix', prefixes: ['']).should == "whthout prefix"
40
+ end
41
+
42
+ it "should not use prefixes for :action" do
43
+ Template.exist?('/prefixes/underscored').should be_true
44
+ Template.exist?('/prefixes/underscored', action: true).should be_false
45
+ end
46
+ end
47
+
48
+ describe 'basic' do
49
+ it "general" do
50
+ some_object = SomeObject.new
51
+ some_object.ivariable = "instance variable value"
52
+ options = {
53
+ instance_variables: [some_object, {ivariable2: "instance variable value 2"}],
54
+ object: OpenObject.new.update(value: 'object value'),
55
+ locals: {lvariable: 'local value'},
56
+ format: 'html'
57
+ }
58
+
59
+ result = render("/basic/general", options){|content_name| "content for :#{content_name}"}
60
+
61
+ check = %{\
62
+ Instance variable: instance variable value
63
+ Instance variable 2: instance variable value 2
64
+ Object value: object value
65
+ Locals value: local value
66
+ Yield: content for :content}
67
+
68
+ result.should == check
69
+ end
70
+
71
+ it "should not render wrong format if :action specified" do
72
+ Template.exist?('/basic/non_existing_format', format: 'html', action: true).should be_true
73
+ Template.exist?('/basic/non_existing_format', format: :invalid, action: true).should be_false
74
+
75
+ # from error
76
+ Template.exist?('non_existing_format', format: :invalid, action: true, current_dir: "#{spec_dir}/views/basic").should be_false
77
+ end
78
+
79
+ it "extension" do
80
+ render('/basic/extension').should == "some content"
81
+ render('/basic/extension.erb').should == "some content"
82
+ end
83
+
84
+ it "must support custom context_class" do
85
+ class CustomTemplateContext < Rad::TemplateContext
86
+ def custom_helper
87
+ 'custom helper'
88
+ end
89
+ end
90
+
91
+ render('/basic/custom_context', context_class: CustomTemplateContext).should == "content from custom helper"
92
+ end
93
+
94
+ it "must support explicit context, and it should overtake context_class" do
95
+ class CustomTemplateContext < Rad::TemplateContext
96
+ def custom_helper
97
+ 'custom helper'
98
+ end
99
+ end
100
+
101
+ render(
102
+ '/basic/custom_context',
103
+ context: CustomTemplateContext.new,
104
+ context_class: Object
105
+ ).should == "content from custom helper"
106
+ end
107
+
108
+ it "no template" do
109
+ lambda{render('/non-existing-template')}.should raise_error(/No template/)
110
+ end
111
+
112
+ it "should render arbitrary file" do
113
+ render(file: "#{spec_dir}/file.erb").should == "file template"
114
+ end
115
+ end
116
+
117
+ describe 'format' do
118
+ it "basic" do
119
+ render('/format/format', format: 'html', action: true).should == "html format"
120
+ render('/format/format', format: 'js', action: true).should == "js format"
121
+ render('/format/format', format: :non_existing, action: true).should == "universal format"
122
+ render('/format/format.html', format: 'js', action: true).should == "html format"
123
+ render('/format/format.html.erb', format: 'js', action: true).should == "html format"
124
+ end
125
+
126
+ it "nesting different formats" do
127
+ render('/nesting_format/dialog', format: 'js', action: true).should == "$.showDialog(dialog, dialog form)"
128
+ end
129
+
130
+ it "should not force format for partials (if :action not specified)" do
131
+ render('/format_for_partials/dialog', format: 'js', action: true).should == "$.showDialog(dialog form)"
132
+ end
133
+ end
134
+
135
+ describe 'nested' do
136
+ it "should render relative templates" do
137
+ render('/nested/relative/a').should == "template a, template b"
138
+ lambda{render('b')}.should raise_error(/You can't use relative template path/)
139
+ current_dir = "#{spec_dir}/views/nested/relative"
140
+ render('b', current_dir: current_dir).should == "template b"
141
+ end
142
+
143
+ it "should render relative templates with complex path (../../xxx)" do
144
+ render('/nested/relative/c').should == "template c, shared template"
145
+ end
146
+
147
+ it "nested templates should use the same format" do
148
+ render('/nested/format/a', format: 'js').should == "js format, js format"
149
+ end
150
+ end
151
+
152
+ describe "layout" do
153
+ def render_with_layout template, options, layout
154
+ content, context = Template.basic_render(Template.parse_arguments(template, options))
155
+ Template.render_layout(layout, content: content, context: context)
156
+ end
157
+
158
+ it "templates and layout must share the same context" do
159
+ render_with_layout(
160
+ '/layout/same_context/a', {instance_variables: {ivariable: "ivariable"}},
161
+ '/layout/same_context/layout'
162
+ ).should == "layout ivariable content a ivariable content b ivariable"
163
+ end
164
+
165
+ it "content_for" do
166
+ render_with_layout(
167
+ '/layout/content_for/content', {},
168
+ '/layout/content_for/layout'
169
+ ).should == %{\
170
+ head
171
+
172
+ content
173
+
174
+ bottom}
175
+ end
176
+
177
+ it "basic" do
178
+ render_with_layout(
179
+ '/layout/basic/content', {},
180
+ '/layout/basic/layout'
181
+ ).should == "layotu begin content end"
182
+ end
183
+
184
+ it "layout with format" do
185
+ render_with_layout(
186
+ '/layout/format/content', {format: 'html'},
187
+ '/layout/format/layout'
188
+ ).should == "html layout begin html content end"
189
+
190
+ render_with_layout(
191
+ '/layout/format/content', {format: 'js'},
192
+ '/layout/format/layout'
193
+ ).should == "js layout begin js content end"
194
+ end
195
+
196
+ it "layout should support yield in partials (from error)" do
197
+ render_with_layout(
198
+ '/layout/nested_yield/a', {},
199
+ '/layout/nested_yield/layout'
200
+ ).should == "some content"
201
+ end
202
+ end
203
+
204
+ end
@@ -0,0 +1 @@
1
+ <% concat "text for concatenation" %><% RenderResult.erb_capture = capture do %>text for capturing<% end %>
@@ -0,0 +1,3 @@
1
+ - concat "text for concatenation"
2
+ - RenderResult.haml_capture = capture do
3
+ text for capturing
@@ -0,0 +1,3 @@
1
+ first line
2
+ <% raise "line with error" %>
3
+ second line
@@ -0,0 +1,3 @@
1
+ first line
2
+ - raise "line with error"
3
+ second line
@@ -0,0 +1,4 @@
1
+ <%= render('/mixed_templates/broken_erb_concat_haml') %>
2
+ <% tag :div do %>
3
+ some content
4
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render '/mixed_templates/broken_haml_concat_haml' %>
@@ -0,0 +1,2 @@
1
+ - tag :div do
2
+ some content
@@ -0,0 +1,3 @@
1
+ - form_tag do
2
+ - form_field do
3
+ some field
@@ -0,0 +1,3 @@
1
+ .a
2
+ .b
3
+ content
@@ -0,0 +1 @@
1
+ Layout, <%= yield :content %>