merb-core 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +285 -0
- data/TODO +0 -0
- data/bin/merb +8 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +57 -0
- data/docs/documentation_standards +40 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +304 -0
- data/lib/merb-core/autoload.rb +29 -0
- data/lib/merb-core/bootloader.rb +601 -0
- data/lib/merb-core/config.rb +284 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +531 -0
- data/lib/merb-core/controller/exceptions.rb +257 -0
- data/lib/merb-core/controller/merb_controller.rb +214 -0
- data/lib/merb-core/controller/mime.rb +88 -0
- data/lib/merb-core/controller/mixins/controller.rb +262 -0
- data/lib/merb-core/controller/mixins/render.rb +324 -0
- data/lib/merb-core/controller/mixins/responder.rb +464 -0
- data/lib/merb-core/controller/template.rb +205 -0
- data/lib/merb-core/core_ext.rb +12 -0
- data/lib/merb-core/core_ext/class.rb +192 -0
- data/lib/merb-core/core_ext/hash.rb +422 -0
- data/lib/merb-core/core_ext/kernel.rb +304 -0
- data/lib/merb-core/core_ext/mash.rb +154 -0
- data/lib/merb-core/core_ext/object.rb +136 -0
- data/lib/merb-core/core_ext/object_space.rb +14 -0
- data/lib/merb-core/core_ext/rubygems.rb +28 -0
- data/lib/merb-core/core_ext/set.rb +41 -0
- data/lib/merb-core/core_ext/string.rb +69 -0
- data/lib/merb-core/dispatch/cookies.rb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +233 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +297 -0
- data/lib/merb-core/dispatch/request.rb +560 -0
- data/lib/merb-core/dispatch/router.rb +141 -0
- data/lib/merb-core/dispatch/router/behavior.rb +777 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +212 -0
- data/lib/merb-core/dispatch/session.rb +28 -0
- data/lib/merb-core/dispatch/session/cookie.rb +166 -0
- data/lib/merb-core/dispatch/session/memcached.rb +161 -0
- data/lib/merb-core/dispatch/session/memory.rb +234 -0
- data/lib/merb-core/gem_ext/erubis.rb +19 -0
- data/lib/merb-core/logger.rb +230 -0
- data/lib/merb-core/plugins.rb +25 -0
- data/lib/merb-core/rack.rb +15 -0
- data/lib/merb-core/rack/adapter.rb +42 -0
- data/lib/merb-core/rack/adapter/ebb.rb +22 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +24 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +16 -0
- data/lib/merb-core/rack/adapter/irb.rb +108 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +25 -0
- data/lib/merb-core/rack/adapter/runner.rb +27 -0
- data/lib/merb-core/rack/adapter/thin.rb +27 -0
- data/lib/merb-core/rack/adapter/webrick.rb +35 -0
- data/lib/merb-core/rack/application.rb +77 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/server.rb +184 -0
- data/lib/merb-core/test.rb +10 -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 +257 -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 +269 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +293 -0
- data/lib/merb-core/test/run_specs.rb +38 -0
- data/lib/merb-core/test/tasks/spectasks.rb +39 -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/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +211 -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 +139 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/hash_spec.rb +506 -0
- data/spec/private/core_ext/kernel_spec.rb +46 -0
- data/spec/private/core_ext/object_spec.rb +39 -0
- data/spec/private/core_ext/set_spec.rb +26 -0
- data/spec/private/core_ext/string_spec.rb +9 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +26 -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/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 +1 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/development.log +1 -0
- data/spec/private/dispatch/fixture/log/merb.4000.pid +1 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +2040 -0
- data/spec/private/dispatch/fixture/log/production.log +1 -0
- data/spec/private/dispatch/fixture/merb.4000.pid +1 -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/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +81 -0
- data/spec/private/rack/application_spec.rb +43 -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/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +167 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +31 -0
- data/spec/public/abstract_controller/controllers/partial.rb +106 -0
- data/spec/public/abstract_controller/controllers/render.rb +86 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/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/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_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_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 +80 -0
- data/spec/public/abstract_controller/helper_spec.rb +13 -0
- data/spec/public/abstract_controller/partial_spec.rb +53 -0
- data/spec/public/abstract_controller/render_spec.rb +70 -0
- data/spec/public/abstract_controller/spec_helper.rb +27 -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/base_spec.rb +31 -0
- data/spec/public/controller/controllers/base.rb +41 -0
- data/spec/public/controller/controllers/display.rb +40 -0
- data/spec/public/controller/controllers/responder.rb +67 -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/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/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 +34 -0
- data/spec/public/controller/log/merb.4000.pid +1 -0
- data/spec/public/controller/responder_spec.rb +95 -0
- data/spec/public/controller/spec_helper.rb +9 -0
- data/spec/public/controller/url_spec.rb +152 -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.4000.pid +1 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +265 -0
- data/spec/public/directory_structure/directory/merb.4000.pid +1 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +175 -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.4000.pid +1 -0
- data/spec/public/reloading/directory/log/merb_test.log +59 -0
- data/spec/public/reloading/directory/merb.4000.pid +1 -0
- data/spec/public/reloading/reload_spec.rb +80 -0
- data/spec/public/request/multipart_spec.rb +15 -0
- data/spec/public/request/request_spec.rb +207 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_resources_spec.rb +34 -0
- data/spec/public/router/resource_spec.rb +45 -0
- data/spec/public/router/resources_spec.rb +57 -0
- data/spec/public/router/spec_helper.rb +72 -0
- data/spec/public/router/special_spec.rb +44 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +92 -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 +378 -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 +30 -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 +153 -0
- data/spec/public/test/route_helper_spec.rb +54 -0
- data/spec/public/test/route_matchers_spec.rb +133 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +107 -0
- data/spec/spec_helper.rb +71 -0
- metadata +488 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "The default routes" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
Merb::Router.prepare {|r| r.default_routes}
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should match /foo to the Foo controller and index action" do
|
10
|
+
route_to("/foo").should have_route(:controller => "foo", :action => "index", :id => nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should match /foo/bar to the Foo controller and the bar action" do
|
14
|
+
route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar", :id => nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should match /foo/bar/12 to the Foo controller, the bar action, and id of 12" do
|
18
|
+
route_to("/foo/bar/12").should have_route(:controller => "foo", :action => "bar", :id => "12")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "Deferred routes" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
Merb::Router.prepare do |r|
|
7
|
+
r.match("/deferred/:zoo").defer_to do |request, params|
|
8
|
+
params.merge(:controller => "w00t") if params[:zoo]
|
9
|
+
end
|
10
|
+
r.default_routes
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match routes based on the incoming params" do
|
15
|
+
route_to("/deferred/baz", :boo => "12").should have_route(:controller => "w00t", :zoo => "baz")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should fall back to the default route if the deferred condition is not met" do
|
19
|
+
route_to("/deferred").should have_route(:controller => "deferred", :action => "index")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
describe "namespaced resource(s) routes" do
|
3
|
+
|
4
|
+
after :each do
|
5
|
+
Merb::Router.named_routes = {}
|
6
|
+
Merb::Router.routes = []
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should match a get to /admin/blogposts without setting namespace" do
|
10
|
+
Merb::Router.prepare do |r|
|
11
|
+
r.match('/admin') do |admin|
|
12
|
+
admin.resources :blogposts
|
13
|
+
end
|
14
|
+
end
|
15
|
+
route_to('/admin/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace=>nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match a get to /admin/blogposts setting namespace manually" do
|
19
|
+
Merb::Router.prepare do |r|
|
20
|
+
r.match('/admin').to(:namespace => "my_admin") do |admin|
|
21
|
+
admin.resources :blogposts
|
22
|
+
end
|
23
|
+
end
|
24
|
+
route_to('/admin/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace=>"my_admin")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should match a get to /admin/blogposts to the blogposts controller and index action" do
|
28
|
+
Merb::Router.prepare do |r|
|
29
|
+
r.namespace :admin do |admin|
|
30
|
+
admin.resources :blogposts
|
31
|
+
end
|
32
|
+
end
|
33
|
+
route_to('/admin/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace => 'admin')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should match a get to /admin/foo to the foo controller and show action" do
|
37
|
+
Merb::Router.prepare do |r|
|
38
|
+
r.namespace :admin do |admin|
|
39
|
+
admin.resource :foo
|
40
|
+
end
|
41
|
+
end
|
42
|
+
route_to('/admin/foo', :method => :get).should have_route(:controller => 'foo', :action => 'show', :id => nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should match a get to /admin/foo/blogposts to the blogposts controller and index action" do
|
46
|
+
Merb::Router.prepare do |r|
|
47
|
+
r.namespace :admin do |admin|
|
48
|
+
admin.resource :foo do |foo|
|
49
|
+
foo.resources :blogposts
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
route_to('/admin/foo/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace => 'admin')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should match a get to /admin/blogposts/1/foo to the foo controller and the show action" do
|
57
|
+
Merb::Router.prepare do |r|
|
58
|
+
r.namespace :admin do |admin|
|
59
|
+
admin.resources :blogposts do |blogposts|
|
60
|
+
blogposts.resource :foo
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
route_to('/admin/blogposts/1/foo', :method => :get).should have_route(:controller => 'foo', :action => 'show', :blogpost_id => '1', :id => nil, :namespace => "admin")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should match a get to /blogposts to the blogposts controller when namespace is passed in to resources" do
|
68
|
+
Merb::Router.prepare do |r|
|
69
|
+
r.resources :blogposts, :namespace => "admin"
|
70
|
+
end
|
71
|
+
route_to("/blogposts", :method =>:get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace => "admin")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should match a get to /blogposts/1/foo to the foo controller when namespace is passed in to resources as an option" do
|
75
|
+
Merb::Router.prepare do |r|
|
76
|
+
r.resources :blogposts, :namespace => "admin" do |blogposts|
|
77
|
+
blogposts.resource :foo, :namespace => "admin"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
route_to("/blogposts", :method =>:get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace => "admin")
|
81
|
+
route_to("/blogposts/1/foo", :method =>:get).should have_route(:controller => 'foo', :action => 'show', :blogpost_id => '1', :namespace => "admin")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should match a get to /blogposts/1/foo to the foo controller without a namespace" do
|
85
|
+
Merb::Router.prepare do |r|
|
86
|
+
r.resources :blogposts, :namespace => "admin" do |blogposts|
|
87
|
+
blogposts.resource :foo
|
88
|
+
end
|
89
|
+
end
|
90
|
+
route_to("/blogposts/1/foo", :method =>:get).should have_route(:controller => 'foo', :action => 'show', :blogpost_id => '1', :namespace => nil)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should match a get to /my_admin/blogposts to the blogposts controller with a custom patch setting" do
|
94
|
+
Merb::Router.prepare do |r|
|
95
|
+
r.namespace(:admin, :path=>"my_admin") do |admin|
|
96
|
+
admin.resources :blogposts
|
97
|
+
end
|
98
|
+
end
|
99
|
+
route_to('/my_admin/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil, :namespace => 'admin')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should match a get to /admin/blogposts/1/foo to the foo controller and the show action with namespace admin" do
|
103
|
+
Merb::Router.prepare do |r|
|
104
|
+
r.namespace(:admin, :path=>"") do |admin|
|
105
|
+
admin.resources :blogposts do |blogposts|
|
106
|
+
blogposts.resource :foo
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
route_to('/blogposts/1/foo', :method => :get).should have_route(:controller => 'foo', :action => 'show', :blogpost_id => '1', :id => nil, :namespace => "admin")
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
Merb::Router.prepare do |r|
|
4
|
+
r.resources :blogposts do |b|
|
5
|
+
b.resources :comments do |c|
|
6
|
+
c.resources :versions
|
7
|
+
end
|
8
|
+
end
|
9
|
+
r.resources :users do |u|
|
10
|
+
u.resources :comments
|
11
|
+
end
|
12
|
+
r.resource :foo do |f|
|
13
|
+
f.resources :comments
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "nested resources routes" do
|
18
|
+
|
19
|
+
it "should match a get to /blogposts/1/comments to the comments controller and index action with blogpost_id" do
|
20
|
+
route_to('/blogposts/1/comments', :method => :get).should have_route(:controller => 'comments', :action => 'index', :id => nil, :blogpost_id => '1')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should match a get to /blogposts/1/comments/2/versions to the versions controller and index action with blogpost_id and comment_id" do
|
24
|
+
route_to('/blogposts/1/comments/2/versions', :method => :get).should have_route(:controller => 'versions', :action => 'index', :id => nil, :blogpost_id => '1', :comment_id => '2')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should match a get to /users/1/comments to the comments controller and index action with user_id" do
|
28
|
+
route_to('/users/1/comments', :method => :get).should have_route(:controller => 'comments', :action => 'index', :id => nil, :user_id => '1')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should match a get to /foo/comments to the comments controller and index action" do
|
32
|
+
route_to('/foo/comments', :method => :get).should have_route(:controller => 'comments', :action => 'index', :id => nil)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "resources routes" do
|
4
|
+
before :each do
|
5
|
+
Merb::Router.prepare do |r|
|
6
|
+
r.resource :foo
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should match a get to /foo to the blogposts controller and show action" do
|
11
|
+
route_to('/foo', :method => :get).should have_route(:controller => 'foo', :action => 'show', :id => nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match a post to /foo to the blogposts controller and create action" do
|
15
|
+
route_to('/foo', :method => :post).should have_route(:controller => 'foo', :action => 'create', :id => nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match a put to /foo to the blogposts controller and update action" do
|
19
|
+
route_to('/foo', :method => :put).should have_route(:controller => 'foo', :action => 'update', :id => nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should match a delete to /foo to the blogposts controller and show action" do
|
23
|
+
route_to('/foo', :method => :delete).should have_route(:controller => 'foo', :action => 'destroy', :id => nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should match a get to /foo/new to the blogposts controller and new action" do
|
27
|
+
route_to('/foo/new', :method => :get).should have_route(:controller => 'foo', :action => 'new', :id => nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should match a get to /foo/edit to the blogposts controller and edit action" do
|
31
|
+
route_to('/foo/edit', :method => :get).should have_route(:controller => 'foo', :action => 'edit', :id => nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should match a get to /foo;edit to the blogposts controller and edit action" do
|
35
|
+
route_to('/foo;edit', :method => :get).should have_route(:controller => 'foo', :action => 'edit', :id => nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should match a get to /foo/delete to the blogposts controller and delete action" do
|
39
|
+
route_to('/foo/delete', :method => :get).should have_route(:controller => 'foo', :action => 'delete', :id => nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should match a get to /foo;delete to the blogposts controller and delete action" do
|
43
|
+
route_to('/foo;delete', :method => :get).should have_route(:controller => 'foo', :action => 'delete', :id => nil)
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "resources routes" do
|
4
|
+
before :each do
|
5
|
+
Merb::Router.prepare do |r|
|
6
|
+
r.resources :blogposts
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should match a get to /blogposts to the blogposts controller and index action" do
|
11
|
+
route_to('/blogposts', :method => :get).should have_route(:controller => 'blogposts', :action => 'index', :id => nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match a post to /blogposts to the blogposts controller and create action" do
|
15
|
+
route_to('/blogposts', :method => :post).should have_route(:controller => 'blogposts', :action => 'create', :id => nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should match a get to /blogposts/new to the blogposts controller and the new action" do
|
19
|
+
route_to('/blogposts/new', :method => :get).should have_route(:controller => 'blogposts', :action => 'new', :id => nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should match a get to /blogposts/1 ot the blogposts controller and the show action with id 1" do
|
23
|
+
route_to('/blogposts/1', :method => :get).should have_route(:controller => 'blogposts', :action => 'show', :id => "1")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should match a put to /blogposts/1 ot the blogposts controller and the update action with id 1" do
|
27
|
+
route_to('/blogposts/1', :method => :put).should have_route(:controller => 'blogposts', :action => 'update', :id => "1")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should match a delete to /blogposts/1 ot the blogposts controller and the destroy action with id 1" do
|
31
|
+
route_to('/blogposts/1', :method => :delete).should have_route(:controller => 'blogposts', :action => 'destroy', :id => "1")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should match a get to /blogposts/1/edit to the blogposts controller and the edit action with id 1" do
|
35
|
+
route_to('/blogposts/1/edit', :method => :get).should have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should match a get to /blogposts/1;edit to the blogposts controller and the edit action with id 1" do
|
39
|
+
route_to('/blogposts/1;edit', :method => :get).should have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not match a put to /blogposts/1/edit" do
|
43
|
+
# not sure which of these is the best way to specify what I mean - so they're both in...
|
44
|
+
route_to('/blogposts/1/edit', :method => :put).should have_nil_route
|
45
|
+
route_to('/blogposts/1/edit', :method => :put).should_not have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not match a put to /blogposts/1;edit" do
|
49
|
+
# not sure which of these is the best way to specify what I mean - so they're both in...
|
50
|
+
route_to('/blogposts/1;edit', :method => :put).should have_nil_route
|
51
|
+
route_to('/blogposts/1;edit', :method => :put).should_not have_route(:controller => 'blogposts', :action => 'edit', :id => "1")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should match a get to /blogposts/1/delete to the blogposts controller and the delete action with id 1" do
|
55
|
+
route_to('/blogposts/1/delete', :method => :get).should have_route(:controller => 'blogposts', :action => 'delete', :id => "1")
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
require 'ostruct'
|
3
|
+
class SimpleRequest < OpenStruct
|
4
|
+
|
5
|
+
def method
|
6
|
+
@table[:method]
|
7
|
+
end
|
8
|
+
|
9
|
+
def params
|
10
|
+
@table
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def prepare_route(from, to)
|
15
|
+
Merb::Router.prepare {|r| r.match(from).to(to)}
|
16
|
+
end
|
17
|
+
|
18
|
+
def route_to(path, args = {}, protocol = "http://")
|
19
|
+
Merb::Router.match(SimpleRequest.new({:protocol => protocol, :path => path}.merge(args)))[1]
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate(*args)
|
23
|
+
Merb::Router.generate *args
|
24
|
+
end
|
25
|
+
|
26
|
+
module Merb
|
27
|
+
|
28
|
+
module Test
|
29
|
+
|
30
|
+
module RspecMatchers
|
31
|
+
|
32
|
+
class HaveRoute
|
33
|
+
|
34
|
+
def self.build(expected)
|
35
|
+
this = new
|
36
|
+
this.instance_variable_set("@expected", expected)
|
37
|
+
this
|
38
|
+
end
|
39
|
+
|
40
|
+
def matches?(target)
|
41
|
+
@target = target
|
42
|
+
@errors = []
|
43
|
+
@expected.all? { |param, value| @target[param] == value }
|
44
|
+
end
|
45
|
+
|
46
|
+
def failure_message
|
47
|
+
@target.each do |param, value|
|
48
|
+
@errors << "Expected :#{param} to be #{@expected[param].inspect}, but was #{value.inspect}" unless
|
49
|
+
@expected[param] == value
|
50
|
+
end
|
51
|
+
@errors << "Got #{@target.inspect}"
|
52
|
+
@errors.join("\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
def negative_failure_message
|
56
|
+
"Expected #{@expected.inspect} not to be #{@target.inspect}, but it was."
|
57
|
+
end
|
58
|
+
|
59
|
+
def description() "have_route #{@target.inspect}" end
|
60
|
+
end
|
61
|
+
|
62
|
+
def have_route(expected)
|
63
|
+
HaveRoute.build(expected)
|
64
|
+
end
|
65
|
+
|
66
|
+
def have_nil_route
|
67
|
+
have_route({})
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "Regex-based routes" do
|
4
|
+
|
5
|
+
it "should process a simple regex" do
|
6
|
+
prepare_route(%r[^/foos?/(bar|baz)/:id], :controller => "foo", :action => "[1]", :id => ":id")
|
7
|
+
route_to("/foo/bar/baz").should have_route(:controller => "foo", :action => "bar", :id => "baz")
|
8
|
+
route_to("/foos/baz/bam").should have_route(:controller => "foo", :action => "baz", :id => "bam")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should support inbound user agents" do
|
12
|
+
Merb::Router.prepare do |r|
|
13
|
+
r.match(%r[^/foo/(.+)], :user_agent => /(MSIE|Gecko)/).
|
14
|
+
to(:controller => "foo", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
|
15
|
+
end
|
16
|
+
route_to("/foo/bar", :user_agent => /MSIE/).should have_route(
|
17
|
+
:controller => "foo", :action => "show", :title => "bar", :agent => "MSIE"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Routes that are restricted based on incoming params" do
|
24
|
+
|
25
|
+
it "should allow you to restrict routes to POST requests" do
|
26
|
+
Merb::Router.prepare do |r|
|
27
|
+
r.match("/:controller/create/:id").
|
28
|
+
to(:action => "create")
|
29
|
+
end
|
30
|
+
route_to("/foo/create/12", :method => "post").should have_route(
|
31
|
+
:controller => "foo", :action => "create", :id => "12"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow you to restrict routes based on protocol" do
|
36
|
+
Merb::Router.prepare do |r|
|
37
|
+
r.match(:protocol => "http://").to(:controller => "foo", :action => "bar")
|
38
|
+
r.default_routes
|
39
|
+
end
|
40
|
+
route_to("/foo/bar").should have_route(:controller => "foo", :action => "bar")
|
41
|
+
route_to("/boo/hoo", :protocol => "https://").should have_route(:controller => "boo", :action => "hoo")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe "A plain route with no variables" do
|
4
|
+
|
5
|
+
it "should return the parameters passed to #to" do
|
6
|
+
prepare_route("/info", :controller => "info", :action => "foo")
|
7
|
+
route_to("/info").should have_route(:controller => "info", :action => "foo", :id => nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "A route with variables specified as :foo/:bar" do
|
13
|
+
|
14
|
+
it "should work with :controller/:action/:id" do
|
15
|
+
prepare_route("/foo/:action/:id", :controller => "foobar")
|
16
|
+
route_to("/foo/bar/baz").should have_route(:controller => "foobar", :action => "bar", :id => "baz")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should work with :foo/:bar/:baz to :controller => ':foo/:bar'" do
|
20
|
+
prepare_route("/:foo/:bar/:baz/:id", :controller => ":foo/:bar", :action => ":baz")
|
21
|
+
route_to("/one/two/three/4").should have_route(:controller => "one/two", :action => "three", :id => "4")
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "A route containing block matchers" do
|
27
|
+
|
28
|
+
it "should support block matchers as a path namespace" do
|
29
|
+
Merb::Router.prepare do |r|
|
30
|
+
r.match("/foo") do |path|
|
31
|
+
path.match("/bar/:id").to(:controller => "foo/bar", :action => "bar")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
route_to("/foo/bar/1").should have_route(:controller => "foo/bar", :action => "bar", :id => "1")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should still support :variables in the to route from any level" do
|
38
|
+
Merb::Router.prepare do |r|
|
39
|
+
r.match("/foo/:bar") do |path|
|
40
|
+
path.match("/:baz/:id").to(:controller => "foo", :action => ":id", :id => ":bar/:baz")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
route_to("/foo/hello/goodbye/zoo").should have_route(:controller => "foo", :action => "zoo", :id => "hello/goodbye")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "A route containing block matchers for the 'to' section" do
|
49
|
+
|
50
|
+
it "should point a bunch of 'from' segments to the same 'to'" do
|
51
|
+
Merb::Router.prepare do |r|
|
52
|
+
r.to(:controller => "foo") do |a|
|
53
|
+
a.match("/hello/:action/:id").to(:tag => ":id")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
route_to("/hello/goodbye/tagging").should have_route(
|
57
|
+
:controller => "foo", :action => "goodbye", :id => "tagging", :tag => "tagging"
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|