crystal_ext 0.0.7 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. data/Rakefile +70 -7
  2. data/lib/crystal/controller.rb +28 -0
  3. data/lib/crystal/controller/abstract_controller.rb +60 -0
  4. data/lib/crystal/controller/abstract_controller/micelaneous.rb +31 -0
  5. data/lib/crystal/controller/abstract_controller/render.rb +133 -0
  6. data/lib/crystal/controller/abstract_controller/responder.rb +17 -0
  7. data/lib/crystal/controller/controller_context.rb +7 -0
  8. data/lib/crystal/controller/http_controller.rb +43 -0
  9. data/lib/crystal/controller/processors/controller_caller.rb +40 -0
  10. data/lib/crystal/controller/processors/controller_error_handling.rb +53 -0
  11. data/lib/crystal/controller/processors/controller_logger.rb +13 -0
  12. data/lib/crystal/conveyor.rb +29 -0
  13. data/lib/crystal/conveyor/conveyor.rb +74 -0
  14. data/lib/crystal/conveyor/conveyors.rb +20 -0
  15. data/lib/crystal/conveyor/params.rb +22 -0
  16. data/lib/crystal/conveyor/processor.rb +68 -0
  17. data/lib/crystal/conveyor/processors/conveyor_logger.rb +24 -0
  18. data/lib/crystal/conveyor/workspace.rb +36 -0
  19. data/lib/crystal/environment.rb +52 -0
  20. data/lib/crystal/environment/config.rb +118 -0
  21. data/lib/crystal/environment/dependency_resolver.rb +107 -0
  22. data/lib/crystal/environment/environment.rb +5 -0
  23. data/lib/crystal/environment/files_helper.rb +42 -0
  24. data/lib/crystal/environment/logger.rb +21 -0
  25. data/lib/crystal/html.rb +28 -0
  26. data/lib/crystal/html/controller_helpers/controller_url_helper.rb +52 -0
  27. data/lib/crystal/html/controller_helpers/flash_helper.rb +5 -0
  28. data/lib/crystal/html/flash.rb +40 -0
  29. data/lib/crystal/html/include_into_controller.rb +24 -0
  30. data/lib/crystal/html/processors/prepare_flash.rb +26 -0
  31. data/lib/crystal/html/processors/scoped_params.rb +30 -0
  32. data/lib/crystal/html/view_helpers/basic_html_helper.rb +83 -0
  33. data/lib/crystal/html/view_helpers/form_helper.rb +104 -0
  34. data/lib/crystal/html/view_helpers/javascript_helper.rb +18 -0
  35. data/lib/crystal/html/view_helpers/model_helper.rb +119 -0
  36. data/lib/crystal/html/view_helpers/view_url_helper.rb +66 -0
  37. data/lib/crystal/http.rb +47 -0
  38. data/lib/crystal/http/http.rb +18 -0
  39. data/lib/crystal/http/http_adapter.rb +30 -0
  40. data/lib/crystal/http/middleware/static_files.rb +20 -0
  41. data/lib/crystal/http/processors/evaluate_format.rb +22 -0
  42. data/lib/crystal/http/processors/http_logger.rb +15 -0
  43. data/lib/crystal/http/processors/http_writer.rb +48 -0
  44. data/lib/crystal/http/processors/prepare_params.rb +24 -0
  45. data/lib/crystal/http/rack_config.rb +15 -0
  46. data/lib/crystal/http/support/rack/rack_adapter.rb +65 -0
  47. data/lib/crystal/http/support/rack/request.rb +12 -0
  48. data/lib/crystal/http/support/rack/response.rb +39 -0
  49. data/lib/crystal/mailer.rb +13 -0
  50. data/lib/crystal/mailer/mail.rb +7 -0
  51. data/lib/{crystal_ext/profiles/web_ext.rb → crystal/profiles/web.rb} +9 -15
  52. data/lib/crystal/profiles/web_require.rb +5 -0
  53. data/lib/crystal/remote.rb +9 -0
  54. data/lib/crystal/remote/processors/remote_caller.rb +54 -0
  55. data/lib/crystal/remote/processors/remote_logger.rb +13 -0
  56. data/lib/crystal/remote/remote.rb +15 -0
  57. data/lib/crystal/router.rb +19 -0
  58. data/lib/crystal/router/configurator.rb +23 -0
  59. data/lib/crystal/router/default_format_processor.rb +12 -0
  60. data/lib/crystal/router/default_router.rb +23 -0
  61. data/lib/crystal/router/named_router.rb +63 -0
  62. data/lib/crystal/router/processors/router.rb +22 -0
  63. data/lib/crystal/router/router.rb +218 -0
  64. data/lib/crystal/router/routing_helper.rb +17 -0
  65. data/lib/crystal/spec.rb +8 -0
  66. data/lib/crystal/spec/controller.rb +15 -0
  67. data/lib/crystal/spec/environment.rb +41 -0
  68. data/lib/crystal/spec/http.rb +67 -0
  69. data/lib/crystal/spec/mail.rb +20 -0
  70. data/lib/crystal/spec/remote.rb +9 -0
  71. data/lib/crystal/spec/view.rb +10 -0
  72. data/lib/crystal/spec/xhtml.rb +33 -0
  73. data/lib/crystal/support.rb +46 -0
  74. data/lib/crystal/support/active_support.rb +39 -0
  75. data/lib/crystal/support/active_support/micelaneous.rb +2 -0
  76. data/lib/crystal/support/addressable.rb +45 -0
  77. data/lib/crystal/support/buffered_logger.rb +38 -0
  78. data/lib/crystal/support/callbacks.rb +155 -0
  79. data/lib/crystal/support/exception.rb +20 -0
  80. data/lib/crystal/support/filters.rb +34 -0
  81. data/lib/crystal/support/format.rb +9 -0
  82. data/lib/crystal/support/gems.rb +8 -0
  83. data/lib/crystal/support/micon.rb +13 -0
  84. data/lib/crystal/support/mime.rb +11 -0
  85. data/lib/crystal/support/module.rb +44 -0
  86. data/lib/crystal/support/rson.rb +53 -0
  87. data/lib/crystal/support/ruby_ext_with_active_support.rb +4 -0
  88. data/lib/crystal/support/safe_hash.rb +135 -0
  89. data/lib/crystal/support/string.rb +26 -0
  90. data/lib/crystal/template.rb +21 -0
  91. data/lib/crystal/template/support/tilt.rb +68 -0
  92. data/lib/crystal/template/template.rb +244 -0
  93. data/lib/crystal/template/template_context.rb +57 -0
  94. data/lib/views/crystal_default_templates/development/error.html.erb +11 -0
  95. data/lib/views/crystal_default_templates/development/error.js.erb +1 -0
  96. data/readme.md +8 -11
  97. data/spec/_mailer/basic_spec.rb +110 -0
  98. data/spec/_mailer/helper.rb +7 -0
  99. data/spec/controller/abstract_controller_spec.rb +137 -0
  100. data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
  101. data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +10 -0
  102. data/spec/controller/controller_context_spec.rb +122 -0
  103. data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
  104. data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
  105. data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
  106. data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
  107. data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
  108. data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
  109. data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
  110. data/spec/controller/controller_helper_spec.rb +57 -0
  111. data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
  112. data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
  113. data/spec/controller/controller_render_spec.rb +191 -0
  114. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
  115. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
  116. data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
  117. data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
  118. data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/action.erb +1 -0
  119. data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/another_action.erb +1 -0
  120. data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
  121. data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
  122. data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
  123. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
  124. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
  125. data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
  126. data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
  127. data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
  128. data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
  129. data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
  130. data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
  131. data/spec/controller/error_handling_spec.rb +96 -0
  132. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
  133. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
  134. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
  135. data/spec/controller/helper.rb +21 -0
  136. data/spec/controller/http_controller_spec.rb +89 -0
  137. data/spec/conveyor/conveyor_spec.rb +124 -0
  138. data/spec/conveyor/helper.rb +8 -0
  139. data/spec/environment/_dependency_resolver_spec.rb +50 -0
  140. data/spec/environment/environment_spec.rb +85 -0
  141. data/spec/environment/environment_spec/app/app_plugin/config/ec_layout +1 -0
  142. data/spec/environment/environment_spec/app/app_plugin/ec_some_file +1 -0
  143. data/spec/environment/environment_spec/app/config/config.test.yml +1 -0
  144. data/spec/environment/environment_spec/app/config/config.yml +2 -0
  145. data/spec/environment/environment_spec/gem_plugin/config/ec_layout +1 -0
  146. data/spec/environment/helper.rb +6 -0
  147. data/spec/environment/logger_spec.rb +18 -0
  148. data/spec/environment/minimal_app_spec.rb +27 -0
  149. data/spec/environment/minimal_app_spec/app.rb +3 -0
  150. data/spec/environment/standard_app_spec.rb +63 -0
  151. data/spec/environment/standard_app_spec_data/config/init.rb +18 -0
  152. data/spec/environment/standard_app_spec_data/plugin_a/plugin_a.rb +7 -0
  153. data/spec/html/basic_html_helper_spec.rb +28 -0
  154. data/spec/html/flash_spec.rb +184 -0
  155. data/spec/html/form_helper_spec.rb +56 -0
  156. data/spec/html/helper.rb +31 -0
  157. data/spec/html/javascript_helper_spec.rb +15 -0
  158. data/spec/html/model_helper_spec.rb +65 -0
  159. data/spec/html/scoped_params_spec.rb +17 -0
  160. data/spec/html/url_helper_spec.rb +151 -0
  161. data/spec/http/helper.rb +9 -0
  162. data/spec/http/http_spec.rb +56 -0
  163. data/spec/http/http_spec_data/config/init.rb +7 -0
  164. data/spec/http/http_spec_data/plugin_b/plugin_b.rb +6 -0
  165. data/spec/integration/basic_spec.rb +82 -0
  166. data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
  167. data/spec/integration/helper.rb +10 -0
  168. data/spec/remote/helper.rb +20 -0
  169. data/spec/remote/remote_spec.rb +75 -0
  170. data/spec/router/basic_spec.rb +130 -0
  171. data/spec/router/configurator_spec.rb +29 -0
  172. data/spec/router/helper.rb +24 -0
  173. data/spec/router/integration_spec.rb +42 -0
  174. data/spec/spec.opts +4 -0
  175. data/spec/support/callbacks_spec.rb +153 -0
  176. data/spec/support/filters_spec.rb +59 -0
  177. data/spec/support/helper.rb +7 -0
  178. data/spec/support/safe_hash_spec.rb +82 -0
  179. data/spec/template/helper.rb +8 -0
  180. data/spec/template/template_spec.rb +189 -0
  181. data/spec/template/template_spec/file.erb +1 -0
  182. data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
  183. data/spec/template/template_spec/views/basic/extension.erb +1 -0
  184. data/spec/template/template_spec/views/basic/general.html.erb +5 -0
  185. data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
  186. data/spec/template/template_spec/views/format/format.erb +1 -0
  187. data/spec/template/template_spec/views/format/format.html.erb +1 -0
  188. data/spec/template/template_spec/views/format/format.js.erb +1 -0
  189. data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
  190. data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
  191. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
  192. data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
  193. data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
  194. data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
  195. data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
  196. data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
  197. data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
  198. data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
  199. data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
  200. data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
  201. data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
  202. data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
  203. data/spec/template/template_spec/views/nested/format/a.erb +1 -0
  204. data/spec/template/template_spec/views/nested/format/b.erb +1 -0
  205. data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
  206. data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
  207. data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
  208. data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
  209. data/spec/template/template_spec/views/nesting_format/_dialog.html.erb +1 -0
  210. data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
  211. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
  212. data/spec/template/template_spec/views/other/template.erb +1 -0
  213. data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
  214. data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
  215. data/spec/template/tilt_spec.rb +96 -0
  216. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
  217. data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
  218. data/spec/template/tilt_spec/views/errors.erb +3 -0
  219. data/spec/template/tilt_spec/views/errors.haml +3 -0
  220. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
  221. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
  222. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
  223. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
  224. data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
  225. data/spec/template/tilt_spec/views/ugly.haml +3 -0
  226. data/spec/template/tilt_spec/views/yield.erb +1 -0
  227. metadata +303 -33
  228. data/lib/crystal_ext/defer_js.rb +0 -75
  229. data/lib/crystal_ext/ensure_no_www.rb +0 -39
  230. data/lib/crystal_ext/gems.rb +0 -2
  231. data/lib/crystal_ext/i18n.rb +0 -25
  232. data/lib/crystal_ext/i18n/locales/ru/pluralization.rb +0 -62
  233. data/lib/crystal_ext/plugin.rb +0 -23
  234. data/lib/crystal_ext/plugin/app.rb +0 -19
  235. data/lib/crystal_ext/plugin/web.rb +0 -44
  236. data/lib/crystal_ext/prepare_model.rb +0 -20
  237. data/lib/crystal_ext/profiles/web_ext_require.rb +0 -13
  238. data/lib/crystal_ext/protect_from_forgery.rb +0 -66
  239. data/lib/crystal_ext/user_error.rb +0 -14
  240. data/spec/controller_spec_helper.rb +0 -19
  241. data/spec/defer_js_spec.rb +0 -33
  242. data/spec/i18n_spec.rb +0 -31
  243. data/spec/i18n_spec/locales/en/general.yml +0 -5
  244. data/spec/i18n_spec/locales/ru/general.yml +0 -7
  245. data/spec/prepare_model_spec.rb +0 -43
  246. data/spec/protect_from_forgery_spec.rb +0 -169
  247. data/spec/spec_helper.rb +0 -4
  248. data/spec/user_error_spec.rb +0 -41
@@ -0,0 +1,7 @@
1
+ dir = File.dirname __FILE__
2
+ crystal_dir = File.expand_path "#{dir}/../.."
3
+ lib_dir = "#{crystal_dir}/lib"
4
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
5
+
6
+ require 'spec_ext'
7
+ require 'crystal/mailer'
@@ -0,0 +1,137 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/helper"
2
+
3
+ describe "AbstractController" do
4
+ with_environment :test
5
+ with_abstract_controller_spec
6
+
7
+ before :all do
8
+ @dir = "#{File.expand_path(File.dirname(__FILE__))}/abstract_controller_spec"
9
+ $LOAD_PATH << @dir
10
+
11
+ AbstractController = Crystal::AbstractController
12
+ end
13
+
14
+ after :all do
15
+ $LOAD_PATH.delete @dir
16
+ remove_constants %w(
17
+ WorkspaceVariablesSpec
18
+ SpecialResultSpec
19
+ RespondToSpec
20
+ ViewVariablesSpec
21
+ OperationsOrderSpec
22
+ NoTemplateSpec
23
+ AbstractController
24
+ )
25
+ end
26
+
27
+ it "should set workspace variables" do
28
+ class ::WorkspaceVariablesSpec
29
+ inherit AbstractController
30
+
31
+ def action; end
32
+ end
33
+
34
+ workspace = ccall WorkspaceVariablesSpec, 'action'
35
+
36
+ workspace.delete(:controller).should be_a(WorkspaceVariablesSpec)
37
+ expected_result = {
38
+ :params => {},
39
+
40
+ :class => WorkspaceVariablesSpec,
41
+ :method_name => "action",
42
+ :action => 'action',
43
+
44
+ :content => ""
45
+ }
46
+ workspace.to_h(true).symbolize_keys.subset(expected_result.keys).should == expected_result
47
+ end
48
+
49
+ it "should be able to throw :special_result in controller or view and that result must be assigned as result" do
50
+ class ::SpecialResultSpec
51
+ inherit AbstractController
52
+ def action
53
+ throw :special_result, "some content"
54
+ end
55
+ end
56
+
57
+ ccall(SpecialResultSpec, :action).content.should == "some content"
58
+ end
59
+
60
+ it "respond_to" do
61
+ class ::RespondToSpec
62
+ inherit AbstractController
63
+
64
+ def action
65
+ respond_to do |format|
66
+ format.html{render :inline => 'html'}
67
+ format.json{render :json => {:a => 'b'}}
68
+ end
69
+ end
70
+ end
71
+
72
+ ccall(RespondToSpec, :action, :format => 'html').content.should == 'html'
73
+ ccall(RespondToSpec, :action, :format => 'json').content.should == %({"a":"b"})
74
+ lambda{ccall(RespondToSpec, :action, :format => 'js')}.should raise_error(/Can't respond to js format/)
75
+ end
76
+
77
+ it "controller's instance variables must be available in view, and also other variables" do
78
+ class ::ViewVariablesSpec
79
+ inherit AbstractController
80
+
81
+ def action
82
+ @instance_variable = "iv value"
83
+ end
84
+ end
85
+
86
+ ccall(
87
+ ViewVariablesSpec, :action,
88
+ :param => 'param value', :format => Crystal::Format.new('html')
89
+ ).content.should == %(\
90
+ controller: ViewVariablesSpec
91
+
92
+ class: ViewVariablesSpec
93
+ method_name: action
94
+ action: action
95
+
96
+ instance_variable: iv value
97
+
98
+ params: param value
99
+ format: html)
100
+ end
101
+
102
+ it "operations order" do
103
+ class ::OperationsOrderSpec
104
+ inherit AbstractController
105
+
106
+ def self.result
107
+ @result ||= []
108
+ end
109
+
110
+ around do |controller, block|
111
+ begin
112
+ OperationsOrderSpec.result << :before
113
+ block.call
114
+ ensure
115
+ OperationsOrderSpec.result << :after
116
+ end
117
+ end
118
+
119
+ def action
120
+ OperationsOrderSpec.result << :action
121
+ end
122
+ end
123
+
124
+ ccall(OperationsOrderSpec, :action)
125
+ OperationsOrderSpec.result.should == [:before, :action, :template, :after]
126
+ end
127
+
128
+ it "should write empty response if no template for action" do
129
+ class NoTemplateSpec
130
+ inherit AbstractController
131
+
132
+ def action; end
133
+ end
134
+
135
+ ccall(NoTemplateSpec, :action).content.should == ""
136
+ end
137
+ end
@@ -0,0 +1 @@
1
+ <% OperationsOrderSpec.result << :template %>
@@ -0,0 +1,10 @@
1
+ controller: <%= workspace.controller.class.name %>
2
+
3
+ class: <%= workspace.class.name %>
4
+ method_name: <%= workspace.method_name %>
5
+ action: <%= workspace.action %>
6
+
7
+ instance_variable: <%= @instance_variable %>
8
+
9
+ params: <%= params.param %>
10
+ format: <%= params.format %>
@@ -0,0 +1,122 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/helper"
2
+
3
+ describe "ControllerContext" do
4
+ with_environment :development
5
+
6
+ before :all do
7
+ @dir = "#{File.expand_path(File.dirname(__FILE__))}/controller_context_spec"
8
+ $LOAD_PATH << @dir
9
+ AbstractController = Crystal::AbstractController
10
+
11
+ class ItemSpec
12
+ inherit AbstractController
13
+
14
+ def show; end
15
+ def update; end
16
+ def delete; end
17
+ def increase; end
18
+ def decrease; end
19
+ end
20
+
21
+ class PageSpec < ItemSpec
22
+ def show; end
23
+ def increase; end
24
+ end
25
+
26
+ module NamespaceSpec
27
+ class ClassSpec
28
+ inherit AbstractController
29
+
30
+ def show; end
31
+ def update; end
32
+ end
33
+ end
34
+ end
35
+
36
+ after :all do
37
+ $LOAD_PATH.delete @dir
38
+ remove_constants %w(
39
+ ItemSpec
40
+ PageSpec
41
+ NamespaceSpec
42
+ ItemSpecHelper
43
+ PageSpecHelper
44
+ AbstractController
45
+ )
46
+ end
47
+
48
+ describe "basic" do
49
+ it "should provide template name for non-existing template" do
50
+ ItemSpec.template_name_for(:delete).should == "/ItemSpec/delete"
51
+ PageSpec.template_name_for(:delete).should == "/ItemSpec/delete"
52
+ end
53
+
54
+ it "should provide template name for existing template" do
55
+ ItemSpec.template_name_for(:update).should == "/ItemSpec/update"
56
+ end
57
+
58
+ it "should inherit template name for template existing in parent" do
59
+ PageSpec.template_name_for(:update).should == "/ItemSpec/update"
60
+ end
61
+
62
+ it "should override template name for template existing in both self and parent" do
63
+ ItemSpec.template_name_for(:show).should == "/ItemSpec/show"
64
+ PageSpec.template_name_for(:show).should == "/PageSpec/show"
65
+ end
66
+
67
+ it "should transfer namespaces into folders" do
68
+ NamespaceSpec::ClassSpec.template_name_for(:show).should == "/NamespaceSpec/ClassSpec/show"
69
+ end
70
+ end
71
+
72
+ describe "actions" do
73
+ it "should be able to check for action inside of actions.xxx files" do
74
+ ItemSpec.template_name_for(:increase).should == "/ItemSpec/actions"
75
+ end
76
+
77
+ it "should be able to check for action inside of actions.xxx files" do
78
+ ItemSpec.template_name_for(:increase).should == "/ItemSpec/actions"
79
+ ItemSpec.template_name_for(:decrease).should == "/ItemSpec/actions"
80
+ end
81
+
82
+ it "should inherit actions.xxx" do
83
+ PageSpec.template_name_for(:increase).should == "/ItemSpec/actions"
84
+ PageSpec.template_name_for(:decrease).should == "/PageSpec/actions"
85
+ end
86
+ end
87
+
88
+ describe "controller_context_class, helper" do
89
+ before :each do
90
+ ItemSpec.instance_variable_set "@controller_context_class", nil
91
+ ItemSpec.instance_variable_set "@controller_context_class", nil
92
+ end
93
+
94
+ it "controller_context_class" do
95
+ ItemSpec.controller_context_class.should == ItemSpec::ItemSpecControllerContext
96
+ PageSpec.controller_context_class.should == PageSpec::PageSpecControllerContext
97
+ PageSpec::PageSpecControllerContext.is?(PageSpec::ItemSpecControllerContext).should be_true
98
+ end
99
+
100
+ it "helper" do
101
+ module ::ItemSpecHelper
102
+ def controller_item; end
103
+ end
104
+
105
+ module ::PageSpecHelper
106
+ def controller_page; end
107
+ end
108
+
109
+ ItemSpec.helper ItemSpecHelper
110
+ PageSpec.helper PageSpecHelper
111
+
112
+ ItemSpec::ItemSpecControllerContext.instance_methods.should include('controller_item')
113
+ PageSpec::PageSpecControllerContext.instance_methods.should include('controller_page')
114
+ end
115
+ end
116
+
117
+ describe "other" do
118
+ it "should understand underscored paths" do
119
+ NamespaceSpec::ClassSpec.template_name_for(:update).should == "/namespace_spec/class_spec/update"
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,4 @@
1
+ <% case value %>
2
+ <% when :increase %>
3
+ <% when :decrease %>
4
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% case value %>
2
+ <% when :decrease %>
3
+ <% end %>
@@ -0,0 +1,57 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/helper"
2
+
3
+ describe "AbstractController" do
4
+ with_environment :test
5
+ with_abstract_controller_spec
6
+
7
+ before :all do
8
+ @dir = "#{File.expand_path(File.dirname(__FILE__))}/controller_helper_spec"
9
+ $LOAD_PATH << @dir
10
+ AbstractController = Crystal::AbstractController
11
+ end
12
+
13
+ after :all do
14
+ $LOAD_PATH.delete @dir
15
+ remove_constants %w(
16
+ SomeHelperSpec
17
+ HelperSpec
18
+ HelperMethodSpec
19
+ AbstractController
20
+ )
21
+ end
22
+
23
+ it "helper_method" do
24
+ class ::HelperMethodSpec
25
+ inherit AbstractController
26
+
27
+ def some_controller_method
28
+ "some controller value (rendered in cotext of #{self.class})"
29
+ end
30
+ helper_method :some_controller_method
31
+
32
+ def action; end
33
+ end
34
+
35
+ ccall(HelperMethodSpec, :action).content.
36
+ should == "some controller value (rendered in cotext of HelperMethodSpec)"
37
+ end
38
+
39
+ it "helper" do
40
+ module ::SomeHelperSpec
41
+ def wiget
42
+ "some wighet (rendered in context of #{self.class.name})"
43
+ end
44
+ end
45
+
46
+ class ::HelperSpec
47
+ inherit AbstractController
48
+
49
+ helper SomeHelperSpec
50
+
51
+ def action; end
52
+ end
53
+
54
+ ccall(HelperSpec, :action).content.
55
+ should == "some wighet (rendered in context of HelperSpec::HelperSpecControllerContext)"
56
+ end
57
+ end
@@ -0,0 +1,191 @@
1
+ require "#{File.expand_path(File.dirname(__FILE__))}/helper"
2
+
3
+ describe "Controller render" do
4
+ with_environment :test
5
+ with_abstract_controller_spec
6
+
7
+ before :all do
8
+ @dir = "#{File.expand_path(File.dirname(__FILE__))}/controller_render_spec"
9
+ $LOAD_PATH << @dir
10
+ AbstractController = Crystal::AbstractController
11
+ end
12
+
13
+ after :all do
14
+ $LOAD_PATH.delete @dir
15
+ remove_constants %w(
16
+ LayoutFiltersSpec
17
+ LayoutSpec
18
+ AnotherLayout
19
+ ExplicitRenderSpec
20
+ RenderInsideOfControllerSpec
21
+ ForbidPartialAsActionSpec
22
+ FormatSpec
23
+ AlreadyRenderedSpec
24
+ SpecialFormatSpec
25
+ AnotherActionSpec
26
+ InlineRenderSpec
27
+ AbstractController
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).content.should == "Layout html, content"
42
+ ccall(LayoutFiltersSpec, :action_without_layout).content.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).content.should == "Layout html, content"
54
+ ccall(LayoutSpec, :action, :format => :js).content.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).content.should == "action"
74
+ ccall(AnotherLayout, :another_layout).content.should == "Admin layout, action"
75
+ end
76
+
77
+
78
+ it "explicitly rendered action shold be rendered with layout but template without" do
79
+ class ::ExplicitRenderSpec
80
+ inherit AbstractController
81
+ layout '/layouts/app'
82
+
83
+ def another_action; end
84
+
85
+ def action
86
+ render :action => 'another_action'
87
+ end
88
+
89
+ def render_template
90
+ render '/some_template'
91
+ end
92
+ end
93
+
94
+ ccall(ExplicitRenderSpec, :action).content.should == "Layout html, another action"
95
+ ccall(ExplicitRenderSpec, :render_template).content.should == "some template"
96
+ end
97
+ end
98
+
99
+ it "inside of controller" do
100
+ class ::RenderInsideOfControllerSpec
101
+ inherit AbstractController
102
+
103
+ def some_action
104
+ render '/some_template'
105
+ end
106
+ end
107
+
108
+ ccall(RenderInsideOfControllerSpec, 'some_action').content.should == "some template"
109
+ end
110
+
111
+ it "should not allow to render partials as actions" do
112
+ class ::ForbidPartialAsActionSpec
113
+ inherit AbstractController
114
+ def action; end
115
+ end
116
+
117
+ lambda{ccall ForbidPartialAsActionSpec, :action}.should raise_error(/No template/)
118
+ end
119
+
120
+ it "should render view with right format" do
121
+ class FormatSpec
122
+ inherit AbstractController
123
+ def action; end
124
+ end
125
+
126
+ ccall(FormatSpec, :action, :format => :html).content.should == "html format"
127
+ ccall(FormatSpec, :action, :format => :js).content.should == "js format"
128
+ end
129
+
130
+ it "should be able to use Template.render for different purposes (mail for example)" do
131
+ Crystal::Template.render("/standalone", :locals => {:a => 'a'}).should == 'standalone usage, a'
132
+ end
133
+
134
+ it "should not rener if already rendered in controller" do
135
+ class ::AlreadyRenderedSpec
136
+ inherit AbstractController
137
+
138
+ def action
139
+ render '/AlreadyRenderedSpec/custom_template'
140
+ end
141
+ end
142
+
143
+ ccall(AlreadyRenderedSpec, :action).content.should == 'custom content'
144
+ end
145
+
146
+ it "should handle serialization :json => obj (:xml, :js)" do
147
+ class ::SpecialFormatSpec
148
+ inherit AbstractController
149
+
150
+ def json_action
151
+ render :json => {:a => "b"}
152
+ end
153
+
154
+ def xml_action
155
+ render :xml => {:a => "b"}
156
+ end
157
+ end
158
+
159
+ ccall(SpecialFormatSpec, :json_action, :format => :json).content.should == %({"a":"b"})
160
+ ccall(SpecialFormatSpec, :xml_action, :format => :xml).content.should =~ /<a>b<\/a>/
161
+ lambda{
162
+ ccall(SpecialFormatSpec, :json_action, :format => :xml)
163
+ }.should raise_error(/responing with :json to the :xml/)
164
+ end
165
+
166
+ it "should render another action via :action => :action_name" do
167
+ class ::AnotherActionSpec
168
+ inherit AbstractController
169
+
170
+ def another_action; end
171
+
172
+ def action
173
+ render :action => 'another_action'
174
+ end
175
+ end
176
+
177
+ ccall(AnotherActionSpec, :action).content.should == "another action"
178
+ end
179
+
180
+ it "should take :inline => 'hi' option" do
181
+ class ::InlineRenderSpec
182
+ inherit AbstractController
183
+
184
+ def action
185
+ render :inline => "content"
186
+ end
187
+ end
188
+
189
+ ccall(InlineRenderSpec, :action).content.should == "content"
190
+ end
191
+ end