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,75 @@
1
+ require 'remote/spec_helper'
2
+
3
+ describe "Remote Basic" do
4
+ with_environment
5
+ with_remote_spec
6
+
7
+ it "basic" do
8
+ class BasicSpec
9
+ inherit Rad::Remote
10
+
11
+ def call
12
+ {result: 'some result'}
13
+ end
14
+ end
15
+
16
+ workspace = rcall BasicSpec, :call, format: 'json'
17
+
18
+ workspace.delete(:remote_object).should be_a(BasicSpec)
19
+ expected_result = {
20
+ params: {format: 'json'},
21
+
22
+ class: BasicSpec,
23
+ method_name: :call,
24
+
25
+ remote_result: {result: "some result"},
26
+ content: %({"result":"some result"})
27
+ }
28
+ workspace.to_h(true).subset(expected_result.keys).should == expected_result
29
+ end
30
+
31
+ describe "error handling should behave different in :production, :development and :test modes" do
32
+ it "error in :development mode" do
33
+ class JsonErrorSpec
34
+ inherit Rad::Remote
35
+
36
+ def call_with_error
37
+ raise 'some error'
38
+ end
39
+ end
40
+
41
+ config.environment = :development
42
+ silence_logger!
43
+
44
+ workspace = rcall JsonErrorSpec, 'call_with_error', format: 'json'
45
+
46
+ workspace.delete(:remote_object).should be_a(JsonErrorSpec)
47
+ workspace.include?(:remote_result).should be_false
48
+ expected_result = {
49
+ params: {format: 'json'},
50
+
51
+ class: JsonErrorSpec,
52
+ method_name: "call_with_error",
53
+
54
+ content: %({"error":"some error"})
55
+ }
56
+ workspace.to_h.subset(expected_result.keys).should == expected_result
57
+ end
58
+ end
59
+
60
+ it "should be able to protect methods from GET request"
61
+
62
+ it "should not allow unregistered object types be used as return value" do
63
+ class UnregisteredReturnValueSpec
64
+ inherit Rad::Remote
65
+
66
+ def call
67
+ Object.new
68
+ end
69
+ end
70
+
71
+ lambda{
72
+ rcall UnregisteredReturnValueSpec, 'call', format: 'json'
73
+ }.should raise_error(/You can't use object of type 'Object' as Remote's return value!/)
74
+ end
75
+ end
@@ -0,0 +1,17 @@
1
+ require 'rspec_ext'
2
+
3
+ require 'rad/remote'
4
+
5
+ require 'rad/spec/remote'
6
+
7
+ rspec do
8
+ def self.with_remote_spec
9
+ before :all do
10
+ rad.after :environment do
11
+ rad.conveyors.services do |ss|
12
+ ss.use Rad::Processors::RemoteCaller, :content
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,98 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "AliasRouter" do
4
+ before :all do
5
+ class SomeController
6
+ end
7
+ end
8
+
9
+ after :all do
10
+ remove_constants %w(SomeController)
11
+ end
12
+
13
+ before :each do
14
+ @router = Rad::AliasRouter.new
15
+ end
16
+
17
+ it "encode / decode" do
18
+ @router.add '/login', class: SomeController, method: :login
19
+
20
+ @router.encode(SomeController, :login, {}).should == ["/login", {}]
21
+ @router.encode_method('login_path').should == [SomeController, :login]
22
+ @router.decode("/login", {}).should == [SomeController, :login, {}]
23
+ end
24
+
25
+ it "should differentiate aliases with similar path elements" do
26
+ @router.add '/login', class: SomeController, method: :login
27
+ @router.add '/login/twitter', class: SomeController, method: :twitter
28
+
29
+ @router.encode(SomeController, :login, {}).should == ["/login", {}]
30
+ @router.decode("/login", {}).should == [SomeController, :login, {}]
31
+
32
+ @router.encode(SomeController, :twitter, {}).should == ["/login/twitter", {}]
33
+ @router.decode("/login/twitter", {}).should == [SomeController, :twitter, {}]
34
+ end
35
+
36
+ it "input validation" do
37
+ lambda{@router.add :login, class: SomeController, method: :login}.should raise_error(/\//)
38
+ lambda{@router.add '/login', class: SomeController}.should raise_error(/method/)
39
+ lambda{@router.add '/login', method: :login}.should raise_error(/class/)
40
+ lambda{@router.add '/login', class: SomeController, method: :login, invalid: 'value'}.should raise_error(/unknown/)
41
+ lambda{@router.add '/login', class: SomeController, method: :login, url_root: 'users'}.should raise_error(/\//)
42
+ lambda{@router.add '/login', class: SomeController, method: :login, prefix: []}.should raise_error(/empty/)
43
+ end
44
+
45
+ it "should use :url_root" do
46
+ @router.add '/login', class: SomeController, method: :login, url_root: '/space'
47
+
48
+ @router.encode(SomeController, :login, {}).should == ["/space/login", {}]
49
+ @router.decode("/space/login", {}).should == [SomeController, :login, {}]
50
+ end
51
+
52
+ it "should return nil if route unknown" do
53
+ @router.encode(SomeController, :unknown, {}).should be_nil
54
+ @router.encode_method(:unknown_path).should be_nil
55
+ @router.decode("/login", {}).should be_nil
56
+ end
57
+
58
+ it 'root alias' do
59
+ @router.add '/', class: SomeController, method: :home
60
+
61
+ @router.encode(SomeController, :home, {}).should == ["/", {}]
62
+ @router.decode("/", {}).should == [SomeController, :home, {}]
63
+
64
+ # should not support url_root
65
+ -> {@router.add '/', class: SomeController, method: :home, url_root: '/space'}.should raise_error(/url_root/)
66
+ end
67
+
68
+ describe "prefixes" do
69
+ it "basics" do
70
+ @router.add '/statistics', class: SomeController, method: :statistics, prefix: [:l, :space]
71
+
72
+ @router.encode(SomeController, :statistics, l: 'en', space: 'personal').should == ["/l/en/space/personal/statistics", {}]
73
+ @router.encode_method("statistics_path").should == [SomeController, :statistics]
74
+ @router.decode("/l/en/space/personal/statistics", {}).should == [SomeController, :statistics, {l: 'en', space: 'personal'}]
75
+ end
76
+
77
+ it "should also works with path with slashes" do
78
+ @router.add '/blogs/show', class: SomeController, method: :show, prefix: [:l, :space]
79
+
80
+ @router.encode(SomeController, :show, l: 'en', space: 'personal').should == ["/l/en/space/personal/blogs/show", {}]
81
+ @router.decode("/l/en/space/personal/blogs/show", {}).should == [SomeController, :show, {l: 'en', space: 'personal'}]
82
+ end
83
+
84
+ it "should raise error if prefixes not provided" do
85
+ @router.add '/login', class: SomeController, method: :login, prefix: [:l]
86
+
87
+ lambda{@router.encode(SomeController, :login, {})}.should raise_error(/prefix/)
88
+ lambda{@router.decode('/login', {})}.should raise_error(/prefix/)
89
+ end
90
+
91
+ it "should works with :url_root" do
92
+ @router.add '/blogs/show', class: SomeController, method: :show, prefix: [:l], url_root: '/users'
93
+
94
+ @router.encode(SomeController, :show, l: 'en').should == ["/users/l/en/blogs/show", {}]
95
+ @router.decode("/users/l/en/blogs/show", {}).should == [SomeController, :show, {l: 'en'}]
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,111 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "Router Basic" do
4
+
5
+ before :all do
6
+ class ::BlogsController
7
+ include Rad::CoreRoutingHelper
8
+
9
+ def show; end
10
+ end
11
+ end
12
+
13
+ after :all do
14
+ remove_constants %w(BlogsController)
15
+ end
16
+
17
+ before :each do
18
+ @router = Rad::Router.new :class
19
+
20
+ @params = Rad::Params.new
21
+ @router.stub(:safe_workspace).and_return({params: @params}.to_openobject)
22
+ end
23
+
24
+ it "encode" do
25
+ @router.encode(BlogsController, :show, format: 'json').should == ["/blogs_controller/show.json", {}]
26
+ end
27
+
28
+ it "encode_method" do
29
+ lambda{@router.encode_method :class_method}.should raise_error(/route method/)
30
+ @router.routes.first.should_receive(:encode_method).and_return([BlogsController, :show])
31
+ @router.encode_method(:class_method).should == [BlogsController, :show]
32
+ end
33
+
34
+ it "decode" do
35
+ @router.decode("/blogs_controller/show", {}).should == [BlogsController, :show, {}]
36
+ end
37
+
38
+ it "skip" do
39
+ @router.skip(/\/fs/)
40
+
41
+ skip = catch :skip do
42
+ @router.decode("/fs/user/avatar", {})
43
+ nil
44
+ end
45
+ skip.should_not be_nil
46
+ end
47
+
48
+ describe "url_for" do
49
+ it "should convert complex params to json" do
50
+ @router.url_for(BlogsController, :show, a: :b, as_json: true).should == %(/blogs_controller/show?json=%7B%22a%22%3A%22b%22%7D)
51
+ end
52
+
53
+ it "should escape params" do
54
+ @router.url_for(BlogsController, :show, a: 'b/c').should == "/blogs_controller/show?a=b%2Fc"
55
+ end
56
+
57
+ it "url_for" do
58
+ @router.stub(:current_class).and_return(BlogsController)
59
+
60
+ @router.url_for(BlogsController, :show, format: 'json').should == "/blogs_controller/show.json"
61
+ @router.url_for(:show, format: 'json').should == "/blogs_controller/show.json"
62
+
63
+ @router.url_for(BlogsController, :show).should == "/blogs_controller/show"
64
+ @router.url_for(:show).should == "/blogs_controller/show"
65
+ @router.url_for(:show).should == "/blogs_controller/show"
66
+ end
67
+
68
+ it "url_for_path should recognize first slash as to use url_for_path" do
69
+ @router.url_for('/some_path', key: :value).should == "/some_path?key=value"
70
+ @router.url_for('/some_path').should == "/some_path"
71
+ end
72
+
73
+ it "should mark url string with format" do
74
+ @router.stub(:current_class).and_return(BlogsController)
75
+ @router.url_for(:show, format: 'js').marks.format.should == 'js'
76
+
77
+ @router.url_for('/path').marks.format.should be_nil
78
+ @router.url_for('/path', format: 'js').marks.format.should == 'js'
79
+ end
80
+
81
+ it "shouldn't modify arguments (from error)" do
82
+ options = {format: :js}
83
+ @router.url_for(BlogsController, :show, options).should == "/blogs_controller/show.js"
84
+ options.should == {format: :js}
85
+ end
86
+ end
87
+
88
+ describe "persistent params" do
89
+ before :each do
90
+ @router.persistent_params << :l
91
+ end
92
+
93
+ it "global persistent params" do
94
+ @params.l, @params.id = 'ru', 1
95
+
96
+ @router.url_for(BlogsController, :show).should == "/blogs_controller/show?l=ru"
97
+ @router.url_for(BlogsController, :show, l: 'en').should == "/blogs_controller/show?l=en"
98
+ end
99
+
100
+ it "should persist params with begining underscore" do
101
+ @params._space, @params.id = 'space_id', 1
102
+
103
+ @router.url_for(BlogsController, :show).should == '/blogs_controller/show'
104
+
105
+ @router.persist_params do
106
+ @router.url_for(BlogsController, :show).should == '/blogs_controller/show?_space=space_id'
107
+ @router.url_for(BlogsController, :show, _space: 'another_id').should == '/blogs_controller/show?_space=another_id'
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,18 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "Configurator" do
4
+ before :each do
5
+ @router = Rad::Router.new :class
6
+ Rad::Routes::Configurator.stub(:router).and_return(@router)
7
+ end
8
+
9
+ it "named routes" do
10
+ rad.routes do |config|
11
+ config.stub(:router).and_return(@router)
12
+
13
+ config.skip(/^\/favicon/)
14
+ end
15
+
16
+ @router.skip.size.should > 0
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "Remote Basic" do
4
+ with_environment
5
+ with_router_spec
6
+
7
+ before :all do
8
+ class ::AnRemote
9
+ def call; end
10
+ end
11
+ end
12
+
13
+ after :all do
14
+ remove_constants %w(AnRemote)
15
+ end
16
+
17
+ def call_router path, params
18
+ rad.conveyors.web.call path: path, params: Rad::Params.new(params)
19
+ end
20
+
21
+ it "basic" do
22
+ workspace = call_router '/an_remote/call', format: 'json'
23
+
24
+ expected_result = {
25
+ path: "/an_remote/call",
26
+ params: {format: 'json'},
27
+
28
+ class_variable: AnRemote,
29
+ method_variable: :call
30
+ }
31
+ workspace.to_h(true).subset(expected_result.keys).should == expected_result
32
+ end
33
+
34
+ it "params must be casted to string" do
35
+ workspace = call_router '/an_remote/call', a: 'b'
36
+ workspace.params.to_h.subset(:a).should == {a: 'b'}
37
+ end
38
+
39
+ it "default router should raise error if route is invalid" do
40
+ lambda{call_router '/invalid/call', format: 'json'}.should raise_error(/uninitialized constant Invalid/)
41
+ end
42
+ end
@@ -0,0 +1,65 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "Persistent Params" do
4
+ after :all do
5
+ remove_constants %w(PathParamsRouter)
6
+ end
7
+
8
+ before :each do
9
+ @router = Rad::Router.new :class
10
+
11
+ @params = Rad::Params.new
12
+ @router.stub(:safe_workspace).and_return({params: @params}.to_openobject)
13
+
14
+ @router.persistent_params << :l
15
+ end
16
+
17
+ describe 'Basics' do
18
+ it "global persistent params" do
19
+ @params.merge! l: 'ru', id: 1
20
+
21
+ @router.encode(Object, :send).should == ["/object/send", {l: 'ru'}]
22
+ @router.encode(Object, :send, l: 'en').should == ["/object/send", {l: 'en'}]
23
+ end
24
+
25
+ it "should persist params with begining underscore" do
26
+ @params.merge! _space: 'space_id', id: 1
27
+
28
+ @router.encode(Object, :send).should == ['/object/send', {}]
29
+
30
+ @router.persist_params do
31
+ @router.encode(Object, :send).should == ["/object/send", {_space: 'space_id'}]
32
+ @router.encode(Object, :send, _space: 'another_id').should == ["/object/send", {_space: 'another_id'}]
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "Micelaneous checks" do
38
+ it "should not persist special params" do
39
+ @params.merge! _method: 'get'
40
+
41
+ @router.persist_params do
42
+ @router.encode(Object, :send).should == ["/object/send", {}]
43
+ end
44
+ end
45
+ end
46
+
47
+ it "should correctly works when params are encoded in url path" do
48
+ class PathParamsRouter
49
+ def encode klass, method, params
50
+ [%(#{klass.name}/#{method}#{'/' unless params.empty?}#{params.to_a.collect{|k, v| "#{k}/#{v}"}.join('/')}), {}]
51
+ end
52
+
53
+ def decode path, params
54
+ end
55
+ end
56
+
57
+ router = Rad::Router.new :class, [[:prefix_router, PathParamsRouter.new]]
58
+ router.persistent_params << :l
59
+ params = Rad::Params.new
60
+ params.l = 'en'
61
+ router.stub(:safe_workspace).and_return({params: params}.to_openobject)
62
+
63
+ router.encode(Object, :send).should == ["Object/send/l/en", {}]
64
+ end
65
+ end
@@ -0,0 +1,120 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "RestfulRouter" do
4
+ before :all do
5
+ class ::BlogControllerSpec
6
+ def show; end
7
+ end
8
+ end
9
+
10
+ after :all do
11
+ remove_constants %w(BlogControllerSpec)
12
+ end
13
+
14
+ before :each do
15
+ @router = Rad::RestfulRouter.new
16
+ end
17
+
18
+ describe 'core API' do
19
+ it "singleton resource" do
20
+ @router.add :blogs, class: BlogControllerSpec
21
+
22
+ @router.encode(BlogControllerSpec, :show, {}).should == ["/blogs/show", {}]
23
+ @router.encode_method('show_blog_path').should == [BlogControllerSpec, :show]
24
+ @router.encode_method('show_blogs_path').should == [BlogControllerSpec, :show]
25
+ @router.decode("/blogs/show", {}).should == [BlogControllerSpec, :show, {}]
26
+ end
27
+
28
+ it "object resource" do
29
+ @router.add :blogs, class: BlogControllerSpec
30
+
31
+ @router.encode(BlogControllerSpec, :show, id: '10', view: 'full').should == ["/blogs/10/show", {view: 'full'}]
32
+ @router.encode_method('show_blog_path').should == [BlogControllerSpec, :show]
33
+ @router.encode_method('show_blogs_path').should == [BlogControllerSpec, :show]
34
+ @router.decode("/blogs/10/show", {view: 'full'}).should == [BlogControllerSpec, :show, {id: '10', view: 'full'}]
35
+ end
36
+ end
37
+
38
+ describe "prefixes" do
39
+ it "singleton resource" do
40
+ @router.add :blogs, class: BlogControllerSpec, prefix: [:l, :space]
41
+
42
+ @router.encode(BlogControllerSpec, :show, l: 'en', space: 'personal').should == ["/l/en/space/personal/blogs/show", {}]
43
+ @router.decode("/l/en/space/personal/blogs/show", {}).should == [BlogControllerSpec, :show, {l: 'en', space: 'personal'}]
44
+ end
45
+
46
+ it "object resource" do
47
+ @router.add :blogs, class: BlogControllerSpec, prefix: [:l, :space]
48
+
49
+ @router.encode(BlogControllerSpec, :show, id: '10', l: 'en', space: 'personal').should == ["/l/en/space/personal/blogs/10/show", {}]
50
+ @router.decode("/l/en/space/personal/blogs/10/show", {}).should == [BlogControllerSpec, :show, {id: '10', l: 'en', space: 'personal'}]
51
+ end
52
+
53
+ it "should raise error or return nil if prefixes not provided" do
54
+ @router.add :blogs, class: BlogControllerSpec, prefix: [:l]
55
+
56
+ lambda{@router.encode(BlogControllerSpec, :show, {})}.should raise_error(/prefix/)
57
+ @router.decode('/blogs/show', {}).should be_nil
58
+
59
+ lambda{@router.encode(BlogControllerSpec, :show, id: '10')}.should raise_error(/prefix/)
60
+ @router.decode('/blogs/10/show', {}).should be_nil
61
+ end
62
+
63
+ it "should works with :url_root" do
64
+ @router.add :blogs, class: BlogControllerSpec, prefix: [:l], url_root: '/users'
65
+
66
+ @router.encode(BlogControllerSpec, :show, l: 'en').should == ["/users/l/en/blogs/show", {}]
67
+ @router.decode("/users/l/en/blogs/show", {}).should == [BlogControllerSpec, :show, {l: 'en'}]
68
+
69
+ @router.encode(BlogControllerSpec, :show, id: '10', l: 'en').should == ["/users/l/en/blogs/10/show", {}]
70
+ @router.decode("/users/l/en/blogs/10/show", {}).should == [BlogControllerSpec, :show, {id: '10', l: 'en'}]
71
+ end
72
+
73
+ it "should be able to use alias for prefix parameter" do
74
+ @router.add :blogs, class: BlogControllerSpec, prefix: [:l, [:space_id, 'space']]
75
+
76
+ @router.encode(BlogControllerSpec, :show, l: 'en', space_id: 'personal').should == ["/l/en/space/personal/blogs/show", {}]
77
+ @router.decode("/l/en/space/personal/blogs/show", {}).should == [BlogControllerSpec, :show, {l: 'en', space_id: 'personal'}]
78
+ end
79
+ end
80
+
81
+ describe "micelaneous check" do
82
+ it "should allow only plural form in resource definition" do
83
+ lambda{@router.add :blog, class: BlogControllerSpec}.should raise_error(/plural/)
84
+ @router.add :blogs, class: BlogControllerSpec
85
+ end
86
+
87
+ it "shouldn't allow slashes in resource name" do
88
+ lambda{@router.add '/admin/blogs', class: BlogControllerSpec}.should raise_error(/\//)
89
+ end
90
+
91
+ it "should correctly works with unknown routes" do
92
+ @router.encode(BlogControllerSpec, :show, {}).should be_nil
93
+ @router.encode_method('show_blog_path').should be_nil
94
+ @router.encode_method('show_blogs_path').should be_nil
95
+ @router.decode("/blogs/show", {}).should be_nil
96
+
97
+ @router.encode(BlogControllerSpec, :show, id: '10', view: 'full').should be_nil
98
+ @router.encode_method('show_blog_path').should be_nil
99
+ @router.encode_method('show_blogs_path').should be_nil
100
+ @router.decode("/blogs/10/show", view: 'full').should be_nil
101
+ end
102
+ end
103
+
104
+ it "should use :url_root" do
105
+ @router.add :blogs, class: BlogControllerSpec, url_root: '/users'
106
+
107
+ @router.encode(BlogControllerSpec, :show, {}).should == ["/users/blogs/show", {}]
108
+ @router.decode("/users/blogs/show", {}).should == [BlogControllerSpec, :show, {}]
109
+
110
+ @router.encode(BlogControllerSpec, :show, id: '10').should == ["/users/blogs/10/show", {}]
111
+ @router.decode("/users/blogs/10/show", {}).should == [BlogControllerSpec, :show, {id: '10'}]
112
+ end
113
+
114
+ it "input validation" do
115
+ lambda{@router.add :blogs, class: BlogControllerSpec, invalid: 'value'}.should raise_error(/unknown/)
116
+ lambda{@router.add :blogs}.should raise_error(/class/)
117
+ lambda{@router.add :blogs, class: BlogControllerSpec, url_root: 'users'}.should raise_error(/\//)
118
+ lambda{@router.add :blogs, class: BlogControllerSpec, prefix: []}.should raise_error(/empty/)
119
+ end
120
+ end
@@ -0,0 +1,55 @@
1
+ require 'router/spec_helper'
2
+
3
+ describe "Routing Helper" do
4
+
5
+ before :all do
6
+ class ::BlogsController
7
+ include Rad::CoreRoutingHelper
8
+
9
+ def show; end
10
+ end
11
+ end
12
+
13
+ after :all do
14
+ remove_constants %w(BlogsController)
15
+ end
16
+
17
+ before :each do
18
+ @router = Rad::Router.new :class
19
+
20
+ @params = Rad::Params.new
21
+ @router.stub(:safe_workspace).and_return({params: @params}.to_openobject)
22
+
23
+ @controller = BlogsController.new
24
+ @controller.stub(:router).and_return(@router)
25
+ end
26
+
27
+ it "basic" do
28
+ @router.stub(:encode_method).and_return([BlogsController, :show])
29
+ @controller.show_blogs_path.should == "/blogs_controller/show"
30
+ end
31
+
32
+ it "correct works if there's no route" do
33
+ lambda{@controller.undefined_path}.should raise_error(/no route for/)
34
+ lambda{@controller.show_blogs}.should raise_error(/undefined method/)
35
+ end
36
+
37
+ it "argument parsing" do
38
+ @router.stub(:encode_method).and_return([BlogsController, :show])
39
+
40
+ @controller.show_blogs_path.should == "/blogs_controller/show"
41
+ @controller.show_blogs_path(a: 'b').should == "/blogs_controller/show?a=b"
42
+ @controller.show_blogs_path(10, a: 'b').should == "/blogs_controller/show?a=b&id=10"
43
+ end
44
+
45
+ it "helper_method should take any object as :id" do
46
+ class IdStub
47
+ def to_param
48
+ 'some_id'
49
+ end
50
+ end
51
+
52
+ @router.stub(:encode_method).and_return([BlogsController, :show])
53
+ @controller.show_blogs_path(IdStub.new, a: 'b').should == "/blogs_controller/show?a=b&id=some_id"
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec_ext'
2
+
3
+ require 'rad/http'
4
+ require 'rad/router'
5
+
6
+ require 'rad/spec/environment'
7
+
8
+ rspec do
9
+ def self.with_router_spec
10
+ before :all do
11
+ rad.after :environment do
12
+ rad.register :router, depends_on: :environment do
13
+ Rad::Router.new(:class, [[:default_router, Rad::SimpleRouter.new]])
14
+ end
15
+
16
+ rad.conveyors.web.use Rad::Processors::Router, :class_variable, :method_variable
17
+ end
18
+ end
19
+ end
20
+ end