merb-core 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +61 -11
- data/bin/merb +5 -1
- data/lib/merb-core.rb +202 -25
- data/lib/merb-core/autoload.rb +19 -17
- data/lib/merb-core/bootloader.rb +84 -71
- data/lib/merb-core/config.rb +19 -14
- data/lib/merb-core/controller/abstract_controller.rb +16 -17
- data/lib/merb-core/controller/exceptions.rb +115 -70
- data/lib/merb-core/controller/merb_controller.rb +62 -38
- data/lib/merb-core/controller/mime.rb +1 -1
- data/lib/merb-core/controller/mixins/authentication.rb +87 -0
- data/lib/merb-core/controller/mixins/controller.rb +16 -15
- data/lib/merb-core/controller/mixins/render.rb +113 -19
- data/lib/merb-core/controller/mixins/responder.rb +8 -2
- data/lib/merb-core/controller/template.rb +1 -1
- data/lib/merb-core/core_ext.rb +1 -0
- data/lib/merb-core/core_ext/class.rb +113 -6
- data/lib/merb-core/core_ext/hash.rb +43 -39
- data/lib/merb-core/core_ext/kernel.rb +75 -38
- data/lib/merb-core/core_ext/mash.rb +4 -4
- data/lib/merb-core/core_ext/object.rb +18 -7
- data/lib/merb-core/core_ext/set.rb +9 -4
- data/lib/merb-core/core_ext/string.rb +29 -9
- data/lib/merb-core/core_ext/time.rb +13 -0
- data/lib/merb-core/dispatch/cookies.rb +1 -2
- data/lib/merb-core/dispatch/dispatcher.rb +18 -10
- data/lib/merb-core/dispatch/exceptions.html.erb +1 -1
- data/lib/merb-core/dispatch/request.rb +3 -0
- data/lib/merb-core/dispatch/router.rb +10 -7
- data/lib/merb-core/dispatch/router/behavior.rb +36 -27
- data/lib/merb-core/dispatch/router/route.rb +7 -2
- data/lib/merb-core/dispatch/session/cookie.rb +4 -4
- data/lib/merb-core/dispatch/session/memcached.rb +17 -5
- data/lib/merb-core/logger.rb +2 -2
- data/lib/merb-core/plugins.rb +16 -4
- data/lib/merb-core/rack/adapter/ebb.rb +4 -1
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +1 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +1 -0
- data/lib/merb-core/rack/adapter/runner.rb +1 -0
- data/lib/merb-core/rack/adapter/thin.rb +3 -1
- data/lib/merb-core/rack/adapter/webrick.rb +1 -0
- data/lib/merb-core/rack/application.rb +17 -1
- data/lib/merb-core/server.rb +78 -28
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
- data/lib/merb-core/test/helpers/request_helper.rb +81 -27
- data/lib/merb-core/test/helpers/view_helper.rb +1 -1
- data/lib/merb-core/test/matchers/controller_matchers.rb +55 -5
- data/lib/merb-core/test/matchers/route_matchers.rb +8 -17
- data/lib/merb-core/test/matchers/view_matchers.rb +53 -11
- data/lib/merb-core/test/run_specs.rb +22 -14
- data/lib/merb-core/test/tasks/spectasks.rb +54 -33
- data/lib/merb-core/vendor/facets/inflect.rb +91 -2
- data/lib/merb-core/version.rb +2 -2
- data/spec/private/config/config_spec.rb +54 -26
- data/spec/private/core_ext/class_spec.rb +22 -0
- data/spec/private/core_ext/hash_spec.rb +70 -54
- data/spec/private/core_ext/kernel_spec.rb +149 -14
- data/spec/private/core_ext/object_spec.rb +92 -10
- data/spec/private/core_ext/string_spec.rb +162 -4
- data/spec/private/core_ext/time_spec.rb +16 -0
- data/spec/private/dispatch/bootloader_spec.rb +24 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +1 -1
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +1 -1
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +1 -1
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +1 -1
- data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +138 -0
- data/spec/private/plugins/plugin_spec.rb +79 -8
- data/spec/private/rack/application_spec.rb +1 -1
- data/spec/public/abstract_controller/controllers/filters.rb +26 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +2 -2
- data/spec/public/abstract_controller/controllers/partial.rb +2 -2
- data/spec/public/abstract_controller/controllers/render.rb +16 -4
- data/spec/public/abstract_controller/filter_spec.rb +8 -0
- data/spec/public/abstract_controller/render_spec.rb +12 -0
- data/spec/public/controller/authentication_spec.rb +103 -0
- data/spec/public/controller/base_spec.rb +4 -3
- data/spec/public/controller/controllers/authentication.rb +47 -0
- data/spec/public/controller/controllers/base.rb +1 -0
- data/spec/public/controller/controllers/display.rb +30 -0
- data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
- data/spec/public/controller/display_spec.rb +17 -0
- data/spec/public/controller/spec_helper.rb +1 -0
- data/spec/public/controller/url_spec.rb +25 -7
- data/spec/public/core/merb_core_spec.rb +34 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +2 -2
- data/spec/public/directory_structure/directory/log/merb_test.log +48 -0
- data/spec/public/logger/logger_spec.rb +10 -4
- data/spec/public/reloading/directory/app/controllers/reload.rb +1 -1
- data/spec/public/reloading/directory/log/merb_test.log +13 -0
- data/spec/public/reloading/reload_spec.rb +23 -22
- data/spec/public/request/request_spec.rb +2 -0
- data/spec/public/router/nested_resources_spec.rb +7 -0
- data/spec/public/router/resources_spec.rb +46 -1
- data/spec/public/router/special_spec.rb +5 -1
- data/spec/public/test/controller_matchers_spec.rb +25 -1
- data/spec/public/test/controllers/spec_helper_controller.rb +8 -0
- data/spec/public/test/request_helper_spec.rb +52 -1
- data/spec/public/test/route_matchers_spec.rb +27 -25
- data/spec/public/test/view_helper_spec.rb +1 -1
- data/spec/public/test/view_matchers_spec.rb +148 -72
- metadata +23 -3
|
@@ -77,4 +77,12 @@ describe Merb::AbstractController, " should support before and after filters" do
|
|
|
77
77
|
it "should throw an error" do
|
|
78
78
|
running { dispatch_should_make_body("TestConditionalFilterWithNoProcOrSymbol", "") }.should raise_error(ArgumentError, /a Symbol or a Proc/)
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
it "should support passing an argument to a before filter method" do
|
|
82
|
+
dispatch_should_make_body("TestBeforeFilterWithArgument", "index action")
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should support passing arguments to a before filter method" do
|
|
86
|
+
dispatch_should_make_body("TestBeforeFilterWithArguments", "index action")
|
|
87
|
+
end
|
|
80
88
|
end
|
|
@@ -46,6 +46,18 @@ describe Merb::AbstractController, " rendering templates" do
|
|
|
46
46
|
it "should support rendering plain strings with the controller layout" do
|
|
47
47
|
dispatch_should_make_body("RenderTemplateControllerLayout", "Controller: the index")
|
|
48
48
|
end
|
|
49
|
+
|
|
50
|
+
it "should support rendering templates without any layout (even if the default layout exists)" do
|
|
51
|
+
dispatch_should_make_body("RenderNoDefaultAppLayout", "the index")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should inherit the layout setting from a parent controller class" do
|
|
55
|
+
dispatch_should_make_body("RenderNoDefaultAppLayoutInherited", "the index")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should support reverting to the default layout" do
|
|
59
|
+
dispatch_should_make_body("RenderDefaultAppLayoutInheritedOverride", "App: the index")
|
|
60
|
+
end
|
|
49
61
|
|
|
50
62
|
it "should support rendering templates with a custom location" do
|
|
51
63
|
dispatch_should_make_body("RenderTemplateCustomLocation", "Wonderful")
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
|
2
|
+
|
|
3
|
+
describe "basic_authentication in general", :shared => true do
|
|
4
|
+
|
|
5
|
+
it "should halt the filter chain and return a 401 status code if no authentication is sent" do
|
|
6
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index)
|
|
7
|
+
response.body.should == "HTTP Basic: Access denied.\n"
|
|
8
|
+
response.status.should == 401
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should halt the filter chain and return a 401 status code on invalid username and password" do
|
|
12
|
+
u, p = "John", "password"
|
|
13
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index, u, p)
|
|
14
|
+
response.body.should == "HTTP Basic: Access denied.\n"
|
|
15
|
+
response.status.should == 401
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should halt the filter chain and return a 401 status code on invalid username and valid password" do
|
|
19
|
+
u, p = "John", "secret"
|
|
20
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index, u, p)
|
|
21
|
+
response.body.should == "HTTP Basic: Access denied.\n"
|
|
22
|
+
response.status.should == 401
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should halt the filter chain and return a 401 status code on valid username and invalid password" do
|
|
26
|
+
u, p = "Fred", "password"
|
|
27
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index, u, p)
|
|
28
|
+
response.body.should == "HTTP Basic: Access denied.\n"
|
|
29
|
+
response.status.should == 401
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should call the action on valid username and password" do
|
|
33
|
+
u, p = "Fred", "secret"
|
|
34
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index, u, p)
|
|
35
|
+
response.body.should == "authenticated"
|
|
36
|
+
response.status.should == 200
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe Merb::Controller, "#basic_authentication with no realm" do
|
|
42
|
+
|
|
43
|
+
it_should_behave_like "basic_authentication in general"
|
|
44
|
+
|
|
45
|
+
it "should have a default WWW-Authenticate realm of 'Application' if no authentication is sent" do
|
|
46
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index)
|
|
47
|
+
response.headers['WWW-Authenticate'] = 'Basic realm="Application"'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should have a default WWW-Authenticate realm of 'Application' if incorrect authentication is sent" do
|
|
51
|
+
u, p = "John", "password"
|
|
52
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthentication, :index, u, p)
|
|
53
|
+
response.headers['WWW-Authenticate'] = 'Basic realm="Application"'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe Merb::Controller, "#basic_authentication with realm" do
|
|
59
|
+
|
|
60
|
+
it_should_behave_like "basic_authentication in general"
|
|
61
|
+
|
|
62
|
+
it "should set the WWW-Authenticate realm if no authentication is sent" do
|
|
63
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::BasicAuthenticationWithRealm, :index)
|
|
64
|
+
response.headers['WWW-Authenticate'] = 'Basic realm="My SuperApp"'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should set the WWW-Authenticate realm if incorrect authentication is sent" do
|
|
68
|
+
u, p = "John", "password"
|
|
69
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::BasicAuthenticationWithRealm, :index, u, p)
|
|
70
|
+
response.headers['WWW-Authenticate'] = 'Basic realm="My SuperApp"'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe Merb::Controller, "#basic_authentication.authenticate" do
|
|
76
|
+
|
|
77
|
+
it "should pass in the username and password and return the result of the block" do
|
|
78
|
+
u, p = "Fred", "secret"
|
|
79
|
+
response = dispatch_with_basic_authentication_to(Merb::Test::Fixtures::Controllers::AuthenticateBasicAuthentication, :index, u, p)
|
|
80
|
+
response.body.should == "Fred:secret"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe Merb::Controller, "#basic_authentication.request" do
|
|
86
|
+
|
|
87
|
+
it "should halt the filter chain and return a 401 status code" do
|
|
88
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::RequestBasicAuthentication, :index)
|
|
89
|
+
response.body.should == "HTTP Basic: Access denied.\n"
|
|
90
|
+
response.status.should == 401
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should have a default WWW-Authenticate realm of 'Application'" do
|
|
94
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::RequestBasicAuthentication, :index)
|
|
95
|
+
response.headers['WWW-Authenticate'].should == 'Basic realm="Application"'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "should set the WWW-Authenticate realm" do
|
|
99
|
+
response = dispatch_to(Merb::Test::Fixtures::Controllers::RequestBasicAuthenticationWithRealm, :index)
|
|
100
|
+
response.headers['WWW-Authenticate'].should == 'Basic realm="My SuperApp"'
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
@@ -10,7 +10,9 @@ describe Merb::Controller, " callable actions" do
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "should dispatch to callable actions" do
|
|
13
|
-
dispatch_to(Merb::Test::Fixtures::Controllers::Base, :index)
|
|
13
|
+
controller = dispatch_to(Merb::Test::Fixtures::Controllers::Base, :index)
|
|
14
|
+
controller.body.should == "index"
|
|
15
|
+
controller.status.should == 200
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
it "should not dispatch to hidden actions" do
|
|
@@ -26,6 +28,5 @@ describe Merb::Controller, " callable actions" do
|
|
|
26
28
|
calling { dispatch_to(Merb::Test::Fixtures::Controllers::Base, :bat) }.
|
|
27
29
|
should raise_error(Merb::ControllerExceptions::ActionNotFound)
|
|
28
30
|
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
|
|
31
32
|
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Merb::Test::Fixtures::Controllers
|
|
2
|
+
|
|
3
|
+
class Testing < Merb::Controller
|
|
4
|
+
self._template_root = File.dirname(__FILE__) / "views"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class BasicAuthentication < Testing
|
|
8
|
+
|
|
9
|
+
before :authenticate, :only => :index
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
"authenticated"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
protected
|
|
16
|
+
|
|
17
|
+
def authenticate
|
|
18
|
+
basic_authentication { |u, p| u == "Fred" && p == "secret" }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class BasicAuthenticationWithRealm < BasicAuthentication
|
|
24
|
+
def authenticate
|
|
25
|
+
basic_authentication("My Super App") { |u, p| u == "Fred" && p == "secret" }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class AuthenticateBasicAuthentication < Testing
|
|
30
|
+
def index
|
|
31
|
+
basic_authentication.authenticate { |u, p| "Fred:secret" }
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class RequestBasicAuthentication < BasicAuthentication
|
|
36
|
+
def authenticate
|
|
37
|
+
basic_authentication.request
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class RequestBasicAuthenticationWithRealm < BasicAuthentication
|
|
42
|
+
def authenticate
|
|
43
|
+
basic_authentication("My SuperApp").request
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
@@ -4,6 +4,11 @@ module Merb::Test::Fixtures::Controllers
|
|
|
4
4
|
|
|
5
5
|
class SomeModel
|
|
6
6
|
def to_xml; "<XML:Model />" end
|
|
7
|
+
def to_json(options = {})
|
|
8
|
+
includes = options[:include].join(', ') rescue ""
|
|
9
|
+
excludes = options[:except].first rescue ""
|
|
10
|
+
"{ 'include': '#{includes}', 'exclude': '#{excludes}' }"
|
|
11
|
+
end
|
|
7
12
|
end
|
|
8
13
|
|
|
9
14
|
class Testing < Merb::Controller
|
|
@@ -37,4 +42,29 @@ module Merb::Test::Fixtures::Controllers
|
|
|
37
42
|
layout :custom
|
|
38
43
|
end
|
|
39
44
|
|
|
45
|
+
class DisplayWithTemplateArgument < Display
|
|
46
|
+
def index
|
|
47
|
+
@obj = SomeModel.new
|
|
48
|
+
display @obj, :layout => :custom_arg
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def index_by_arg
|
|
52
|
+
@obj = SomeModel.new
|
|
53
|
+
display @obj, "merb/test/fixtures/controllers/display_with_template_argument/index.html"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class DisplayWithSerializationOptions < Display
|
|
58
|
+
provides :json
|
|
59
|
+
|
|
60
|
+
def index
|
|
61
|
+
@obj = SomeModel.new
|
|
62
|
+
display @obj, :include => [:beer, :jazz], :except => [:idiots]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def index_that_passes_empty_hash
|
|
66
|
+
@obj = SomeModel.new
|
|
67
|
+
display @obj, {}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
40
70
|
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Custom Arg: <%= catch_content(:for_layout) %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Template
|
|
@@ -15,6 +15,14 @@ describe Merb::Controller, " displaying objects based on mime type" do
|
|
|
15
15
|
it "should use a template if specified" do
|
|
16
16
|
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :index).body.should == "Custom: Template"
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
it "should accept a layout argument" do
|
|
20
|
+
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplateArgument, :index).body.should == "Custom Arg: Template"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should accept a template path argument" do
|
|
24
|
+
dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplateArgument, :index_by_arg).body.should == "Template"
|
|
25
|
+
end
|
|
18
26
|
|
|
19
27
|
it "should use other mime-types if they are provided on the class level" do
|
|
20
28
|
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayClassProvides, :index, {}, :http_accept => "application/xml")
|
|
@@ -31,4 +39,13 @@ describe Merb::Controller, " displaying objects based on mime type" do
|
|
|
31
39
|
controller.body.should == "<XML:Model />"
|
|
32
40
|
end
|
|
33
41
|
|
|
42
|
+
it "passes all options to serialization method like :to_json" do
|
|
43
|
+
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithSerializationOptions, :index, {}, :http_accept => "application/json")
|
|
44
|
+
controller.body.should == "{ 'include': 'beer, jazz', 'exclude': 'idiots' }"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "passes single argument to serialization method like :to_json" do
|
|
48
|
+
controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithSerializationOptions, :index_that_passes_empty_hash, {}, :http_accept => "application/json")
|
|
49
|
+
controller.body.should == "{ 'include': '', 'exclude': '' }"
|
|
50
|
+
end
|
|
34
51
|
end
|
|
@@ -5,5 +5,6 @@ require File.join(__DIR__, "..", "..", "spec_helper")
|
|
|
5
5
|
require File.join(__DIR__, "controllers", "base")
|
|
6
6
|
require File.join(__DIR__, "controllers", "responder")
|
|
7
7
|
require File.join(__DIR__, "controllers", "display")
|
|
8
|
+
require File.join(__DIR__, "controllers", "authentication")
|
|
8
9
|
|
|
9
10
|
Merb.start :environment => 'test'
|
|
@@ -74,6 +74,14 @@ describe Merb::Controller, " url" do
|
|
|
74
74
|
@controller.url(:person, :name => 'david', :color => 'blue').should eql("/people/david?color=blue")
|
|
75
75
|
end
|
|
76
76
|
|
|
77
|
+
it "should match with a :format" do
|
|
78
|
+
@controller.url(:person, :name => 'david', :format => :xml).should eql("/people/david.xml")
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should match with an additional param and :format" do
|
|
82
|
+
@controller.url(:person, :name => 'david', :color => 'blue', :format => :xml).should eql("/people/david.xml?color=blue")
|
|
83
|
+
end
|
|
84
|
+
|
|
77
85
|
it "should match with additional params" do
|
|
78
86
|
url = @controller.url(:person, :name => 'david', :smell => 'funky', :color => 'blue')
|
|
79
87
|
url.should match(%r{/people/david?.*color=blue})
|
|
@@ -96,6 +104,16 @@ describe Merb::Controller, " url" do
|
|
|
96
104
|
it "should match with a fixnum as second arg" do
|
|
97
105
|
@controller.url(:monkey, 3).should == "/monkeys/3"
|
|
98
106
|
end
|
|
107
|
+
|
|
108
|
+
it "should match with an object and :format" do
|
|
109
|
+
@monkey = Monkey.new
|
|
110
|
+
@controller.url(:monkey, :id => @monkey, :format => :xml).should == "/monkeys/45.xml"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should match with an object, :format and additional options" do
|
|
114
|
+
@monkey = Monkey.new
|
|
115
|
+
@controller.url(:monkey, :id => @monkey, :format => :xml, :color => "blue").should == "/monkeys/45.xml?color=blue"
|
|
116
|
+
end
|
|
99
117
|
|
|
100
118
|
it "should match the delete_monkey route" do
|
|
101
119
|
@monkey = Monkey.new
|
|
@@ -114,23 +132,23 @@ describe Merb::Controller, " url" do
|
|
|
114
132
|
|
|
115
133
|
it "should match a nested resources show action" do
|
|
116
134
|
@blue = Blue.new
|
|
117
|
-
@controller.url(:monkey_blue
|
|
135
|
+
@controller.url(:monkey_blue, @blue).should == "/monkeys/45/blues/13"
|
|
118
136
|
end
|
|
119
137
|
|
|
120
138
|
it "should match the index action of nested resource with parent object" do
|
|
121
139
|
@blue = Blue.new
|
|
122
140
|
@monkey = Monkey.new
|
|
123
|
-
@controller.url(:monkey_blues
|
|
141
|
+
@controller.url(:monkey_blues, :monkey_id => @monkey).should == "/monkeys/45/blues"
|
|
124
142
|
end
|
|
125
143
|
|
|
126
144
|
it "should match the index action of nested resource with parent id as string" do
|
|
127
145
|
@blue = Blue.new
|
|
128
|
-
@controller.url(:monkey_blues
|
|
146
|
+
@controller.url(:monkey_blues, :monkey_id => '1').should == "/monkeys/1/blues"
|
|
129
147
|
end
|
|
130
148
|
|
|
131
149
|
it "should match the edit action of nested resource" do
|
|
132
150
|
@blue = Blue.new
|
|
133
|
-
@controller.url(:edit_monkey_blue
|
|
151
|
+
@controller.url(:edit_monkey_blue, @blue).should == "/monkeys/45/blues/13/edit"
|
|
134
152
|
end
|
|
135
153
|
|
|
136
154
|
it "should match the index action of resources nested under a resource" do
|
|
@@ -140,13 +158,13 @@ describe Merb::Controller, " url" do
|
|
|
140
158
|
|
|
141
159
|
it "should match resource that has been nested multiple times" do
|
|
142
160
|
@blue = Blue.new
|
|
143
|
-
@controller.url(:donkey_blue
|
|
144
|
-
@controller.url(:monkey_blue
|
|
161
|
+
@controller.url(:donkey_blue, @blue).should == "/donkeys/19/blues/13"
|
|
162
|
+
@controller.url(:monkey_blue, @blue).should == "/monkeys/45/blues/13"
|
|
145
163
|
end
|
|
146
164
|
|
|
147
165
|
it "should match resources nested more than one level deep" do
|
|
148
166
|
@pink = Pink.new
|
|
149
|
-
@controller.url(:monkey_blue_pink
|
|
167
|
+
@controller.url(:monkey_blue_pink, @pink).should == "/monkeys/45/blues/13/pinks/22"
|
|
150
168
|
end
|
|
151
169
|
|
|
152
170
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
describe "Merb.env helpers" do
|
|
4
|
+
before(:all) do
|
|
5
|
+
@orig_env = Merb.environment
|
|
6
|
+
end
|
|
7
|
+
after(:all) do
|
|
8
|
+
Merb.environment = @orig_env
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should pickup the environment from env" do
|
|
12
|
+
%w(development test production staging demo).each do |e|
|
|
13
|
+
Merb.environment = e
|
|
14
|
+
Merb.env.should == e
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should correctly answer the question about which env it's in with symbol or string" do
|
|
19
|
+
%w(development test production staging demo custom).each do |e|
|
|
20
|
+
Merb.environment = e
|
|
21
|
+
Merb.env?(e).should be true
|
|
22
|
+
Merb.env?(e.to_sym).should be_true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should answer false if asked for an environment that is not current" do
|
|
27
|
+
%w(development test production staging demo custom).each do |e|
|
|
28
|
+
Merb.environment = e
|
|
29
|
+
Merb.env?(:not_it).should be_false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -12,8 +12,8 @@ class Custom < Application
|
|
|
12
12
|
|
|
13
13
|
private
|
|
14
14
|
|
|
15
|
-
def _template_location(
|
|
16
|
-
"wonderful/#{
|
|
15
|
+
def _template_location(context, type = nil, controller = controller_name)
|
|
16
|
+
"wonderful/#{context}"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
end
|
|
@@ -263,3 +263,51 @@ Mon, 25 Feb 2008 23:13:20 GMT ~ {:action_time=>0.000562, :after_filters_time=>6.
|
|
|
263
263
|
~ {:before_filters_time=>7.0e-06, :after_filters_time=>5.0e-06, :action_time=>7.4e-05}
|
|
264
264
|
~ {:before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000615}
|
|
265
265
|
~ {:before_filters_time=>6.0e-06, :after_filters_time=>7.0e-06, :action_time=>0.000601}
|
|
266
|
+
~ Not Using Sessions
|
|
267
|
+
~ {:before_filters_time=>8.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.5e-05}
|
|
268
|
+
~ {:before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000618}
|
|
269
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000588}
|
|
270
|
+
~ Not Using Sessions
|
|
271
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.8e-05}
|
|
272
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000597}
|
|
273
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000574}
|
|
274
|
+
~ Not Using Sessions
|
|
275
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.3e-05}
|
|
276
|
+
~ {:before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000596}
|
|
277
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000571}
|
|
278
|
+
~ Not Using Sessions
|
|
279
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.5e-05}
|
|
280
|
+
~ {:before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000594}
|
|
281
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000576}
|
|
282
|
+
~ Not Using Sessions
|
|
283
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.5e-05}
|
|
284
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000843}
|
|
285
|
+
~ {:before_filters_time=>8.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000735}
|
|
286
|
+
~ Not Using Sessions
|
|
287
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>6.0e-06, :action_time=>7.9e-05}
|
|
288
|
+
~ {:before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06, :action_time=>0.000935}
|
|
289
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000656}
|
|
290
|
+
~ Not Using Sessions
|
|
291
|
+
~ {:before_filters_time=>9.0e-06, :after_filters_time=>6.0e-06, :action_time=>8.9e-05}
|
|
292
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000826}
|
|
293
|
+
~ {:before_filters_time=>3.5e-05, :after_filters_time=>7.0e-06, :action_time=>0.000879}
|
|
294
|
+
~ Not Using Sessions
|
|
295
|
+
~ {:before_filters_time=>8.0e-06, :after_filters_time=>6.0e-06, :action_time=>8.8e-05}
|
|
296
|
+
~ {:before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06, :action_time=>0.000823}
|
|
297
|
+
~ {:before_filters_time=>7.0e-06, :after_filters_time=>7.0e-06, :action_time=>0.000841}
|
|
298
|
+
~ Not Using Sessions
|
|
299
|
+
~ {:action_time=>8.9e-05, :before_filters_time=>8.0e-06, :after_filters_time=>7.0e-06}
|
|
300
|
+
~ {:action_time=>0.000828, :before_filters_time=>6.0e-06, :after_filters_time=>6.0e-06}
|
|
301
|
+
~ {:action_time=>0.00083, :before_filters_time=>8.0e-06, :after_filters_time=>7.0e-06}
|
|
302
|
+
~ Not Using Sessions
|
|
303
|
+
~ {:action_time=>0.000145, :before_filters_time=>8.0e-06, :after_filters_time=>5.0e-06}
|
|
304
|
+
~ {:action_time=>0.000796, :before_filters_time=>5.0e-06, :after_filters_time=>5.0e-06}
|
|
305
|
+
~ {:action_time=>0.000761, :before_filters_time=>7.0e-06, :after_filters_time=>5.0e-06}
|
|
306
|
+
~ Not Using Sessions
|
|
307
|
+
~ {:action_time=>0.000146, :before_filters_time=>8.0e-06, :after_filters_time=>5.0e-06}
|
|
308
|
+
~ {:action_time=>0.000797, :before_filters_time=>5.0e-06, :after_filters_time=>6.0e-06}
|
|
309
|
+
~ {:action_time=>0.000771, :before_filters_time=>6.0e-06, :after_filters_time=>5.0e-06}
|
|
310
|
+
~ Not Using Sessions
|
|
311
|
+
~ {:action_time=>0.000149, :before_filters_time=>7.0e-06, :after_filters_time=>5.0e-06}
|
|
312
|
+
~ {:action_time=>0.000813, :before_filters_time=>6.0e-06, :after_filters_time=>5.0e-06}
|
|
313
|
+
~ {:action_time=>0.000787, :before_filters_time=>5.0e-06, :after_filters_time=>6.0e-06}
|