thorero 0.9.4.4 → 0.9.4.5
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.
- data/LICENSE +1 -1
- data/README +21 -0
- data/Rakefile +275 -108
- data/TODO +0 -0
- data/bin/merb +12 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +58 -0
- data/docs/documentation_standards +40 -0
- data/docs/merb-core-call-stack-diagram.mmap +0 -0
- data/docs/merb-core-call-stack-diagram.pdf +0 -0
- data/docs/merb-core-call-stack-diagram.png +0 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +603 -0
- data/lib/merb-core/autoload.rb +32 -0
- data/lib/merb-core/bootloader.rb +708 -0
- data/lib/merb-core/config.rb +303 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +578 -0
- data/lib/merb-core/controller/exceptions.rb +302 -0
- data/lib/merb-core/controller/merb_controller.rb +256 -0
- data/lib/merb-core/controller/mime.rb +106 -0
- data/lib/merb-core/controller/mixins/authentication.rb +87 -0
- data/lib/merb-core/controller/mixins/controller.rb +290 -0
- data/lib/merb-core/controller/mixins/render.rb +481 -0
- data/lib/merb-core/controller/mixins/responder.rb +472 -0
- data/lib/merb-core/controller/template.rb +254 -0
- data/lib/merb-core/core_ext.rb +8 -0
- data/lib/merb-core/core_ext/kernel.rb +319 -0
- data/lib/merb-core/dispatch/cookies.rb +91 -0
- data/lib/merb-core/dispatch/dispatcher.rb +278 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +303 -0
- data/lib/merb-core/dispatch/request.rb +603 -0
- data/lib/merb-core/dispatch/router.rb +179 -0
- data/lib/merb-core/dispatch/router/behavior.rb +867 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +321 -0
- data/lib/merb-core/dispatch/session.rb +78 -0
- data/lib/merb-core/dispatch/session/cookie.rb +168 -0
- data/lib/merb-core/dispatch/session/memcached.rb +184 -0
- data/lib/merb-core/dispatch/session/memory.rb +241 -0
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +77 -0
- data/lib/{extlib → merb-core}/logger.rb +2 -2
- data/lib/merb-core/plugins.rb +59 -0
- data/lib/merb-core/rack.rb +21 -0
- data/lib/merb-core/rack/adapter.rb +44 -0
- data/lib/merb-core/rack/adapter/ebb.rb +25 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
- data/lib/merb-core/rack/adapter/irb.rb +118 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/runner.rb +28 -0
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +39 -0
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/adapter/webrick.rb +36 -0
- data/lib/merb-core/rack/application.rb +18 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/rack/middleware.rb +26 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
- data/lib/merb-core/rack/middleware/profiler.rb +19 -0
- data/lib/merb-core/rack/middleware/static.rb +45 -0
- data/lib/merb-core/server.rb +252 -0
- data/lib/merb-core/tasks/audit.rake +68 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
- data/lib/merb-core/test.rb +11 -0
- data/lib/merb-core/test/helpers.rb +9 -0
- data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
- data/lib/merb-core/test/helpers/request_helper.rb +344 -0
- data/lib/merb-core/test/helpers/route_helper.rb +33 -0
- data/lib/merb-core/test/helpers/view_helper.rb +121 -0
- data/lib/merb-core/test/matchers.rb +9 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +319 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +335 -0
- data/lib/merb-core/test/run_specs.rb +47 -0
- data/lib/merb-core/test/tasks/spectasks.rb +68 -0
- data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
- data/lib/merb-core/test/test_ext/object.rb +14 -0
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +345 -0
- data/lib/merb-core/version.rb +11 -0
- data/spec/private/config/adapter_spec.rb +32 -0
- data/spec/private/config/config_spec.rb +202 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/kernel_spec.rb +169 -0
- data/spec/private/dispatch/bootloader_spec.rb +24 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +35 -0
- data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
- data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
- data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
- data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
- data/spec/private/dispatch/fixture/config/init.rb +45 -0
- data/spec/private/dispatch/fixture/config/rack.rb +11 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +1874 -0
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
- data/spec/private/dispatch/route_params_spec.rb +24 -0
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/dispatch/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +166 -0
- data/spec/private/rack/application_spec.rb +49 -0
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +139 -0
- data/spec/private/router/route_spec.rb +414 -0
- data/spec/private/router/router_spec.rb +175 -0
- data/spec/private/vendor/facets/plural_spec.rb +564 -0
- data/spec/private/vendor/facets/singular_spec.rb +489 -0
- data/spec/public/DEFINITIONS +11 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +193 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +41 -0
- data/spec/public/abstract_controller/controllers/partial.rb +121 -0
- data/spec/public/abstract_controller/controllers/render.rb +113 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
- data/spec/public/abstract_controller/display_spec.rb +33 -0
- data/spec/public/abstract_controller/filter_spec.rb +106 -0
- data/spec/public/abstract_controller/helper_spec.rb +21 -0
- data/spec/public/abstract_controller/partial_spec.rb +61 -0
- data/spec/public/abstract_controller/render_spec.rb +90 -0
- data/spec/public/abstract_controller/spec_helper.rb +31 -0
- data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
- data/spec/public/boot_loader/spec_helper.rb +1 -0
- data/spec/public/controller/authentication_spec.rb +103 -0
- data/spec/public/controller/base_spec.rb +36 -0
- data/spec/public/controller/controllers/authentication.rb +45 -0
- data/spec/public/controller/controllers/base.rb +36 -0
- data/spec/public/controller/controllers/display.rb +118 -0
- data/spec/public/controller/controllers/redirect.rb +30 -0
- data/spec/public/controller/controllers/responder.rb +93 -0
- data/spec/public/controller/controllers/url.rb +7 -0
- data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
- data/spec/public/controller/display_spec.rb +84 -0
- data/spec/public/controller/redirect_spec.rb +27 -0
- data/spec/public/controller/responder_spec.rb +163 -0
- data/spec/public/controller/spec_helper.rb +11 -0
- data/spec/public/controller/url_spec.rb +180 -0
- data/spec/public/core/merb_core_spec.rb +45 -0
- data/spec/public/core_ext/class_spec.rb +91 -0
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
- data/spec/public/core_ext/kernel_spec.rb +9 -0
- data/spec/public/core_ext/spec_helper.rb +1 -0
- data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
- data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
- data/spec/public/directory_structure/directory/config/router.rb +3 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +562 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +181 -0
- data/spec/public/logger/spec_helper.rb +1 -0
- data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
- data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
- data/spec/public/reloading/directory/config/init.rb +2 -0
- data/spec/public/reloading/directory/log/merb_test.log +138 -0
- data/spec/public/reloading/reload_spec.rb +103 -0
- data/spec/public/request/multipart_spec.rb +41 -0
- data/spec/public/request/request_spec.rb +228 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +1556 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/nested_resources_spec.rb +41 -0
- data/spec/public/router/resource_spec.rb +37 -0
- data/spec/public/router/resources_spec.rb +82 -0
- data/spec/public/router/spec_helper.rb +90 -0
- data/spec/public/router/special_spec.rb +61 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +104 -0
- data/spec/public/template/templates/error.html.erb +2 -0
- data/spec/public/template/templates/template.html.erb +1 -0
- data/spec/public/template/templates/template.html.myt +1 -0
- data/spec/public/test/controller_matchers_spec.rb +402 -0
- data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
- data/spec/public/test/controllers/dispatch_controller.rb +11 -0
- data/spec/public/test/controllers/spec_helper_controller.rb +38 -0
- data/spec/public/test/multipart_request_helper_spec.rb +159 -0
- data/spec/public/test/multipart_upload_text_file.txt +1 -0
- data/spec/public/test/request_helper_spec.rb +221 -0
- data/spec/public/test/route_helper_spec.rb +71 -0
- data/spec/public/test/route_matchers_spec.rb +162 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +183 -0
- data/spec/spec_helper.rb +68 -0
- metadata +493 -41
- data/README.txt +0 -3
- data/lib/extlib.rb +0 -32
- data/lib/extlib/assertions.rb +0 -8
- data/lib/extlib/blank.rb +0 -42
- data/lib/extlib/class.rb +0 -175
- data/lib/extlib/hash.rb +0 -410
- data/lib/extlib/hook.rb +0 -366
- data/lib/extlib/inflection.rb +0 -141
- data/lib/extlib/lazy_array.rb +0 -106
- data/lib/extlib/mash.rb +0 -143
- data/lib/extlib/module.rb +0 -37
- data/lib/extlib/object.rb +0 -165
- data/lib/extlib/object_space.rb +0 -13
- data/lib/extlib/pathname.rb +0 -5
- data/lib/extlib/pooling.rb +0 -233
- data/lib/extlib/rubygems.rb +0 -38
- data/lib/extlib/simple_set.rb +0 -39
- data/lib/extlib/string.rb +0 -132
- data/lib/extlib/struct.rb +0 -8
- data/lib/extlib/tasks/release.rb +0 -9
- data/lib/extlib/time.rb +0 -12
- data/lib/extlib/version.rb +0 -3
- data/lib/extlib/virtual_file.rb +0 -10
@@ -0,0 +1,68 @@
|
|
1
|
+
namespace :audit do
|
2
|
+
|
3
|
+
desc "Print out the named and anonymous routes"
|
4
|
+
task :routes => :merb_env do
|
5
|
+
seen = []
|
6
|
+
unless Merb::Router.named_routes.empty?
|
7
|
+
puts "Named Routes"
|
8
|
+
Merb::Router.named_routes.each do |name,route|
|
9
|
+
puts " #{name}: #{route}"
|
10
|
+
seen << route
|
11
|
+
end
|
12
|
+
end
|
13
|
+
puts "Anonymous Routes"
|
14
|
+
(Merb::Router.routes - seen).each do |route|
|
15
|
+
puts " #{route}"
|
16
|
+
end
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "Print out all controllers"
|
21
|
+
task :controllers => :merb_env do
|
22
|
+
puts "\nControllers:\n\n"
|
23
|
+
abstract_controller_classes.each do |klass|
|
24
|
+
if klass.respond_to?(:subclasses_list)
|
25
|
+
puts "#{klass} < #{klass.superclass}"
|
26
|
+
subklasses = klass.subclasses_list.sort.map { |x| Object.full_const_get(x) }
|
27
|
+
unless subklasses.empty?
|
28
|
+
subklasses.each { |subklass| puts "- #{subklass}" }
|
29
|
+
else
|
30
|
+
puts "~ no subclasses"
|
31
|
+
end
|
32
|
+
puts
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Print out controllers and their actions (use CONTROLLER=Foo,Bar to be selective)"
|
38
|
+
task :actions => :merb_env do
|
39
|
+
puts "\nControllers and their actions:\n\n"
|
40
|
+
filter_controllers = ENV['CONTROLLER'] ? ENV['CONTROLLER'].split(',') : nil
|
41
|
+
abstract_controllers = abstract_controller_classes
|
42
|
+
classes = Merb::AbstractController.subclasses_list.sort.map { |x| Object.full_const_get(x) }
|
43
|
+
classes = classes.select { |k| k.name.in?(filter_controllers) } if filter_controllers
|
44
|
+
classes.each do |subklass|
|
45
|
+
next if subklass.in?(abstract_controllers) || !subklass.respond_to?(:callable_actions)
|
46
|
+
puts "#{subklass} < #{subklass.superclass}"
|
47
|
+
unless subklass.callable_actions.empty?
|
48
|
+
subklass.callable_actions.sort.each do |action, null|
|
49
|
+
if subklass.respond_to?(:action_argument_list)
|
50
|
+
arguments, defaults = subklass.action_argument_list[action]
|
51
|
+
args = arguments.map { |name, value| value ? "#{name} = #{value.inspect}" : name.to_s }.join(', ')
|
52
|
+
puts args.empty? ? "- #{action}" : "- #{action}(#{args})"
|
53
|
+
else
|
54
|
+
puts "- #{action}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
puts "~ no callable actions"
|
59
|
+
end
|
60
|
+
puts
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def abstract_controller_classes
|
65
|
+
ObjectSpace.classes.select { |x| x.superclass == Merb::AbstractController }.sort_by { |x| x.name }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) / '*.rake'].each { |ext| load ext }
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "hpricot"
|
2
|
+
|
3
|
+
require 'merb-core/test/test_ext/hpricot'
|
4
|
+
require 'merb-core/test/test_ext/object'
|
5
|
+
require 'merb-core/test/test_ext/string'
|
6
|
+
|
7
|
+
module Merb; module Test; end; end
|
8
|
+
|
9
|
+
require 'merb-core/test/helpers'
|
10
|
+
|
11
|
+
require 'merb-core/test/matchers'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# This is a place holder to allow plugins etc a place to include
|
2
|
+
# testing helpers
|
3
|
+
module Merb::Test::Helpers; end
|
4
|
+
|
5
|
+
require "merb-core/test/helpers/request_helper"
|
6
|
+
require "merb-core/test/helpers/multipart_request_helper"
|
7
|
+
require "merb-core/test/helpers/controller_helper"
|
8
|
+
require "merb-core/test/helpers/route_helper"
|
9
|
+
require "merb-core/test/helpers/view_helper"
|
@@ -0,0 +1,175 @@
|
|
1
|
+
module Merb::Test::MultipartRequestHelper
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mime/types'
|
4
|
+
|
5
|
+
class Param
|
6
|
+
attr_accessor :key, :value
|
7
|
+
|
8
|
+
# ==== Parameters
|
9
|
+
# key<~to_s>:: The parameter key.
|
10
|
+
# value<~to_s>:: The parameter value.
|
11
|
+
def initialize(key, value)
|
12
|
+
@key = key
|
13
|
+
@value = value
|
14
|
+
end
|
15
|
+
|
16
|
+
# ==== Returns
|
17
|
+
# String:: The parameter in a form suitable for a multipart request.
|
18
|
+
def to_multipart
|
19
|
+
return %(Content-Disposition: form-data; name="#{key}"\r\n\r\n#{value}\r\n)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FileParam
|
24
|
+
attr_accessor :key, :filename, :content
|
25
|
+
|
26
|
+
# ==== Parameters
|
27
|
+
# key<~to_s>:: The parameter key.
|
28
|
+
# filename<~to_s>:: Name of the file for this parameter.
|
29
|
+
# content<~to_s>:: Content of the file for this parameter.
|
30
|
+
def initialize(key, filename, content)
|
31
|
+
@key = key
|
32
|
+
@filename = filename
|
33
|
+
@content = content
|
34
|
+
end
|
35
|
+
|
36
|
+
# ==== Returns
|
37
|
+
# String::
|
38
|
+
# The file parameter in a form suitable for a multipart request.
|
39
|
+
def to_multipart
|
40
|
+
return %(Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n) + "Content-Type: #{MIME::Types.type_for(@filename)}\r\n\r\n" + content + "\r\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Post
|
45
|
+
BOUNDARY = '----------0xKhTmLbOuNdArY'
|
46
|
+
CONTENT_TYPE = "multipart/form-data, boundary=" + BOUNDARY
|
47
|
+
|
48
|
+
# ==== Parameters
|
49
|
+
# params<Hash>:: Optional params for the controller.
|
50
|
+
def initialize(params = {})
|
51
|
+
@multipart_params = []
|
52
|
+
push_params(params)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Saves the params in an array of multipart params as Param and
|
56
|
+
# FileParam objects.
|
57
|
+
#
|
58
|
+
# ==== Parameters
|
59
|
+
# params<Hash>:: The params to add to the multipart params.
|
60
|
+
# prefix<~to_s>:: An optional prefix for the request string keys.
|
61
|
+
def push_params(params, prefix = nil)
|
62
|
+
params.sort_by {|k| k.to_s}.each do |key, value|
|
63
|
+
param_key = prefix.nil? ? key : "#{prefix}[#{key}]"
|
64
|
+
if value.respond_to?(:read)
|
65
|
+
@multipart_params << FileParam.new(param_key, value.path, value.read)
|
66
|
+
else
|
67
|
+
if value.is_a?(Hash) || value.is_a?(Mash)
|
68
|
+
value.keys.each do |k|
|
69
|
+
push_params(value, param_key)
|
70
|
+
end
|
71
|
+
else
|
72
|
+
@multipart_params << Param.new(param_key, value)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# ==== Returns
|
79
|
+
# Array[String, String]:: The query and the content type.
|
80
|
+
def to_multipart
|
81
|
+
query = @multipart_params.collect { |param| "--" + BOUNDARY + "\r\n" + param.to_multipart }.join("") + "--" + BOUNDARY + "--"
|
82
|
+
return query, CONTENT_TYPE
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Similar to dispatch_to but allows for sending files inside params.
|
87
|
+
#
|
88
|
+
# ==== Paramters
|
89
|
+
# controller_klass<Controller>::
|
90
|
+
# The controller class object that the action should be dispatched to.
|
91
|
+
# action<Symbol>:: The action name, as a symbol.
|
92
|
+
# params<Hash>::
|
93
|
+
# An optional hash that will end up as params in the controller instance.
|
94
|
+
# env<Hash>::
|
95
|
+
# An optional hash that is passed to the fake request. Any request options
|
96
|
+
# should go here (see +fake_request+).
|
97
|
+
# &blk:: The block is executed in the context of the controller.
|
98
|
+
#
|
99
|
+
# ==== Example
|
100
|
+
# dispatch_multipart_to(MyController, :create, :my_file => @a_file ) do |controller|
|
101
|
+
# controller.stub!(:current_user).and_return(@user)
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# ==== Notes
|
105
|
+
# Set your option to contain a file object to simulate file uploads.
|
106
|
+
#
|
107
|
+
# Does not use routes.
|
108
|
+
#---
|
109
|
+
# @public
|
110
|
+
def dispatch_multipart_to(controller_klass, action, params = {}, env = {}, &blk)
|
111
|
+
request = multipart_fake_request(env, params)
|
112
|
+
dispatch_request(request, controller_klass, action, &blk)
|
113
|
+
end
|
114
|
+
|
115
|
+
# An HTTP POST request that operates through the router and uses multipart
|
116
|
+
# parameters.
|
117
|
+
#
|
118
|
+
# ==== Parameters
|
119
|
+
# path<String>:: The path that should go to the router as the request uri.
|
120
|
+
# params<Hash>::
|
121
|
+
# An optional hash that will end up as params in the controller instance.
|
122
|
+
# env<Hash>::
|
123
|
+
# An optional hash that is passed to the fake request. Any request options
|
124
|
+
# should go here (see +fake_request+).
|
125
|
+
# block<Proc>:: The block is executed in the context of the controller.
|
126
|
+
#
|
127
|
+
# ==== Notes
|
128
|
+
# To include an uploaded file, put a file object as a value in params.
|
129
|
+
def multipart_post(path, params = {}, env = {}, &block)
|
130
|
+
env[:request_method] = "POST"
|
131
|
+
env[:test_with_multipart] = true
|
132
|
+
request(path, params, env, &block)
|
133
|
+
end
|
134
|
+
|
135
|
+
# An HTTP PUT request that operates through the router and uses multipart
|
136
|
+
# parameters.
|
137
|
+
#
|
138
|
+
# ==== Parameters
|
139
|
+
# path<String>:: The path that should go to the router as the request uri.
|
140
|
+
# params<Hash>::
|
141
|
+
# An optional hash that will end up as params in the controller instance.
|
142
|
+
# env<Hash>::
|
143
|
+
# An optional hash that is passed to the fake request. Any request options
|
144
|
+
# should go here (see +fake_request+).
|
145
|
+
# block<Proc>:: The block is executed in the context of the controller.
|
146
|
+
#
|
147
|
+
# ==== Notes
|
148
|
+
# To include an uplaoded file, put a file object as a value in params.
|
149
|
+
def multipart_put(path, params = {}, env = {}, &block)
|
150
|
+
env[:request_method] = "PUT"
|
151
|
+
env[:test_with_multipart] = true
|
152
|
+
request(path, params, env, &block)
|
153
|
+
end
|
154
|
+
|
155
|
+
# ==== Parameters
|
156
|
+
# env<Hash>::
|
157
|
+
# An optional hash that is passed to the fake request. Any request options
|
158
|
+
# should go here (see +fake_request+).
|
159
|
+
# params<Hash>::
|
160
|
+
# An optional hash that will end up as params in the controller instance.
|
161
|
+
#
|
162
|
+
# ==== Returns
|
163
|
+
# FakeRequest::
|
164
|
+
# A multipart Request object that is built based on the parameters.
|
165
|
+
def multipart_fake_request(env = {}, params = {})
|
166
|
+
if params.empty?
|
167
|
+
fake_request(env)
|
168
|
+
else
|
169
|
+
m = Post.new(params)
|
170
|
+
body, head = m.to_multipart
|
171
|
+
fake_request(env.merge( :content_type => head,
|
172
|
+
:content_length => body.length), :post_body => body)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,344 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Merb
|
4
|
+
module Test
|
5
|
+
module RequestHelper
|
6
|
+
# FakeRequest sets up a default enviroment which can be overridden either
|
7
|
+
# by passing and env into initialize or using request['HTTP_VAR'] = 'foo'
|
8
|
+
class FakeRequest < Request
|
9
|
+
|
10
|
+
# ==== Parameters
|
11
|
+
# env<Hash>:: Environment options that override the defaults.
|
12
|
+
# req<StringIO>:: The request to set as input for Rack.
|
13
|
+
def initialize(env = {}, req = StringIO.new)
|
14
|
+
env.environmentize_keys!
|
15
|
+
env['rack.input'] = req
|
16
|
+
super(DEFAULT_ENV.merge(env))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
DEFAULT_ENV = Mash.new({
|
21
|
+
'SERVER_NAME' => 'localhost',
|
22
|
+
'PATH_INFO' => '/',
|
23
|
+
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate',
|
24
|
+
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.1) Gecko/20060214 Camino/1.0',
|
25
|
+
'SCRIPT_NAME' => '/',
|
26
|
+
'SERVER_PROTOCOL' => 'HTTP/1.1',
|
27
|
+
'HTTP_CACHE_CONTROL' => 'max-age=0',
|
28
|
+
'HTTP_ACCEPT_LANGUAGE' => 'en,ja;q=0.9,fr;q=0.9,de;q=0.8,es;q=0.7,it;q=0.7,nl;q=0.6,sv;q=0.5,nb;q=0.5,da;q=0.4,fi;q=0.3,pt;q=0.3,zh-Hans;q=0.2,zh-Hant;q=0.1,ko;q=0.1',
|
29
|
+
'HTTP_HOST' => 'localhost',
|
30
|
+
'REMOTE_ADDR' => '127.0.0.1',
|
31
|
+
'SERVER_SOFTWARE' => 'Mongrel 1.1',
|
32
|
+
'HTTP_KEEP_ALIVE' => '300',
|
33
|
+
'HTTP_REFERER' => 'http://localhost/',
|
34
|
+
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
|
35
|
+
'HTTP_VERSION' => 'HTTP/1.1',
|
36
|
+
'REQUEST_URI' => '/',
|
37
|
+
'SERVER_PORT' => '80',
|
38
|
+
'GATEWAY_INTERFACE' => 'CGI/1.2',
|
39
|
+
'HTTP_ACCEPT' => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
|
40
|
+
'HTTP_CONNECTION' => 'keep-alive',
|
41
|
+
'REQUEST_METHOD' => 'GET'
|
42
|
+
}) unless defined?(DEFAULT_ENV)
|
43
|
+
end
|
44
|
+
|
45
|
+
# ==== Parameters
|
46
|
+
# env<Hash>:: A hash of environment keys to be merged into the default list.
|
47
|
+
# opt<Hash>:: A hash of options (see below).
|
48
|
+
#
|
49
|
+
# ==== Options (opt)
|
50
|
+
# :post_body<String>:: The post body for the request.
|
51
|
+
# :req<String>::
|
52
|
+
# The request string. This will only be used if :post_body is left out.
|
53
|
+
#
|
54
|
+
# ==== Returns
|
55
|
+
# FakeRequest:: A Request object that is built based on the parameters.
|
56
|
+
#
|
57
|
+
# ==== Notes
|
58
|
+
# If you pass a post body, the content-type will be set to URL-encoded.
|
59
|
+
#
|
60
|
+
#---
|
61
|
+
# @public
|
62
|
+
def fake_request(env = {}, opt = {})
|
63
|
+
if opt[:post_body]
|
64
|
+
req = opt[:post_body]
|
65
|
+
env[:content_type] ||= "application/x-www-form-urlencoded"
|
66
|
+
else
|
67
|
+
req = opt[:req]
|
68
|
+
end
|
69
|
+
FakeRequest.new(env, StringIO.new(req || ''))
|
70
|
+
end
|
71
|
+
|
72
|
+
# Dispatches an action to the given class. This bypasses the router and is
|
73
|
+
# suitable for unit testing of controllers.
|
74
|
+
#
|
75
|
+
# ==== Parameters
|
76
|
+
# controller_klass<Controller>::
|
77
|
+
# The controller class object that the action should be dispatched to.
|
78
|
+
# action<Symbol>:: The action name, as a symbol.
|
79
|
+
# params<Hash>::
|
80
|
+
# An optional hash that will end up as params in the controller instance.
|
81
|
+
# env<Hash>::
|
82
|
+
# An optional hash that is passed to the fake request. Any request options
|
83
|
+
# should go here (see +fake_request+), including :req or :post_body
|
84
|
+
# for setting the request body itself.
|
85
|
+
# &blk::
|
86
|
+
# The controller is yielded to the block provided for actions *prior* to
|
87
|
+
# the action being dispatched.
|
88
|
+
#
|
89
|
+
# ==== Example
|
90
|
+
# dispatch_to(MyController, :create, :name => 'Homer' ) do |controller|
|
91
|
+
# controller.stub!(:current_user).and_return(@user)
|
92
|
+
# end
|
93
|
+
#
|
94
|
+
# ==== Notes
|
95
|
+
# Does not use routes.
|
96
|
+
#
|
97
|
+
#---
|
98
|
+
# @public
|
99
|
+
def dispatch_to(controller_klass, action, params = {}, env = {}, &blk)
|
100
|
+
dispatch_request(build_request(params, env), controller_klass, action.to_s, &blk)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# Dispatches an action to the given class and using HTTP Basic Authentication
|
105
|
+
# This bypasses the router and is suitable for unit testing of controllers.
|
106
|
+
#
|
107
|
+
# ==== Parameters
|
108
|
+
# controller_klass<Controller>::
|
109
|
+
# The controller class object that the action should be dispatched to.
|
110
|
+
# action<Symbol>:: The action name, as a symbol.
|
111
|
+
# username<String>:: The username.
|
112
|
+
# password<String>:: The password.
|
113
|
+
# params<Hash>::
|
114
|
+
# An optional hash that will end up as params in the controller instance.
|
115
|
+
# env<Hash>::
|
116
|
+
# An optional hash that is passed to the fake request. Any request options
|
117
|
+
# should go here (see +fake_request+), including :req or :post_body
|
118
|
+
# for setting the request body itself.
|
119
|
+
# &blk::
|
120
|
+
# The controller is yielded to the block provided for actions *prior* to
|
121
|
+
# the action being dispatched.
|
122
|
+
#
|
123
|
+
# ==== Example
|
124
|
+
# dispatch_with_basic_authentication_to(MyController, :create, 'Fred', 'secret', :name => 'Homer' ) do |controller|
|
125
|
+
# controller.stub!(:current_user).and_return(@user)
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# ==== Notes
|
129
|
+
# Does not use routes.
|
130
|
+
#
|
131
|
+
#---
|
132
|
+
# @public
|
133
|
+
def dispatch_with_basic_authentication_to(controller_klass, action, username, password, params = {}, env = {}, &blk)
|
134
|
+
env["X_HTTP_AUTHORIZATION"] = "Basic #{Base64.encode64("#{username}:#{password}")}"
|
135
|
+
|
136
|
+
dispatch_request(build_request(params, env), controller_klass, action.to_s, &blk)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Prepares and returns a request suitable for dispatching with
|
140
|
+
# dispatch_request. If you don't need to modify the request
|
141
|
+
# object before dispatching (e.g. to add cookies), you probably
|
142
|
+
# want to use dispatch_to instead.
|
143
|
+
#
|
144
|
+
# ==== Parameters
|
145
|
+
# params<Hash>::
|
146
|
+
# An optional hash that will end up as params in the controller instance.
|
147
|
+
# env<Hash>::
|
148
|
+
# An optional hash that is passed to the fake request. Any request options
|
149
|
+
# should go here (see +fake_request+), including :req or :post_body
|
150
|
+
# for setting the request body itself.
|
151
|
+
#
|
152
|
+
# ==== Example
|
153
|
+
# req = build_request(:id => 1)
|
154
|
+
# req.cookies['app_cookie'] = "testing"
|
155
|
+
# dispatch_request(req, MyController, :edit)
|
156
|
+
#
|
157
|
+
# ==== Notes
|
158
|
+
# Does not use routes.
|
159
|
+
#
|
160
|
+
#---
|
161
|
+
# @public
|
162
|
+
def build_request(params = {}, env = {})
|
163
|
+
params = Merb::Request.params_to_query_string(params)
|
164
|
+
env[:query_string] = env["QUERY_STRING"] ? "#{env["QUERY_STRING"]}&#{params}" : params
|
165
|
+
|
166
|
+
fake_request(env, { :post_body => env[:post_body], :req => env[:req] })
|
167
|
+
end
|
168
|
+
|
169
|
+
# An HTTP GET request that operates through the router.
|
170
|
+
#
|
171
|
+
# ==== Parameters
|
172
|
+
# path<String>:: The path that should go to the router as the request uri.
|
173
|
+
# params<Hash>::
|
174
|
+
# An optional hash that will end up as params in the controller instance.
|
175
|
+
# env<Hash>::
|
176
|
+
# An optional hash that is passed to the fake request. Any request options
|
177
|
+
# should go here (see +fake_request+).
|
178
|
+
# &blk::
|
179
|
+
# The controller is yielded to the block provided for actions *prior* to
|
180
|
+
# the action being dispatched.
|
181
|
+
#---
|
182
|
+
# @public
|
183
|
+
def get(path, params = {}, env = {}, &block)
|
184
|
+
env[:request_method] = "GET"
|
185
|
+
request(path, params, env, &block)
|
186
|
+
end
|
187
|
+
|
188
|
+
# An HTTP POST request that operates through the router.
|
189
|
+
#
|
190
|
+
# ==== Parameters
|
191
|
+
# path<String>:: The path that should go to the router as the request uri.
|
192
|
+
# params<Hash>::
|
193
|
+
# An optional hash that will end up as params in the controller instance.
|
194
|
+
# env<Hash>::
|
195
|
+
# An optional hash that is passed to the fake request. Any request options
|
196
|
+
# should go here (see fake_request).
|
197
|
+
# &blk::
|
198
|
+
# The controller is yielded to the block provided for actions *prior* to
|
199
|
+
# the action being dispatched.
|
200
|
+
#---
|
201
|
+
# @public
|
202
|
+
def post(path, params = {}, env = {}, &block)
|
203
|
+
env[:request_method] = "POST"
|
204
|
+
request(path, params, env, &block)
|
205
|
+
end
|
206
|
+
|
207
|
+
# An HTTP PUT request that operates through the router.
|
208
|
+
#
|
209
|
+
# ==== Parameters
|
210
|
+
# path<String>:: The path that should go to the router as the request uri.
|
211
|
+
# params<Hash>::
|
212
|
+
# An optional hash that will end up as params in the controller instance.
|
213
|
+
# env<Hash>::
|
214
|
+
# An optional hash that is passed to the fake request. Any request options
|
215
|
+
# should go here (see fake_request).
|
216
|
+
# &blk::
|
217
|
+
# The controller is yielded to the block provided for actions *prior* to
|
218
|
+
# the action being dispatched.
|
219
|
+
#---
|
220
|
+
# @public
|
221
|
+
def put(path, params = {}, env = {}, &block)
|
222
|
+
env[:request_method] = "PUT"
|
223
|
+
request(path, params, env, &block)
|
224
|
+
end
|
225
|
+
|
226
|
+
# An HTTP DELETE request that operates through the router
|
227
|
+
#
|
228
|
+
# ==== Parameters
|
229
|
+
# path<String>:: The path that should go to the router as the request uri.
|
230
|
+
# params<Hash>::
|
231
|
+
# An optional hash that will end up as params in the controller instance.
|
232
|
+
# env<Hash>::
|
233
|
+
# An optional hash that is passed to the fake request. Any request options
|
234
|
+
# should go here (see fake_request).
|
235
|
+
# &blk::
|
236
|
+
# The controller is yielded to the block provided for actions *prior* to
|
237
|
+
# the action being dispatched.
|
238
|
+
#---
|
239
|
+
# @public
|
240
|
+
def delete(path, params = {}, env = {}, &block)
|
241
|
+
env[:request_method] = "DELETE"
|
242
|
+
request(path, params, env, &block)
|
243
|
+
end
|
244
|
+
|
245
|
+
# A generic request that checks the router for the controller and action.
|
246
|
+
# This request goes through the Merb::Router and finishes at the controller.
|
247
|
+
#
|
248
|
+
# ==== Parameters
|
249
|
+
# path<String>:: The path that should go to the router as the request uri.
|
250
|
+
# params<Hash>::
|
251
|
+
# An optional hash that will end up as params in the controller instance.
|
252
|
+
# env<Hash>::
|
253
|
+
# An optional hash that is passed to the fake request. Any request options
|
254
|
+
# should go here (see +fake_request+).
|
255
|
+
# &blk::
|
256
|
+
# The controller is yielded to the block provided for actions *prior* to
|
257
|
+
# the action being dispatched.
|
258
|
+
#
|
259
|
+
# ==== Example
|
260
|
+
# request(path, { :name => 'Homer' }, { :request_method => "PUT" }) do |controller|
|
261
|
+
# controller.stub!(:current_user).and_return(@user)
|
262
|
+
# end
|
263
|
+
#
|
264
|
+
# ==== Notes
|
265
|
+
# Uses Routes.
|
266
|
+
#
|
267
|
+
#---
|
268
|
+
# @semi-public
|
269
|
+
def request(path, params = {}, env= {}, &block)
|
270
|
+
env[:request_method] ||= "GET"
|
271
|
+
env[:request_uri], env[:query_string] = path.split('?')
|
272
|
+
|
273
|
+
multipart = env.delete(:test_with_multipart)
|
274
|
+
|
275
|
+
request = fake_request(env)
|
276
|
+
|
277
|
+
opts = check_request_for_route(request) # Check that the request will be routed correctly
|
278
|
+
controller_name = (opts[:namespace] ? opts.delete(:namespace) + '/' : '') + opts.delete(:controller)
|
279
|
+
klass = Object.full_const_get(controller_name.snake_case.to_const_string)
|
280
|
+
|
281
|
+
action = opts.delete(:action).to_s
|
282
|
+
params.merge!(opts)
|
283
|
+
|
284
|
+
multipart.nil? ? dispatch_to(klass, action, params, env, &block) : dispatch_multipart_to(klass, action, params, env, &block)
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
# The workhorse for the dispatch*to helpers.
|
289
|
+
#
|
290
|
+
# ==== Parameters
|
291
|
+
# request<Merb::Test::FakeRequest, Merb::Request>::
|
292
|
+
# A request object that has been setup for testing.
|
293
|
+
# controller_klass<Merb::Controller>::
|
294
|
+
# The class object off the controller to dispatch the action to.
|
295
|
+
# action<Symbol>:: The action to dispatch the request to.
|
296
|
+
# &blk::
|
297
|
+
# The controller is yielded to the block provided for actions *prior* to
|
298
|
+
# the action being dispatched.
|
299
|
+
#
|
300
|
+
# ==== Returns
|
301
|
+
# An instance of +controller_klass+ based on the parameters.
|
302
|
+
#
|
303
|
+
# ==== Notes
|
304
|
+
# Does not use routes.
|
305
|
+
#
|
306
|
+
#---
|
307
|
+
# @public
|
308
|
+
def dispatch_request(request, controller_klass, action, &blk)
|
309
|
+
controller = controller_klass.new(request)
|
310
|
+
yield controller if block_given?
|
311
|
+
controller._dispatch(action)
|
312
|
+
|
313
|
+
Merb.logger.info controller._benchmarks.inspect
|
314
|
+
Merb.logger.flush
|
315
|
+
|
316
|
+
controller
|
317
|
+
end
|
318
|
+
|
319
|
+
# Checks to see that a request is routable.
|
320
|
+
#
|
321
|
+
# ==== Parameters
|
322
|
+
# request<Merb::Test::FakeRequest, Merb::Request>::
|
323
|
+
# The request object to inspect.
|
324
|
+
#
|
325
|
+
# ==== Raises
|
326
|
+
# Merb::ControllerExceptions::BadRequest::
|
327
|
+
# No matching route was found.
|
328
|
+
#
|
329
|
+
# ==== Returns
|
330
|
+
# Hash:: The parameters built based on the matching route.
|
331
|
+
#
|
332
|
+
#---
|
333
|
+
# @semi-public
|
334
|
+
def check_request_for_route(request)
|
335
|
+
match = ::Merb::Router.match(request)
|
336
|
+
if match[0].nil? && match[1].empty?
|
337
|
+
raise ::Merb::ControllerExceptions::BadRequest, "No routes match the request"
|
338
|
+
else
|
339
|
+
match[1]
|
340
|
+
end
|
341
|
+
end # check_request_for_route
|
342
|
+
end # RequestHelper
|
343
|
+
end # Test
|
344
|
+
end # Merb
|