merb-core 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +136 -2
- data/CONTRIBUTORS +6 -0
- data/PUBLIC_CHANGELOG +38 -0
- data/Rakefile +38 -30
- data/lib/merb-core.rb +88 -23
- data/lib/merb-core/bootloader.rb +235 -51
- data/lib/merb-core/config.rb +121 -36
- data/lib/merb-core/controller/abstract_controller.rb +59 -36
- data/lib/merb-core/controller/exceptions.rb +2 -15
- data/lib/merb-core/controller/merb_controller.rb +44 -1
- data/lib/merb-core/controller/mime.rb +4 -0
- data/lib/merb-core/controller/mixins/controller.rb +38 -21
- data/lib/merb-core/controller/mixins/render.rb +44 -29
- data/lib/merb-core/controller/mixins/responder.rb +3 -31
- data/lib/merb-core/controller/template.rb +45 -21
- data/lib/merb-core/core_ext/kernel.rb +60 -32
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +2 -2
- data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +3 -1
- data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +71 -67
- data/lib/merb-core/dispatch/default_exception/views/index.html.erb +7 -3
- data/lib/merb-core/dispatch/dispatcher.rb +3 -3
- data/lib/merb-core/dispatch/request.rb +56 -9
- data/lib/merb-core/dispatch/router.rb +159 -133
- data/lib/merb-core/dispatch/router/behavior.rb +462 -703
- data/lib/merb-core/dispatch/router/cached_proc.rb +3 -3
- data/lib/merb-core/dispatch/router/resources.rb +289 -0
- data/lib/merb-core/dispatch/router/route.rb +514 -294
- data/lib/merb-core/dispatch/session.rb +4 -2
- data/lib/merb-core/logger.rb +213 -202
- data/lib/merb-core/plugins.rb +9 -1
- data/lib/merb-core/rack.rb +3 -1
- data/lib/merb-core/rack/adapter.rb +7 -4
- data/lib/merb-core/rack/adapter/abstract.rb +188 -0
- data/lib/merb-core/rack/adapter/ebb.rb +12 -13
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -15
- data/lib/merb-core/rack/adapter/irb.rb +3 -2
- data/lib/merb-core/rack/adapter/mongrel.rb +22 -15
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +4 -16
- data/lib/merb-core/rack/adapter/thin.rb +21 -22
- data/lib/merb-core/rack/adapter/thin_turbo.rb +4 -11
- data/lib/merb-core/rack/adapter/webrick.rb +54 -18
- data/lib/merb-core/rack/application.rb +4 -4
- data/lib/merb-core/rack/handler/mongrel.rb +12 -13
- data/lib/merb-core/rack/middleware/csrf.rb +1 -1
- data/lib/merb-core/rack/stream_wrapper.rb +41 -0
- data/lib/merb-core/server.rb +157 -90
- data/lib/merb-core/tasks/gem_management.rb +267 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +48 -34
- data/lib/merb-core/tasks/stats.rake +1 -1
- data/lib/merb-core/test.rb +9 -3
- data/lib/merb-core/test/helpers.rb +1 -0
- data/lib/merb-core/test/helpers/mock_request_helper.rb +393 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -2
- data/lib/merb-core/test/helpers/request_helper.rb +40 -372
- data/lib/merb-core/test/helpers/route_helper.rb +16 -2
- data/lib/merb-core/test/matchers.rb +1 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +4 -247
- data/lib/merb-core/test/matchers/request_matchers.rb +140 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +22 -4
- data/lib/merb-core/test/run_specs.rb +118 -26
- data/lib/merb-core/test/test_ext/rspec.rb +181 -0
- data/lib/merb-core/version.rb +1 -9
- metadata +10 -342
- data/docs/bootloading.dox +0 -58
- data/docs/documentation_standards +0 -40
- 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 +0 -51
- data/lib/merb-core/vendor/facets.rb +0 -2
- data/lib/merb-core/vendor/facets/dictionary.rb +0 -433
- data/lib/merb-core/vendor/facets/inflect.rb +0 -342
- data/spec/private/config/adapter_spec.rb +0 -32
- data/spec/private/config/config_spec.rb +0 -202
- data/spec/private/config/environment_spec.rb +0 -13
- data/spec/private/config/merb_spec.rb +0 -34
- data/spec/private/config/spec_helper.rb +0 -1
- data/spec/private/core_ext/kernel_spec.rb +0 -159
- data/spec/private/dispatch/bootloader_spec.rb +0 -24
- data/spec/private/dispatch/fixture/app/controllers/application.rb +0 -4
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -25
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -19
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +0 -8
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +0 -37
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +0 -40
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +0 -11
- data/spec/private/dispatch/fixture/config/black_hole.rb +0 -12
- data/spec/private/dispatch/fixture/config/environments/development.rb +0 -6
- data/spec/private/dispatch/fixture/config/environments/production.rb +0 -5
- data/spec/private/dispatch/fixture/config/environments/test.rb +0 -6
- data/spec/private/dispatch/fixture/config/init.rb +0 -45
- data/spec/private/dispatch/fixture/config/rack.rb +0 -11
- data/spec/private/dispatch/fixture/config/router.rb +0 -35
- data/spec/private/dispatch/fixture/log/merb_test.log +0 -8839
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +0 -4
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +0 -119
- data/spec/private/dispatch/route_params_spec.rb +0 -23
- data/spec/private/dispatch/spec_helper.rb +0 -1
- data/spec/private/router/behavior_spec.rb +0 -60
- data/spec/private/router/fixture/log/merb_test.log +0 -35
- data/spec/private/router/route_spec.rb +0 -418
- data/spec/private/router/router_spec.rb +0 -183
- data/spec/private/vendor/facets/plural_spec.rb +0 -564
- data/spec/private/vendor/facets/singular_spec.rb +0 -489
- data/spec/public/DEFINITIONS +0 -11
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/cousins.rb +0 -41
- data/spec/public/abstract_controller/controllers/display.rb +0 -60
- data/spec/public/abstract_controller/controllers/filters.rb +0 -260
- data/spec/public/abstract_controller/controllers/helpers.rb +0 -41
- data/spec/public/abstract_controller/controllers/partial.rb +0 -121
- data/spec/public/abstract_controller/controllers/render.rb +0 -113
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +0 -1
- 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 +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +0 -1
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +0 -1
- data/spec/public/abstract_controller/display_spec.rb +0 -37
- data/spec/public/abstract_controller/filter_spec.rb +0 -136
- data/spec/public/abstract_controller/helper_spec.rb +0 -21
- data/spec/public/abstract_controller/partial_spec.rb +0 -61
- data/spec/public/abstract_controller/render_spec.rb +0 -90
- data/spec/public/abstract_controller/spec_helper.rb +0 -31
- data/spec/public/boot_loader/boot_loader_spec.rb +0 -33
- data/spec/public/boot_loader/spec_helper.rb +0 -1
- data/spec/public/controller/authentication_spec.rb +0 -174
- data/spec/public/controller/base_spec.rb +0 -88
- data/spec/public/controller/conditional_get_spec.rb +0 -100
- data/spec/public/controller/config/init.rb +0 -6
- data/spec/public/controller/controllers/authentication.rb +0 -74
- data/spec/public/controller/controllers/base.rb +0 -65
- data/spec/public/controller/controllers/conditional_get.rb +0 -35
- data/spec/public/controller/controllers/cookies.rb +0 -36
- data/spec/public/controller/controllers/dispatcher.rb +0 -35
- data/spec/public/controller/controllers/display.rb +0 -118
- data/spec/public/controller/controllers/redirect.rb +0 -36
- data/spec/public/controller/controllers/responder.rb +0 -93
- data/spec/public/controller/controllers/url.rb +0 -7
- data/spec/public/controller/controllers/views/layout/custom.html.erb +0 -1
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +0 -1
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +0 -1
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +0 -1
- data/spec/public/controller/cookies_spec.rb +0 -95
- data/spec/public/controller/dispatcher_spec.rb +0 -410
- data/spec/public/controller/display_spec.rb +0 -84
- data/spec/public/controller/redirect_spec.rb +0 -33
- data/spec/public/controller/responder_spec.rb +0 -169
- data/spec/public/controller/spec_helper.rb +0 -13
- data/spec/public/controller/url_spec.rb +0 -255
- data/spec/public/core/merb_core_spec.rb +0 -45
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +0 -2
- data/spec/public/core_ext/kernel_spec.rb +0 -88
- data/spec/public/core_ext/spec_helper.rb +0 -1
- data/spec/public/directory_structure/directory/app/controllers/application.rb +0 -3
- data/spec/public/directory_structure/directory/app/controllers/base.rb +0 -13
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +0 -19
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +0 -1
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +0 -1
- data/spec/public/directory_structure/directory/config/router.rb +0 -3
- data/spec/public/directory_structure/directory/log/merb_test.log +0 -4588
- data/spec/public/directory_structure/directory_spec.rb +0 -43
- data/spec/public/logger/logger_spec.rb +0 -181
- data/spec/public/logger/spec_helper.rb +0 -1
- data/spec/public/rack/conditinal_get_middleware_spec.rb +0 -127
- data/spec/public/rack/csrf_middleware_spec.rb +0 -70
- data/spec/public/rack/rack_middleware_spec.rb +0 -99
- data/spec/public/rack/shared_example_groups.rb +0 -35
- data/spec/public/reloading/directory/app/controllers/application.rb +0 -3
- data/spec/public/reloading/directory/app/controllers/reload.rb +0 -6
- data/spec/public/reloading/directory/config/init.rb +0 -2
- data/spec/public/reloading/directory/log/merb_test.log +0 -288231
- data/spec/public/reloading/reload_spec.rb +0 -103
- data/spec/public/request/multipart_spec.rb +0 -41
- data/spec/public/request/request_spec.rb +0 -250
- data/spec/public/router/default_spec.rb +0 -21
- data/spec/public/router/deferred_spec.rb +0 -22
- data/spec/public/router/fixation_spec.rb +0 -49
- data/spec/public/router/fixture/log/merb_test.log +0 -524
- data/spec/public/router/namespace_spec.rb +0 -113
- data/spec/public/router/nested_matches_spec.rb +0 -97
- data/spec/public/router/nested_resources_spec.rb +0 -41
- data/spec/public/router/resource_spec.rb +0 -37
- data/spec/public/router/resources_spec.rb +0 -82
- data/spec/public/router/spec_helper.rb +0 -90
- data/spec/public/router/special_spec.rb +0 -61
- data/spec/public/router/string_spec.rb +0 -61
- data/spec/public/session/controllers/sessions.rb +0 -56
- data/spec/public/session/cookie_session_spec.rb +0 -73
- data/spec/public/session/memcached_session_spec.rb +0 -31
- data/spec/public/session/memory_session_spec.rb +0 -28
- data/spec/public/session/multiple_sessions_spec.rb +0 -74
- data/spec/public/session/no_session_spec.rb +0 -12
- data/spec/public/session/session_spec.rb +0 -106
- data/spec/public/template/template_spec.rb +0 -104
- data/spec/public/template/templates/error.html.erb +0 -2
- data/spec/public/template/templates/template.html.erb +0 -1
- data/spec/public/template/templates/template.html.myt +0 -1
- data/spec/public/test/controller_matchers_spec.rb +0 -412
- data/spec/public/test/controllers/controller_assertion_mock.rb +0 -7
- data/spec/public/test/controllers/dispatch_controller.rb +0 -11
- data/spec/public/test/controllers/spec_helper_controller.rb +0 -39
- data/spec/public/test/multipart_request_helper_spec.rb +0 -159
- data/spec/public/test/multipart_upload_text_file.txt +0 -1
- data/spec/public/test/request_helper_spec.rb +0 -269
- data/spec/public/test/route_helper_spec.rb +0 -78
- data/spec/public/test/route_matchers_spec.rb +0 -166
- data/spec/public/test/view_helper_spec.rb +0 -96
- data/spec/public/test/view_matchers_spec.rb +0 -183
- data/spec/spec_helper.rb +0 -121
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Merb::Controller, " displaying objects based on mime type" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Merb::Router.prepare do |r|
|
7
|
-
r.default_routes
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should default the mime-type to HTML (and raise since there's no to_html)" do
|
12
|
-
running { dispatch_to(Merb::Test::Fixtures::Controllers::DisplayHtmlDefault, :index) }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set headers['Location'] to string provided by :location" do
|
16
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithStringLocation, :index, {}, :http_accept => "application/json").headers['Location'].should =~ /some_resources/
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should set the status to a code provided by :status" do
|
20
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithStatus, :index, {}, :http_accept => "application/json").status.should == 500
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should use a template if specified" do
|
24
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :index).body.should match(/Custom: Template/)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "overrides layout settings with render :layout => false" do
|
28
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :no_layout).body.should_not match(/Custom: Template/)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should accept an absolute template path argument - with the mimetype extension" do
|
32
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :absolute_with_mime).body.should == "Custom: HTML: Default"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should accept an absolute template path argument - without the mimetype extension" do
|
36
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :absolute_without_mime).body.should == "Custom: HTML: Default"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should accept a relative template path argument - with the mimetype extension" do
|
40
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :relative_with_mime).body.should == "Custom: HTML: Default"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should accept a relative template path argument - without the mimetype extension" do
|
44
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :relative_without_mime).body.should == "Custom: HTML: Default"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should accept a layout argument when calling to_*" do
|
48
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithLayout, :index, {},
|
49
|
-
:http_accept => "application/json").body.should == "{custom_arg: { 'include': '', 'exclude': '' }}"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should accept a layout argument with a template" do
|
53
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplateArgument, :index).body.should == "Custom Arg: Template"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should accept a template path argument" do
|
57
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplateArgument, :index_by_arg).body.should == "Template"
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should use other mime-types if they are provided on the class level" do
|
61
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayClassProvides, :index, {}, :http_accept => "application/xml")
|
62
|
-
controller.body.should == "<XML:Model />"
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should fail if none of the acceptable mime-types are available" do
|
66
|
-
calling { dispatch_to(Merb::Test::Fixtures::Controllers::DisplayClassProvides, :index, {}, :http_accept => "application/json") }.
|
67
|
-
should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should use mime-types that are provided at the local level" do
|
71
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayLocalProvides, :index, {}, :http_accept => "application/xml")
|
72
|
-
controller.body.should == "<XML:Model />"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "passes all options to serialization method like :to_json" do
|
76
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithSerializationOptions, :index, {}, :http_accept => "application/json")
|
77
|
-
controller.body.should == "{ 'include': 'beer, jazz', 'exclude': 'idiots' }"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "passes single argument to serialization method like :to_json" do
|
81
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithSerializationOptions, :index_that_passes_empty_hash, {}, :http_accept => "application/json")
|
82
|
-
controller.body.should == "{ 'include': '', 'exclude': '' }"
|
83
|
-
end
|
84
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Merb::Controller, " redirects" do
|
4
|
-
it "redirects with simple URLs" do
|
5
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::SimpleRedirect, :index)
|
6
|
-
@controller.status.should == 302
|
7
|
-
@controller.headers["Location"].should == "/"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "permanently redirects" do
|
11
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::PermanentRedirect, :index)
|
12
|
-
@controller.status.should == 301
|
13
|
-
@controller.headers["Location"].should == "/"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "redirects with messages" do
|
17
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::RedirectWithMessage, :index)
|
18
|
-
@controller.status.should == 302
|
19
|
-
expected_url = Merb::Request.escape([Marshal.dump(:notice => "what?")].pack("m"))
|
20
|
-
@controller.headers["Location"].should == "/?_message=#{expected_url}"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "consumes redirects with messages" do
|
24
|
-
message = Merb::Request.escape([Marshal.dump(:notice => "what?")].pack("m"))
|
25
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::ConsumesMessage, :index, {:_message => message})
|
26
|
-
@controller.body.should == "\"what?\""
|
27
|
-
end
|
28
|
-
|
29
|
-
it "supports setting the message for use immediately" do
|
30
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::SetsMessage, :index)
|
31
|
-
@controller.body.should == "Hello"
|
32
|
-
end
|
33
|
-
end
|
@@ -1,169 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
|
3
|
-
describe Merb::Controller, " responds" do
|
4
|
-
|
5
|
-
before do
|
6
|
-
Merb.push_path(:layout, File.dirname(__FILE__) / "controllers" / "views" / "layouts")
|
7
|
-
Merb::Router.prepare do |r|
|
8
|
-
r.default_routes
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should default the mime-type to HTML" do
|
13
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::HtmlDefault, :index).body.should == "HTML: Default"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should use other mime-types if they are provided on the controller-level" do
|
17
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, {}, :http_accept => "application/xml")
|
18
|
-
controller.body.should == "<XML:Class provides='true' />"
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should fail if none of the acceptable mime-types are available" do
|
22
|
-
calling { dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, {}, :http_accept => "application/json") }.
|
23
|
-
should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should use mime-types that are provided at the action-level" do
|
27
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::LocalProvides, :index, {}, :http_accept => "application/xml")
|
28
|
-
controller.body.should == "<XML:Local provides='true' />"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should use mime-types that are provided at the controller-level as well as the action-level (controller)" do
|
32
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, {}, :http_accept => "text/html")
|
33
|
-
controller.class_provided_formats.should == [:html]
|
34
|
-
controller._provided_formats.should == [:html, :xml]
|
35
|
-
controller.body.should == "HTML: Class and Local"
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should use mime-types that are provided at the controller-level as well as the action-level (action)" do
|
39
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, {}, :http_accept => "application/xml")
|
40
|
-
controller.class_provided_formats.should == [:html]
|
41
|
-
controller._provided_formats.should == [:html, :xml]
|
42
|
-
controller.body.should == "<XML:ClassAndLocalProvides provides='true' />"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should use the first mime-type when accepting anything */*" do
|
46
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "*/*")
|
47
|
-
controller.body.should == "HTML: Multi"
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should pick application/xhtml+xml when both application/xml and application/xhtml+xml are available" do
|
51
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides,
|
52
|
-
:index, {}, :http_accept => "application/xml,application/xhtml+xml")
|
53
|
-
controller.body.should == "HTML: Wins Over XML If Both Are Specified"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should use the first mime-type when accepting anything */*, even if something unprovidable comes first" do
|
57
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::HtmlDefault, :index, {}, :http_accept => "application/json, */*")
|
58
|
-
controller.body.should == "HTML: Default"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should use the pick the first mime-type from the list not the */*" do
|
62
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "text/javascript, */*")
|
63
|
-
controller.body.should == "JS: Multi"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should pick the first mime-type if no specific supported content-type matches are *available*" do
|
67
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*")
|
68
|
-
controller.body.should == "HTML: Multi"
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should pick the first mime-type if no specific supported content-type matches are actually *provided*" do
|
72
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::MultiProvides, :index, {}, :http_accept => "application/json, */*")
|
73
|
-
controller.body.should == "HTML: Multi"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should select the format based on params supplied to it with controller-level provides" do
|
77
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, :format => "xml")
|
78
|
-
controller.content_type.should == :xml
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should select the format based on params supplied to it with action-level provides" do
|
82
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::LocalProvides, :index, :format => "xml")
|
83
|
-
controller.content_type.should == :xml
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should select the format based on params supplied to it with controller and action provides (controller)" do
|
87
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, :format => "html")
|
88
|
-
controller.content_type.should == :html
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should select the format based on params supplied to it with controller and action provides (action)" do
|
92
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassAndLocalProvides, :index, :format => "xml")
|
93
|
-
controller.content_type.should == :xml
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should properly add formats when only_provides is called in action" do
|
97
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "application/xml")
|
98
|
-
controller._provided_formats.should == [:text, :xml]
|
99
|
-
controller.content_type.should == :xml
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should properly remove formats when only_provides is called in action" do
|
103
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::OnlyProvides, :index, {}, :http_accept => "text/html")
|
104
|
-
lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should properly add formats when only_provides is called in controller" do
|
108
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "application/xml")
|
109
|
-
controller._provided_formats.should == [:text, :xml]
|
110
|
-
controller.content_type.should == :xml
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should properly remove formats when only_provides is called in controller" do
|
114
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassOnlyProvides, :index, {}, :http_accept => "text/html")
|
115
|
-
lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should properly remove formats when does_not_provide is called in controller" do
|
119
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassDoesntProvides, :index, {}, :http_accept => "text/html")
|
120
|
-
controller._provided_formats.should == [:xml]
|
121
|
-
lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should properly remove formats when does_not_provide is called in action" do
|
125
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DoesntProvide, :index, {}, :http_accept => "text/html")
|
126
|
-
controller._provided_formats.should == [:xml]
|
127
|
-
lambda { controller.content_type }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should return the correct default HTTP headers for a format" do
|
131
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::ClassProvides, :index, :format => "xml")
|
132
|
-
controller.headers.keys.sort.should == ["Content-Type"]
|
133
|
-
controller.headers["Content-Type"].should == "application/xml; charset=utf-8"
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should append the correct charset which was set when the format was added" do
|
137
|
-
Merb.add_mime_type(:foo, nil, %w[application/foo], :charset => "iso-8859-1")
|
138
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::FooFormatProvides, :index, :format => "foo")
|
139
|
-
controller.headers["Content-Type"].should == "application/foo; charset=iso-8859-1"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should return the correct HTTP headers which were set when the format was added" do
|
143
|
-
Merb.add_mime_type(:foo, nil, %w[application/foo], "Foo" => 'bar', "Content-Language" => "en", :charset => "utf-8")
|
144
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::FooFormatProvides, :index, :format => "foo")
|
145
|
-
controller.headers.keys.should_not include(:charset)
|
146
|
-
controller.headers["Content-Type"].should == "application/foo; charset=utf-8"
|
147
|
-
controller.headers["Content-Language"].should == "en"
|
148
|
-
controller.headers["Foo"] = "bar"
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should return the correct HTTP headers using the block given when the format was added" do
|
152
|
-
Merb.add_mime_type(:foo, nil, %w[application/foo], "Foo" => "bar") do |controller|
|
153
|
-
controller.headers["Action-Name"] = controller.action_name
|
154
|
-
end
|
155
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::FooFormatProvides, :index, :format => "foo")
|
156
|
-
controller.headers["Content-Type"].should == "application/foo"
|
157
|
-
controller.headers["Action-Name"].should == "index"
|
158
|
-
controller.headers["Foo"] = "bar"
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should not overwrite runtime-set headers with default format response headers" do
|
162
|
-
Merb.add_mime_type(:foo, nil, %w[application/foo], "Foo" => "bar", "Content-Language" => "en")
|
163
|
-
controller = dispatch_to(Merb::Test::Fixtures::Controllers::FooFormatProvides, :show, :format => "foo")
|
164
|
-
controller.headers["Content-Language"].should == "nl"
|
165
|
-
controller.headers["Biz"] = "buzz"
|
166
|
-
controller.headers["Foo"] = "bar"
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
__DIR__ = File.dirname(__FILE__)
|
2
|
-
|
3
|
-
require File.join(__DIR__, "..", "..", "spec_helper")
|
4
|
-
|
5
|
-
require File.join(__DIR__, "controllers", "base")
|
6
|
-
require File.join(__DIR__, "controllers", "responder")
|
7
|
-
require File.join(__DIR__, "controllers", "display")
|
8
|
-
require File.join(__DIR__, "controllers", "authentication")
|
9
|
-
require File.join(__DIR__, "controllers", "redirect")
|
10
|
-
require File.join(__DIR__, "controllers", "cookies")
|
11
|
-
require File.join(__DIR__, "controllers", "conditional_get")
|
12
|
-
|
13
|
-
Merb.start :environment => 'test', :init_file => File.join(__DIR__, 'config', 'init')
|
@@ -1,255 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
-
require File.join(File.dirname(__FILE__), "controllers", "url")
|
3
|
-
|
4
|
-
class Monkey ; def to_param ; 45 ; end ; end
|
5
|
-
class Donkey ; def to_param ; 19 ; end ; end
|
6
|
-
class Blue
|
7
|
-
def to_param ; 13 ; end
|
8
|
-
def monkey_id ; Monkey.new ; end
|
9
|
-
def donkey_id ; Donkey.new ; end
|
10
|
-
end
|
11
|
-
class Pink
|
12
|
-
def to_param ; 22 ; end
|
13
|
-
def blue_id ; Blue.new ; end
|
14
|
-
def monkey_id ; blue_id.monkey_id ; end
|
15
|
-
end
|
16
|
-
|
17
|
-
Merb::Router.prepare do |r|
|
18
|
-
r.default_routes
|
19
|
-
r.resources :monkeys do |m|
|
20
|
-
m.resources :blues do |b|
|
21
|
-
b.resources :pinks
|
22
|
-
end
|
23
|
-
end
|
24
|
-
r.resources :donkeys do |d|
|
25
|
-
d.resources :blues
|
26
|
-
end
|
27
|
-
r.resource :red do |red|
|
28
|
-
red.resources :blues
|
29
|
-
end
|
30
|
-
r.match(%r{/foo/(\d+)/}).to(:controller => 'asdf').name(:regexp)
|
31
|
-
r.match('/people/:name').
|
32
|
-
to(:controller => 'people', :action => 'show').name(:person)
|
33
|
-
r.match('/argstrs').to(:controller => "args").name(:args)
|
34
|
-
end
|
35
|
-
|
36
|
-
describe Merb::Controller, " url" do
|
37
|
-
|
38
|
-
before do
|
39
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::Url, :index)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should match the :controller to the default route" do
|
43
|
-
@controller.url(:controller => "monkeys").should eql("/monkeys")
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should match the :controller,:action to the default route" do
|
47
|
-
@controller.url(:controller => "monkeys", :action => "list").
|
48
|
-
should eql("/monkeys/list")
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should match the :controller,:action,:id to the default route" do
|
52
|
-
@controller.url(:controller => "monkeys", :action => "list", :id => 4).
|
53
|
-
should eql("/monkeys/list/4")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should match the :controller,:action,:id,:format to the default route" do
|
57
|
-
@controller.url(:controller => "monkeys", :action => "list", :id => 4, :format => "xml").
|
58
|
-
should eql("/monkeys/list/4.xml")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should match the :controller,:action,:id,:format,:fragment to the default route" do
|
62
|
-
@controller.url(:controller => "monkeys", :action => "list", :id => 4, :format => "xml", :fragment => :half_way).
|
63
|
-
should eql("/monkeys/list/4.xml#half_way")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should raise an error" do
|
67
|
-
lambda { @controller.url(:regexp) }.should raise_error
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should match with a route param" do
|
71
|
-
@controller.url(:person, :name => "david").should eql("/people/david")
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should match without a route param" do
|
75
|
-
@controller.url(:person).should eql("/people/")
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should match with an additional param" do
|
79
|
-
@controller.url(:person, :name => 'david', :color => 'blue').should eql("/people/david?color=blue")
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should match with a :format" do
|
83
|
-
@controller.url(:person, :name => 'david', :format => :xml).should eql("/people/david.xml")
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should match with a :fragment" do
|
87
|
-
@controller.url(:person, :name => 'david', :fragment => :half_way).should eql("/people/david#half_way")
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should match with an additional param and :format" do
|
91
|
-
@controller.url(:person, :name => 'david', :color => 'blue', :format => :xml).should eql("/people/david.xml?color=blue")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should match with an additional param, :format, and :fragment" do
|
95
|
-
@controller.url(:person, :name => 'david', :color => 'blue', :format => :xml, :fragment => :half_way).
|
96
|
-
should eql("/people/david.xml?color=blue#half_way")
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should match with additional params" do
|
100
|
-
url = @controller.url(:person, :name => 'david', :smell => 'funky', :color => 'blue')
|
101
|
-
url.should match(%r{/people/david?.*color=blue})
|
102
|
-
url.should match(%r{/people/david?.*smell=funky})
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should match with extra params and an array" do
|
106
|
-
@controller.url(:args, :monkey => [1,2]).should == "/argstrs?monkey[]=1&monkey[]=2"
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should match with no second arg" do
|
110
|
-
@controller.url(:monkeys).should == "/monkeys"
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should match with an object as second arg" do
|
114
|
-
@monkey = Monkey.new
|
115
|
-
@controller.url(:monkey, @monkey).should == "/monkeys/45"
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should match with a fixnum as second arg" do
|
119
|
-
@controller.url(:monkey, 3).should == "/monkeys/3"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should match with an object and :format" do
|
123
|
-
@monkey = Monkey.new
|
124
|
-
@controller.url(:monkey, :id => @monkey, :format => :xml).should == "/monkeys/45.xml"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should match with an object, :format and additional options" do
|
128
|
-
@monkey = Monkey.new
|
129
|
-
@controller.url(:monkey, :id => @monkey, :format => :xml, :color => "blue").should == "/monkeys/45.xml?color=blue"
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should match with an object, :format, :fragment, and additional options" do
|
133
|
-
@monkey = Monkey.new
|
134
|
-
@controller.url(:monkey, :id => @monkey, :format => :xml, :color => "blue", :fragment => :half_way).should == "/monkeys/45.xml?color=blue#half_way"
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should match the delete_monkey route" do
|
138
|
-
@monkey = Monkey.new
|
139
|
-
@controller.url(:delete_monkey, @monkey).should == "/monkeys/45/delete"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should match the delete_red route" do
|
143
|
-
@controller.url(:delete_red).should == "/red/delete"
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should add a path_prefix to the url if :path_prefix is set" do
|
147
|
-
Merb::Config[:path_prefix] = "/jungle"
|
148
|
-
@controller.url(:monkeys).should == "/jungle/monkeys"
|
149
|
-
Merb::Config[:path_prefix] = nil
|
150
|
-
end
|
151
|
-
|
152
|
-
it "should match a nested resources show action" do
|
153
|
-
@blue = Blue.new
|
154
|
-
@controller.url(:monkey_blue, @blue).should == "/monkeys/45/blues/13"
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should match the index action of nested resource with parent object" do
|
158
|
-
@blue = Blue.new
|
159
|
-
@monkey = Monkey.new
|
160
|
-
@controller.url(:monkey_blues, :monkey_id => @monkey).should == "/monkeys/45/blues"
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should match the index action of nested resource with parent id as string" do
|
164
|
-
@blue = Blue.new
|
165
|
-
@controller.url(:monkey_blues, :monkey_id => '1').should == "/monkeys/1/blues"
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should match the edit action of nested resource" do
|
169
|
-
@blue = Blue.new
|
170
|
-
@controller.url(:edit_monkey_blue, @blue).should == "/monkeys/45/blues/13/edit"
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should match the index action of resources nested under a resource" do
|
174
|
-
@blue = Blue.new
|
175
|
-
@controller.url(:red_blues).should == "/red/blues"
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should match resource that has been nested multiple times" do
|
179
|
-
@blue = Blue.new
|
180
|
-
@controller.url(:donkey_blue, @blue).should == "/donkeys/19/blues/13"
|
181
|
-
@controller.url(:monkey_blue, @blue).should == "/monkeys/45/blues/13"
|
182
|
-
end
|
183
|
-
|
184
|
-
it "should match resources nested more than one level deep" do
|
185
|
-
@pink = Pink.new
|
186
|
-
@controller.url(:monkey_blue_pink, @pink).should == "/monkeys/45/blues/13/pinks/22"
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should match resource with additional params" do
|
190
|
-
@monkey = Monkey.new
|
191
|
-
@controller.url(:monkey, @monkey, :foo => "bar").should == "/monkeys/45?foo=bar"
|
192
|
-
end
|
193
|
-
it "should match resource with fragment" do
|
194
|
-
@monkey = Monkey.new
|
195
|
-
@controller.url(:monkey, @monkey, :fragment => :half_way).should == "/monkeys/45#half_way"
|
196
|
-
end
|
197
|
-
|
198
|
-
it "should match a nested resource with additional params" do
|
199
|
-
@blue = Blue.new
|
200
|
-
@controller.url(:monkey_blue, @blue, :foo => "bar").should == "/monkeys/45/blues/13?foo=bar"
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should match a nested resource with additional params and fragment" do
|
204
|
-
@blue = Blue.new
|
205
|
-
@controller.url(:monkey_blue, @blue, :foo => "bar", :fragment => :half_way).should == "/monkeys/45/blues/13?foo=bar#half_way"
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
describe Merb::Controller, "absolute_url" do
|
214
|
-
before do
|
215
|
-
@controller = dispatch_to(Merb::Test::Fixtures::Controllers::Url, :index)
|
216
|
-
end
|
217
|
-
|
218
|
-
it 'takes :protocol option' do
|
219
|
-
@monkey = Monkey.new
|
220
|
-
@controller.absolute_url(:monkey,
|
221
|
-
:id => @monkey,
|
222
|
-
:format => :xml,
|
223
|
-
:protocol => "https").should == "https://localhost/monkeys/45.xml"
|
224
|
-
end
|
225
|
-
|
226
|
-
it 'takes :host option' do
|
227
|
-
@monkey = Monkey.new
|
228
|
-
@controller.absolute_url(:monkey,
|
229
|
-
:id => @monkey,
|
230
|
-
:format => :xml,
|
231
|
-
:protocol => "https",
|
232
|
-
:host => "rubyisnotrails.org").should == "https://rubyisnotrails.org/monkeys/45.xml"
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'falls back to request protocol' do
|
236
|
-
@monkey = Monkey.new
|
237
|
-
@controller.absolute_url(:monkey,
|
238
|
-
:id => @monkey,
|
239
|
-
:format => :xml).should == "http://localhost/monkeys/45.xml"
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'falls back to request host' do
|
243
|
-
@monkey = Monkey.new
|
244
|
-
@controller.absolute_url(:monkey,
|
245
|
-
:id => @monkey,
|
246
|
-
:format => :xml,
|
247
|
-
:protocol => "https").should == "https://localhost/monkeys/45.xml"
|
248
|
-
end
|
249
|
-
|
250
|
-
it "allows passing an object instead of a hash" do
|
251
|
-
@monkey = Monkey.new
|
252
|
-
@controller.absolute_url(:monkey, @monkey).should == "http://localhost/monkeys/45"
|
253
|
-
end
|
254
|
-
|
255
|
-
end
|