merb-core 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README +3 -3
- data/Rakefile +144 -33
- data/bin/merb +0 -0
- data/bin/merb-specs +0 -0
- data/docs/bootloading.dox +1 -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/lib/merb-core.rb +159 -37
- data/lib/merb-core/autoload.rb +1 -0
- data/lib/merb-core/bootloader.rb +208 -92
- data/lib/merb-core/config.rb +20 -6
- data/lib/merb-core/controller/abstract_controller.rb +113 -61
- data/lib/merb-core/controller/exceptions.rb +28 -13
- data/lib/merb-core/controller/merb_controller.rb +73 -44
- data/lib/merb-core/controller/mime.rb +25 -7
- data/lib/merb-core/controller/mixins/authentication.rb +1 -1
- data/lib/merb-core/controller/mixins/controller.rb +44 -8
- data/lib/merb-core/controller/mixins/render.rb +191 -128
- data/lib/merb-core/controller/mixins/responder.rb +65 -63
- data/lib/merb-core/controller/template.rb +103 -54
- data/lib/merb-core/core_ext.rb +7 -12
- data/lib/merb-core/core_ext/kernel.rb +128 -136
- data/lib/merb-core/dispatch/cookies.rb +26 -4
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
- data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
- data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
- data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +156 -224
- data/lib/merb-core/dispatch/request.rb +126 -25
- data/lib/merb-core/dispatch/router.rb +61 -6
- data/lib/merb-core/dispatch/router/behavior.rb +122 -41
- data/lib/merb-core/dispatch/router/route.rb +147 -22
- data/lib/merb-core/dispatch/session.rb +52 -2
- data/lib/merb-core/dispatch/session/cookie.rb +4 -2
- data/lib/merb-core/dispatch/session/memcached.rb +38 -27
- data/lib/merb-core/dispatch/session/memory.rb +18 -11
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +58 -0
- data/lib/merb-core/logger.rb +3 -31
- data/lib/merb-core/plugins.rb +25 -3
- data/lib/merb-core/rack.rb +18 -12
- data/lib/merb-core/rack/adapter.rb +10 -8
- data/lib/merb-core/rack/adapter/ebb.rb +2 -2
- data/lib/merb-core/rack/adapter/irb.rb +31 -21
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +19 -9
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/application.rb +9 -84
- 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 +27 -9
- 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/tasks/stats.rake +71 -0
- data/lib/merb-core/test.rb +2 -1
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
- data/lib/merb-core/test/helpers/request_helper.rb +66 -24
- data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
- data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
- data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
- data/lib/merb-core/test/run_specs.rb +1 -0
- data/lib/merb-core/test/tasks/spectasks.rb +13 -5
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
- data/lib/merb-core/vendor/facets/inflect.rb +82 -37
- data/lib/merb-core/version.rb +2 -2
- data/spec/private/config/config_spec.rb +39 -4
- data/spec/private/core_ext/kernel_spec.rb +3 -14
- data/spec/private/dispatch/bootloader_spec.rb +1 -1
- data/spec/private/dispatch/cookies_spec.rb +181 -69
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
- data/spec/private/dispatch/fixture/config/rack.rb +10 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
- data/spec/private/dispatch/route_params_spec.rb +2 -3
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/plugins/plugin_spec.rb +73 -59
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +1693 -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/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
- data/spec/public/abstract_controller/controllers/partial.rb +17 -2
- data/spec/public/abstract_controller/controllers/render.rb +16 -1
- 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/merb/test/fixtures/abstract/render_two_throw_contents/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/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/filter_spec.rb +20 -1
- data/spec/public/abstract_controller/helper_spec.rb +10 -2
- data/spec/public/abstract_controller/partial_spec.rb +8 -0
- data/spec/public/abstract_controller/render_spec.rb +8 -0
- data/spec/public/abstract_controller/spec_helper.rb +7 -3
- data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
- data/spec/public/controller/base_spec.rb +10 -2
- data/spec/public/controller/config/init.rb +6 -0
- data/spec/public/controller/controllers/authentication.rb +9 -11
- data/spec/public/controller/controllers/base.rb +2 -8
- data/spec/public/controller/controllers/cookies.rb +16 -0
- data/spec/public/controller/controllers/dispatcher.rb +35 -0
- data/spec/public/controller/controllers/display.rb +62 -14
- data/spec/public/controller/controllers/redirect.rb +36 -0
- data/spec/public/controller/controllers/responder.rb +37 -11
- 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/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/cookies_spec.rb +23 -0
- data/spec/public/controller/dispatcher_spec.rb +411 -0
- data/spec/public/controller/display_spec.rb +43 -10
- data/spec/public/controller/redirect_spec.rb +33 -0
- data/spec/public/controller/responder_spec.rb +79 -11
- data/spec/public/controller/spec_helper.rb +3 -1
- data/spec/public/controller/url_spec.rb +10 -0
- data/spec/public/core/merb_core_spec.rb +11 -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/log/merb_test.log +3729 -272
- data/spec/public/directory_structure/directory_spec.rb +3 -4
- data/spec/public/logger/logger_spec.rb +4 -4
- data/spec/public/reloading/directory/log/merb_test.log +288066 -15
- data/spec/public/reloading/reload_spec.rb +49 -27
- data/spec/public/request/multipart_spec.rb +26 -0
- data/spec/public/request/request_spec.rb +21 -2
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +30050 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/resource_spec.rb +1 -9
- data/spec/public/router/resources_spec.rb +0 -20
- data/spec/public/router/spec_helper.rb +27 -9
- data/spec/public/router/special_spec.rb +21 -8
- data/spec/public/template/template_spec.rb +17 -5
- data/spec/public/test/controller_matchers_spec.rb +10 -0
- data/spec/public/test/request_helper_spec.rb +29 -0
- data/spec/public/test/route_helper_spec.rb +18 -1
- data/spec/public/test/route_matchers_spec.rb +28 -1
- data/spec/public/test/view_matchers_spec.rb +3 -3
- data/spec/spec_helper.rb +56 -12
- metadata +89 -47
- data/lib/merb-core/core_ext/class.rb +0 -299
- data/lib/merb-core/core_ext/hash.rb +0 -426
- data/lib/merb-core/core_ext/mash.rb +0 -154
- data/lib/merb-core/core_ext/object.rb +0 -147
- data/lib/merb-core/core_ext/object_space.rb +0 -14
- data/lib/merb-core/core_ext/rubygems.rb +0 -28
- data/lib/merb-core/core_ext/set.rb +0 -46
- data/lib/merb-core/core_ext/string.rb +0 -89
- data/lib/merb-core/core_ext/time.rb +0 -13
- data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
- data/spec/private/core_ext/class_spec.rb +0 -22
- data/spec/private/core_ext/hash_spec.rb +0 -522
- data/spec/private/core_ext/object_spec.rb +0 -121
- data/spec/private/core_ext/set_spec.rb +0 -26
- data/spec/private/core_ext/string_spec.rb +0 -167
- data/spec/private/core_ext/time_spec.rb +0 -16
- data/spec/private/dispatch/dispatch_spec.rb +0 -26
- data/spec/private/dispatch/fixture/log/development.log +0 -1
- data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
- data/spec/private/dispatch/fixture/log/production.log +0 -1
- data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
- data/spec/private/rack/application_spec.rb +0 -43
- data/spec/public/controller/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Merb::Test::Fixtures::Controllers
|
4
|
-
|
5
2
|
class SomeModel
|
6
3
|
def to_xml; "<XML:Model />" end
|
7
4
|
def to_json(options = {})
|
@@ -9,18 +6,31 @@ module Merb::Test::Fixtures::Controllers
|
|
9
6
|
excludes = options[:except].first rescue ""
|
10
7
|
"{ 'include': '#{includes}', 'exclude': '#{excludes}' }"
|
11
8
|
end
|
9
|
+
def to_param
|
10
|
+
"1"
|
11
|
+
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
|
+
|
14
15
|
class Testing < Merb::Controller
|
15
16
|
self._template_root = File.dirname(__FILE__) / "views"
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
|
18
20
|
class Display < Testing
|
19
|
-
|
20
21
|
def index
|
21
22
|
@obj = SomeModel.new
|
22
23
|
display @obj
|
23
|
-
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class DisplayWithLayout < Testing
|
28
|
+
provides :json
|
29
|
+
|
30
|
+
def index
|
31
|
+
@obj = SomeModel.new
|
32
|
+
display @obj, :layout => :custom_arg
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
class DisplayHtmlDefault < Display; end
|
@@ -29,17 +39,39 @@ module Merb::Test::Fixtures::Controllers
|
|
29
39
|
provides :xml
|
30
40
|
end
|
31
41
|
|
42
|
+
|
32
43
|
class DisplayLocalProvides < Display
|
33
|
-
|
34
44
|
def index
|
35
45
|
@obj = SomeModel.new
|
36
46
|
provides :xml
|
37
47
|
display @obj
|
38
48
|
end
|
39
49
|
end
|
40
|
-
|
50
|
+
|
51
|
+
|
41
52
|
class DisplayWithTemplate < Display
|
42
53
|
layout :custom
|
54
|
+
|
55
|
+
def no_layout
|
56
|
+
render :layout => false
|
57
|
+
end
|
58
|
+
|
59
|
+
def absolute_without_mime
|
60
|
+
render :template => File.expand_path(self._template_root) / "merb/test/fixtures/controllers/html_default/index"
|
61
|
+
end
|
62
|
+
|
63
|
+
def absolute_with_mime
|
64
|
+
render :template => File.expand_path(self._template_root) / "merb/test/fixtures/controllers/html_default/index.html"
|
65
|
+
end
|
66
|
+
|
67
|
+
def relative_without_mime
|
68
|
+
render :template => "merb/test/fixtures/controllers/html_default/index"
|
69
|
+
end
|
70
|
+
|
71
|
+
def relative_with_mime
|
72
|
+
render :template => "merb/test/fixtures/controllers/html_default/index.html"
|
73
|
+
end
|
74
|
+
|
43
75
|
end
|
44
76
|
|
45
77
|
class DisplayWithTemplateArgument < Display
|
@@ -47,24 +79,40 @@ module Merb::Test::Fixtures::Controllers
|
|
47
79
|
@obj = SomeModel.new
|
48
80
|
display @obj, :layout => :custom_arg
|
49
81
|
end
|
50
|
-
|
82
|
+
|
51
83
|
def index_by_arg
|
52
84
|
@obj = SomeModel.new
|
53
85
|
display @obj, "merb/test/fixtures/controllers/display_with_template_argument/index.html"
|
54
86
|
end
|
55
87
|
end
|
56
|
-
|
88
|
+
|
89
|
+
class DisplayWithStringLocation < Display
|
90
|
+
provides :json
|
91
|
+
def index
|
92
|
+
@obj = SomeModel.new
|
93
|
+
display @obj, :location => "/some_resources/#{@obj.to_param}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class DisplayWithStatus < Display
|
98
|
+
provides :json
|
99
|
+
def index
|
100
|
+
@obj = SomeModel.new
|
101
|
+
display @obj, :status => 500
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
57
105
|
class DisplayWithSerializationOptions < Display
|
58
106
|
provides :json
|
59
|
-
|
107
|
+
|
60
108
|
def index
|
61
109
|
@obj = SomeModel.new
|
62
110
|
display @obj, :include => [:beer, :jazz], :except => [:idiots]
|
63
111
|
end
|
64
|
-
|
112
|
+
|
65
113
|
def index_that_passes_empty_hash
|
66
114
|
@obj = SomeModel.new
|
67
115
|
display @obj, {}
|
68
116
|
end
|
69
117
|
end
|
70
|
-
end
|
118
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Merb::Test::Fixtures::Controllers
|
2
|
+
class Testing < Merb::Controller
|
3
|
+
self._template_root = File.dirname(__FILE__) / "views"
|
4
|
+
end
|
5
|
+
|
6
|
+
class SimpleRedirect < Testing
|
7
|
+
def index
|
8
|
+
redirect("/")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class PermanentRedirect < Testing
|
13
|
+
def index
|
14
|
+
redirect("/", :permanent => true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class RedirectWithMessage < Testing
|
19
|
+
def index
|
20
|
+
redirect("/", :message => { :notice => "what?" })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class ConsumesMessage < Testing
|
25
|
+
def index
|
26
|
+
message[:notice].inspect
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class SetsMessage < Testing
|
31
|
+
def index
|
32
|
+
message[:notice] = "Hello"
|
33
|
+
message[:notice]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
1
|
module Merb::Test::Fixtures::Controllers
|
4
|
-
|
5
2
|
class Testing < Merb::Controller
|
6
3
|
self._template_root = File.dirname(__FILE__) / "views"
|
7
4
|
end
|
8
5
|
|
6
|
+
|
9
7
|
class Responder < Testing
|
10
|
-
|
11
8
|
def index
|
12
9
|
render
|
13
10
|
end
|
14
11
|
end
|
15
12
|
|
13
|
+
|
16
14
|
class HtmlDefault < Responder; end
|
17
15
|
|
16
|
+
|
18
17
|
class ClassProvides < Responder
|
19
18
|
provides :xml
|
20
19
|
end
|
21
20
|
|
21
|
+
|
22
22
|
class LocalProvides < Responder
|
23
23
|
def index
|
24
24
|
provides :xml
|
@@ -26,37 +26,48 @@ module Merb::Test::Fixtures::Controllers
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
|
29
30
|
class MultiProvides < Responder
|
30
31
|
def index
|
31
32
|
provides :html, :js
|
32
33
|
render
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
+
|
37
|
+
class ClassAndLocalProvides < Responder
|
38
|
+
provides :html
|
39
|
+
def index
|
40
|
+
provides :xml
|
41
|
+
render
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
36
45
|
class ClassOnlyProvides < Responder
|
37
46
|
only_provides :text, :xml
|
38
|
-
|
47
|
+
|
39
48
|
def index
|
40
49
|
"nothing"
|
41
50
|
end
|
42
51
|
end
|
43
|
-
|
52
|
+
|
53
|
+
|
44
54
|
class OnlyProvides < Responder
|
45
55
|
def index
|
46
56
|
only_provides :text, :xml
|
47
57
|
"nothing"
|
48
58
|
end
|
49
59
|
end
|
50
|
-
|
60
|
+
|
51
61
|
class ClassDoesntProvides < Responder
|
52
62
|
provides :xml
|
53
63
|
does_not_provide :html
|
54
|
-
|
64
|
+
|
55
65
|
def index
|
56
66
|
"nothing"
|
57
67
|
end
|
58
68
|
end
|
59
|
-
|
69
|
+
|
70
|
+
|
60
71
|
class DoesntProvide < Responder
|
61
72
|
def index
|
62
73
|
provides :xml
|
@@ -64,4 +75,19 @@ module Merb::Test::Fixtures::Controllers
|
|
64
75
|
"nothing"
|
65
76
|
end
|
66
77
|
end
|
67
|
-
|
78
|
+
|
79
|
+
|
80
|
+
class FooFormatProvides < Responder
|
81
|
+
only_provides :foo
|
82
|
+
|
83
|
+
def index
|
84
|
+
render "nothing"
|
85
|
+
end
|
86
|
+
|
87
|
+
def show
|
88
|
+
headers["Content-Language"] = 'nl'
|
89
|
+
headers["Biz"] = "buzz"
|
90
|
+
render "nothing"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{custom_arg: <%= catch_content(:for_layout) %>}
|
@@ -0,0 +1 @@
|
|
1
|
+
HTML: Class and Local
|
@@ -0,0 +1 @@
|
|
1
|
+
<XML:ClassAndLocalProvides provides='true' />
|
@@ -0,0 +1 @@
|
|
1
|
+
No layoutz eva!
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Merb::Controller, "._session_cookie_domain" do
|
4
|
+
before(:each) do
|
5
|
+
Merb::Config[:session_cookie_domain].should_not be(nil)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'is set to Merb::Config[:session_cookie_domain] by default' do
|
9
|
+
Merb::Controller._session_cookie_domain.should == Merb::Config[:session_cookie_domain]
|
10
|
+
Merb::Test::Fixtures::Controllers::CookiesController._session_cookie_domain.should ==
|
11
|
+
Merb::Config[:session_cookie_domain]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can be overridden for particular controller" do
|
15
|
+
Merb::Test::Fixtures::Controllers::OverridingSessionCookieDomain._session_cookie_domain.should ==
|
16
|
+
"overridden.merbivore.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is inherited by subclasses unless overriden' do
|
20
|
+
Merb::Test::Fixtures::Controllers::NotOverridingSessionCookieDomain._session_cookie_domain.should ==
|
21
|
+
Merb::Config[:session_cookie_domain]
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,411 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
require File.join(File.dirname(__FILE__), "controllers", "dispatcher")
|
3
|
+
|
4
|
+
include Merb::Test::Fixtures::Controllers
|
5
|
+
|
6
|
+
describe Merb::Dispatcher do
|
7
|
+
include Merb::Test::Rspec::ControllerMatchers
|
8
|
+
include Merb::Test::Rspec::ViewMatchers
|
9
|
+
|
10
|
+
def with_level(level)
|
11
|
+
Merb.logger = Merb::Logger.new(StringIO.new, level)
|
12
|
+
yield
|
13
|
+
Merb.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def dispatch(url)
|
17
|
+
Merb::Dispatcher.handle(request_for(url))
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_for(url)
|
21
|
+
Merb::Request.new(Rack::MockRequest.env_for(url))
|
22
|
+
end
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
Merb::Config[:exception_details] = true
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with a regular route, " do
|
29
|
+
before(:each) do
|
30
|
+
Merb::Router.prepare do |r|
|
31
|
+
r.default_routes
|
32
|
+
end
|
33
|
+
@url = "/dispatch_to/index"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "dispatches to the right controller and action" do
|
37
|
+
controller = dispatch(@url)
|
38
|
+
controller.body.should == "Dispatched"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets the Request#params to include the route params" do
|
42
|
+
controller = dispatch(@url)
|
43
|
+
controller.request.params.should ==
|
44
|
+
{"controller" => "dispatch_to", "action" => "index",
|
45
|
+
"id" => nil, "format" => nil}
|
46
|
+
end
|
47
|
+
|
48
|
+
it "provides the time for start of request handling via Logger#info" do
|
49
|
+
with_level(:info) do
|
50
|
+
dispatch(@url)
|
51
|
+
end.should include_log("Started request handling")
|
52
|
+
|
53
|
+
with_level(:warn) do
|
54
|
+
dispatch(@url)
|
55
|
+
end.should_not include_log("Started request handling")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "provides the routed params via Logger#debug" do
|
59
|
+
with_level(:debug) do
|
60
|
+
dispatch(@url)
|
61
|
+
end.should include_log("Routed to:")
|
62
|
+
|
63
|
+
with_level(:info) do
|
64
|
+
dispatch(@url)
|
65
|
+
end.should_not include_log("Routed to:")
|
66
|
+
end
|
67
|
+
|
68
|
+
it "provides the benchmarks via Logger#info" do
|
69
|
+
with_level(:info) do
|
70
|
+
dispatch(@url)
|
71
|
+
end.should include_log(":after_filters_time")
|
72
|
+
|
73
|
+
with_level(:warn) do
|
74
|
+
dispatch(@url)
|
75
|
+
end.should_not include_log(":after_filters_time")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "with a route that redirects" do
|
80
|
+
before(:each) do
|
81
|
+
Merb::Router.prepare do |r|
|
82
|
+
r.match("/redirect/to/foo").redirect("/foo")
|
83
|
+
r.default_routes
|
84
|
+
end
|
85
|
+
@url = "/redirect/to/foo"
|
86
|
+
@controller = dispatch(@url)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "redirects" do
|
90
|
+
@controller.body.should =~ %r{You are being <a href="/foo">redirected}
|
91
|
+
end
|
92
|
+
|
93
|
+
it "reports that it is redirecting via Logger#info" do
|
94
|
+
with_level(:info) do
|
95
|
+
dispatch(@url)
|
96
|
+
end.should include_log("Dispatcher redirecting to: /foo")
|
97
|
+
|
98
|
+
with_level(:warn) do
|
99
|
+
dispatch(@url)
|
100
|
+
end.should_not include_log("Dispatcher redirecting to: /foo")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "sets the status correctly" do
|
104
|
+
@controller.status.should == 301
|
105
|
+
end
|
106
|
+
|
107
|
+
it "sets the location correctly" do
|
108
|
+
@controller.headers["Location"].should == "/foo"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "with a route that points to a class that is not a Controller, " do
|
113
|
+
before(:each) do
|
114
|
+
Merb::Router.prepare do |r|
|
115
|
+
r.default_routes
|
116
|
+
end
|
117
|
+
@url = "/not_a_controller/index"
|
118
|
+
@controller = dispatch(@url)
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "with exception details showing" do
|
122
|
+
it "raises a NotFound" do
|
123
|
+
@controller.should be_error(Merb::ControllerExceptions::NotFound)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "returns a 404 status" do
|
127
|
+
@controller.status.should == 404
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns useful info in the body" do
|
131
|
+
@controller.body.should =~
|
132
|
+
%r{<h2>Controller 'Merb::Test::Fixtures::Controllers::NotAController' not found.</h2>}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "when the action raises an Exception" do
|
137
|
+
before(:each) do
|
138
|
+
Object.class_eval <<-RUBY
|
139
|
+
class Exceptions < Application
|
140
|
+
def gone
|
141
|
+
"Gone"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
RUBY
|
145
|
+
end
|
146
|
+
|
147
|
+
after(:each) do
|
148
|
+
Object.send(:remove_const, :Exceptions)
|
149
|
+
end
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
Merb::Router.prepare do |r|
|
153
|
+
r.default_routes
|
154
|
+
end
|
155
|
+
@url = "/raise_gone/index"
|
156
|
+
@controller = dispatch(@url)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "remembers that the Exception is Gone" do
|
160
|
+
@controller.should be_error(Merb::ControllerExceptions::Gone)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "renders the action Exception#gone" do
|
164
|
+
@controller.body.should == "Gone"
|
165
|
+
end
|
166
|
+
|
167
|
+
it "returns the status 410" do
|
168
|
+
@controller.status.should == 410
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "when the action raises an Exception that has a superclass Exception available" do
|
173
|
+
before(:each) do
|
174
|
+
Object.class_eval <<-RUBY
|
175
|
+
class Exceptions < Application
|
176
|
+
def client_error
|
177
|
+
"ClientError"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
RUBY
|
181
|
+
end
|
182
|
+
|
183
|
+
after(:each) do
|
184
|
+
Object.send(:remove_const, :Exceptions)
|
185
|
+
end
|
186
|
+
|
187
|
+
before(:each) do
|
188
|
+
Merb::Router.prepare do |r|
|
189
|
+
r.default_routes
|
190
|
+
end
|
191
|
+
@url = "/raise_gone/index"
|
192
|
+
@controller = dispatch(@url)
|
193
|
+
end
|
194
|
+
|
195
|
+
it "renders the Exception from the Exceptions controller" do
|
196
|
+
@controller.should be_error(Merb::ControllerExceptions::Gone)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "renders the action Exceptions#client_error since #gone is not defined" do
|
200
|
+
@controller.body.should == "ClientError"
|
201
|
+
end
|
202
|
+
|
203
|
+
it "returns the status 410 (Gone) even though we rendered #client_error" do
|
204
|
+
@controller.status.should == 410
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "when the action raises an Error that is not a ControllerError" do
|
210
|
+
before(:each) do
|
211
|
+
Object.class_eval <<-RUBY
|
212
|
+
class Exceptions < Application
|
213
|
+
def load_error
|
214
|
+
"LoadError"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
RUBY
|
218
|
+
end
|
219
|
+
|
220
|
+
after(:each) do
|
221
|
+
Object.send(:remove_const, :Exceptions)
|
222
|
+
end
|
223
|
+
|
224
|
+
before(:each) do
|
225
|
+
Merb::Router.prepare do |r|
|
226
|
+
r.default_routes
|
227
|
+
end
|
228
|
+
@url = "/raise_load_error/index"
|
229
|
+
@controller = dispatch(@url)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "knows that the error is a LoadError" do
|
233
|
+
@controller.should be_error(LoadError)
|
234
|
+
end
|
235
|
+
|
236
|
+
it "renders Exceptions#load_error" do
|
237
|
+
@controller.body.should == "LoadError"
|
238
|
+
end
|
239
|
+
|
240
|
+
it "returns a 500 status code" do
|
241
|
+
@controller.status.should == 500
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe "when the Exception action raises" do
|
246
|
+
before(:each) do
|
247
|
+
Object.class_eval <<-RUBY
|
248
|
+
class Exceptions < Application
|
249
|
+
def load_error
|
250
|
+
raise StandardError, "Big error"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
RUBY
|
254
|
+
end
|
255
|
+
|
256
|
+
after(:each) do
|
257
|
+
Object.send(:remove_const, :Exceptions)
|
258
|
+
end
|
259
|
+
|
260
|
+
before(:each) do
|
261
|
+
Merb::Router.prepare do |r|
|
262
|
+
r.default_routes
|
263
|
+
end
|
264
|
+
@url = "/raise_load_error/index"
|
265
|
+
@controller = dispatch(@url)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "knows that the error is a StandardError" do
|
269
|
+
@controller.should be_error(StandardError)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "renders the default exception template" do
|
273
|
+
@controller.body.should have_selector("h1:contains(Standard Error)")
|
274
|
+
@controller.body.should have_selector("h2:contains(Big Error)")
|
275
|
+
|
276
|
+
@controller.body.should have_selector("h1:contains(Load Error)")
|
277
|
+
@controller.body.should have_selector("h2:contains(Big Error)")
|
278
|
+
end
|
279
|
+
|
280
|
+
it "returns a 500 status code" do
|
281
|
+
@controller.status.should == 500
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
|
286
|
+
describe "when the Exception action raises a NotFound" do
|
287
|
+
before(:each) do
|
288
|
+
Object.class_eval <<-RUBY
|
289
|
+
class Exceptions < Application
|
290
|
+
def not_found
|
291
|
+
raise NotFound, "Somehow, the thing you were looking for was not found."
|
292
|
+
end
|
293
|
+
end
|
294
|
+
RUBY
|
295
|
+
end
|
296
|
+
|
297
|
+
after(:each) do
|
298
|
+
Object.send(:remove_const, :Exceptions)
|
299
|
+
end
|
300
|
+
|
301
|
+
before(:each) do
|
302
|
+
Merb::Router.prepare do |r|
|
303
|
+
r.default_routes
|
304
|
+
end
|
305
|
+
@url = "/page/not/found"
|
306
|
+
@controller = dispatch(@url)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "knows that the error is a NotFound" do
|
310
|
+
@controller.should be_error(Merb::ControllerExceptions::NotFound)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "renders the default exception template" do
|
314
|
+
@controller.body.should have_selector("h1:contains(Not Found)")
|
315
|
+
@controller.body.should have_selector("h2:contains(Somehow, the thing)")
|
316
|
+
end
|
317
|
+
|
318
|
+
it "returns a 404 status code" do
|
319
|
+
@controller.status.should == 404
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
describe "when the Exception action raises the same thing as the original failure" do
|
324
|
+
before(:each) do
|
325
|
+
Object.class_eval <<-RUBY
|
326
|
+
class Exceptions < Application
|
327
|
+
def load_error
|
328
|
+
raise LoadError, "Something failed here"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
RUBY
|
332
|
+
end
|
333
|
+
|
334
|
+
after(:each) do
|
335
|
+
Object.send(:remove_const, :Exceptions)
|
336
|
+
end
|
337
|
+
|
338
|
+
before(:each) do
|
339
|
+
Merb::Router.prepare do |r|
|
340
|
+
r.default_routes
|
341
|
+
end
|
342
|
+
@url = "/raise_load_error/index"
|
343
|
+
@controller = dispatch(@url)
|
344
|
+
end
|
345
|
+
|
346
|
+
it "knows that the error is a NotFound" do
|
347
|
+
@controller.should be_error(LoadError)
|
348
|
+
end
|
349
|
+
|
350
|
+
it "renders the default exception template" do
|
351
|
+
@controller.body.should have_selector("h1:contains(Something failed here)")
|
352
|
+
end
|
353
|
+
|
354
|
+
it "returns a 500 status code" do
|
355
|
+
@controller.status.should == 500
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
describe "when more than one Exceptions methods raises an Error" do
|
360
|
+
before(:each) do
|
361
|
+
Object.class_eval <<-RUBY
|
362
|
+
class Exceptions < Application
|
363
|
+
def load_error
|
364
|
+
raise StandardError, "StandardError"
|
365
|
+
end
|
366
|
+
|
367
|
+
def standard_error
|
368
|
+
raise Exception, "Exception"
|
369
|
+
end
|
370
|
+
end
|
371
|
+
RUBY
|
372
|
+
end
|
373
|
+
|
374
|
+
after(:each) do
|
375
|
+
Object.send(:remove_const, :Exceptions)
|
376
|
+
end
|
377
|
+
|
378
|
+
before(:each) do
|
379
|
+
Merb::Router.prepare do |r|
|
380
|
+
r.default_routes
|
381
|
+
end
|
382
|
+
@url = "/raise_load_error/index"
|
383
|
+
@controller = dispatch(@url)
|
384
|
+
@body = @controller.body
|
385
|
+
end
|
386
|
+
|
387
|
+
it "knows that the error is a NotFound" do
|
388
|
+
@controller.should be_error(Exception)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "renders a list of links to the traces" do
|
392
|
+
@body.should have_selector("li a[@href=#exception_0]")
|
393
|
+
@body.should have_selector("li a[@href=#exception_1]")
|
394
|
+
@body.should have_selector("li a[@href=#exception_2]")
|
395
|
+
end
|
396
|
+
|
397
|
+
it "renders the default exception template" do
|
398
|
+
@body.should have_selector("h1:contains(Load Error)")
|
399
|
+
@body.should have_selector("h2:contains(In the controller)")
|
400
|
+
@body.should have_selector("h1:contains(Standard Error)")
|
401
|
+
@body.should have_selector("h2:contains(StandardError)")
|
402
|
+
@body.should have_selector("h1:contains(Exception)")
|
403
|
+
@body.should have_selector("h2:contains(Exception)")
|
404
|
+
end
|
405
|
+
|
406
|
+
it "returns a 500 status code" do
|
407
|
+
@controller.status.should == 500
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
end
|