merb-core 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +285 -0
- data/TODO +0 -0
- data/bin/merb +8 -0
- data/bin/merb-specs +5 -0
- data/docs/bootloading.dox +57 -0
- data/docs/documentation_standards +40 -0
- data/docs/new_render_api +51 -0
- data/lib/merb-core.rb +304 -0
- data/lib/merb-core/autoload.rb +29 -0
- data/lib/merb-core/bootloader.rb +601 -0
- data/lib/merb-core/config.rb +284 -0
- data/lib/merb-core/constants.rb +43 -0
- data/lib/merb-core/controller/abstract_controller.rb +531 -0
- data/lib/merb-core/controller/exceptions.rb +257 -0
- data/lib/merb-core/controller/merb_controller.rb +214 -0
- data/lib/merb-core/controller/mime.rb +88 -0
- data/lib/merb-core/controller/mixins/controller.rb +262 -0
- data/lib/merb-core/controller/mixins/render.rb +324 -0
- data/lib/merb-core/controller/mixins/responder.rb +464 -0
- data/lib/merb-core/controller/template.rb +205 -0
- data/lib/merb-core/core_ext.rb +12 -0
- data/lib/merb-core/core_ext/class.rb +192 -0
- data/lib/merb-core/core_ext/hash.rb +422 -0
- data/lib/merb-core/core_ext/kernel.rb +304 -0
- data/lib/merb-core/core_ext/mash.rb +154 -0
- data/lib/merb-core/core_ext/object.rb +136 -0
- data/lib/merb-core/core_ext/object_space.rb +14 -0
- data/lib/merb-core/core_ext/rubygems.rb +28 -0
- data/lib/merb-core/core_ext/set.rb +41 -0
- data/lib/merb-core/core_ext/string.rb +69 -0
- data/lib/merb-core/dispatch/cookies.rb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +233 -0
- data/lib/merb-core/dispatch/exceptions.html.erb +297 -0
- data/lib/merb-core/dispatch/request.rb +560 -0
- data/lib/merb-core/dispatch/router.rb +141 -0
- data/lib/merb-core/dispatch/router/behavior.rb +777 -0
- data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
- data/lib/merb-core/dispatch/router/route.rb +212 -0
- data/lib/merb-core/dispatch/session.rb +28 -0
- data/lib/merb-core/dispatch/session/cookie.rb +166 -0
- data/lib/merb-core/dispatch/session/memcached.rb +161 -0
- data/lib/merb-core/dispatch/session/memory.rb +234 -0
- data/lib/merb-core/gem_ext/erubis.rb +19 -0
- data/lib/merb-core/logger.rb +230 -0
- data/lib/merb-core/plugins.rb +25 -0
- data/lib/merb-core/rack.rb +15 -0
- data/lib/merb-core/rack/adapter.rb +42 -0
- data/lib/merb-core/rack/adapter/ebb.rb +22 -0
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +24 -0
- data/lib/merb-core/rack/adapter/fcgi.rb +16 -0
- data/lib/merb-core/rack/adapter/irb.rb +108 -0
- data/lib/merb-core/rack/adapter/mongrel.rb +25 -0
- data/lib/merb-core/rack/adapter/runner.rb +27 -0
- data/lib/merb-core/rack/adapter/thin.rb +27 -0
- data/lib/merb-core/rack/adapter/webrick.rb +35 -0
- data/lib/merb-core/rack/application.rb +77 -0
- data/lib/merb-core/rack/handler/mongrel.rb +97 -0
- data/lib/merb-core/server.rb +184 -0
- data/lib/merb-core/test.rb +10 -0
- data/lib/merb-core/test/helpers.rb +9 -0
- data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
- data/lib/merb-core/test/helpers/request_helper.rb +257 -0
- data/lib/merb-core/test/helpers/route_helper.rb +33 -0
- data/lib/merb-core/test/helpers/view_helper.rb +121 -0
- data/lib/merb-core/test/matchers.rb +9 -0
- data/lib/merb-core/test/matchers/controller_matchers.rb +269 -0
- data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
- data/lib/merb-core/test/matchers/view_matchers.rb +293 -0
- data/lib/merb-core/test/run_specs.rb +38 -0
- data/lib/merb-core/test/tasks/spectasks.rb +39 -0
- data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
- data/lib/merb-core/test/test_ext/object.rb +14 -0
- data/lib/merb-core/vendor/facets.rb +2 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
- data/lib/merb-core/vendor/facets/inflect.rb +211 -0
- data/lib/merb-core/version.rb +11 -0
- data/spec/private/config/adapter_spec.rb +32 -0
- data/spec/private/config/config_spec.rb +139 -0
- data/spec/private/config/environment_spec.rb +13 -0
- data/spec/private/config/spec_helper.rb +1 -0
- data/spec/private/core_ext/hash_spec.rb +506 -0
- data/spec/private/core_ext/kernel_spec.rb +46 -0
- data/spec/private/core_ext/object_spec.rb +39 -0
- data/spec/private/core_ext/set_spec.rb +26 -0
- data/spec/private/core_ext/string_spec.rb +9 -0
- data/spec/private/dispatch/cookies_spec.rb +107 -0
- data/spec/private/dispatch/dispatch_spec.rb +26 -0
- data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
- data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
- data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
- data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
- data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
- data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
- data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
- data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
- data/spec/private/dispatch/fixture/config/init.rb +45 -0
- data/spec/private/dispatch/fixture/config/rack.rb +1 -0
- data/spec/private/dispatch/fixture/config/router.rb +35 -0
- data/spec/private/dispatch/fixture/log/development.log +1 -0
- data/spec/private/dispatch/fixture/log/merb.4000.pid +1 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +2040 -0
- data/spec/private/dispatch/fixture/log/production.log +1 -0
- data/spec/private/dispatch/fixture/merb.4000.pid +1 -0
- data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
- data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
- data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
- data/spec/private/dispatch/route_params_spec.rb +24 -0
- data/spec/private/dispatch/spec_helper.rb +1 -0
- data/spec/private/plugins/plugin_spec.rb +81 -0
- data/spec/private/rack/application_spec.rb +43 -0
- data/spec/public/DEFINITIONS +11 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/display.rb +54 -0
- data/spec/public/abstract_controller/controllers/filters.rb +167 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +31 -0
- data/spec/public/abstract_controller/controllers/partial.rb +106 -0
- data/spec/public/abstract_controller/controllers/render.rb +86 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
- data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
- data/spec/public/abstract_controller/display_spec.rb +33 -0
- data/spec/public/abstract_controller/filter_spec.rb +80 -0
- data/spec/public/abstract_controller/helper_spec.rb +13 -0
- data/spec/public/abstract_controller/partial_spec.rb +53 -0
- data/spec/public/abstract_controller/render_spec.rb +70 -0
- data/spec/public/abstract_controller/spec_helper.rb +27 -0
- data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
- data/spec/public/boot_loader/spec_helper.rb +1 -0
- data/spec/public/controller/base_spec.rb +31 -0
- data/spec/public/controller/controllers/base.rb +41 -0
- data/spec/public/controller/controllers/display.rb +40 -0
- data/spec/public/controller/controllers/responder.rb +67 -0
- data/spec/public/controller/controllers/url.rb +7 -0
- data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
- data/spec/public/controller/display_spec.rb +34 -0
- data/spec/public/controller/log/merb.4000.pid +1 -0
- data/spec/public/controller/responder_spec.rb +95 -0
- data/spec/public/controller/spec_helper.rb +9 -0
- data/spec/public/controller/url_spec.rb +152 -0
- data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
- data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
- data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
- data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
- data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
- data/spec/public/directory_structure/directory/config/router.rb +3 -0
- data/spec/public/directory_structure/directory/log/merb.4000.pid +1 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +265 -0
- data/spec/public/directory_structure/directory/merb.4000.pid +1 -0
- data/spec/public/directory_structure/directory_spec.rb +44 -0
- data/spec/public/logger/logger_spec.rb +175 -0
- data/spec/public/logger/spec_helper.rb +1 -0
- data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
- data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
- data/spec/public/reloading/directory/config/init.rb +2 -0
- data/spec/public/reloading/directory/log/merb.4000.pid +1 -0
- data/spec/public/reloading/directory/log/merb_test.log +59 -0
- data/spec/public/reloading/directory/merb.4000.pid +1 -0
- data/spec/public/reloading/reload_spec.rb +80 -0
- data/spec/public/request/multipart_spec.rb +15 -0
- data/spec/public/request/request_spec.rb +207 -0
- data/spec/public/router/default_spec.rb +21 -0
- data/spec/public/router/deferred_spec.rb +22 -0
- data/spec/public/router/namespace_spec.rb +113 -0
- data/spec/public/router/nested_resources_spec.rb +34 -0
- data/spec/public/router/resource_spec.rb +45 -0
- data/spec/public/router/resources_spec.rb +57 -0
- data/spec/public/router/spec_helper.rb +72 -0
- data/spec/public/router/special_spec.rb +44 -0
- data/spec/public/router/string_spec.rb +61 -0
- data/spec/public/template/template_spec.rb +92 -0
- data/spec/public/template/templates/error.html.erb +2 -0
- data/spec/public/template/templates/template.html.erb +1 -0
- data/spec/public/template/templates/template.html.myt +1 -0
- data/spec/public/test/controller_matchers_spec.rb +378 -0
- data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
- data/spec/public/test/controllers/dispatch_controller.rb +11 -0
- data/spec/public/test/controllers/spec_helper_controller.rb +30 -0
- data/spec/public/test/multipart_request_helper_spec.rb +159 -0
- data/spec/public/test/multipart_upload_text_file.txt +1 -0
- data/spec/public/test/request_helper_spec.rb +153 -0
- data/spec/public/test/route_helper_spec.rb +54 -0
- data/spec/public/test/route_matchers_spec.rb +133 -0
- data/spec/public/test/view_helper_spec.rb +96 -0
- data/spec/public/test/view_matchers_spec.rb +107 -0
- data/spec/spec_helper.rb +71 -0
- metadata +488 -0
@@ -0,0 +1 @@
|
|
1
|
+
7315
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
Merb.start :environment => 'test',
|
3
|
+
:merb_root => File.dirname(__FILE__) / "directory"
|
4
|
+
|
5
|
+
describe "The default Merb directory structure" do
|
6
|
+
|
7
|
+
it "should load in controllers" do
|
8
|
+
calling { Base }.should_not raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to complete the dispatch cycle" do
|
12
|
+
controller = dispatch_to(Base, :string)
|
13
|
+
controller.body.should == "String"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to complete the dispatch cycle with templates" do
|
17
|
+
controller = dispatch_to(Base, :template)
|
18
|
+
controller.body.should == "Template ERB"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Modifying the _template_path" do
|
24
|
+
|
25
|
+
it "should move the templates to a new location" do
|
26
|
+
controller = dispatch_to(Custom, :template)
|
27
|
+
controller.body.should == "Wonderful Template"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Merb.root_path" do
|
33
|
+
|
34
|
+
it "should return a path relative to Merb.root" do
|
35
|
+
path = Merb.root_path('/app/controllers/base.rb')
|
36
|
+
path.should == File.join(Merb.root, '/app/controllers/base.rb')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should accept multiple arguments like File.join" do
|
40
|
+
path = Merb.root_path('app', 'controllers', 'base.rb')
|
41
|
+
path.should == File.join(Merb.root, 'app', 'controllers', 'base.rb')
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Merb do
|
4
|
+
|
5
|
+
describe "Command Line Options" do
|
6
|
+
|
7
|
+
it "should allow -l / --log_level to set the log_level" do
|
8
|
+
pending("How do we spec these?")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow -L / --log_file to set the log_file" do
|
12
|
+
pending("How do we spec these?")
|
13
|
+
# Run an instance of merb from the command line
|
14
|
+
# using system and test if the file was created?
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Merb::Logger do
|
22
|
+
|
23
|
+
describe "#new" do
|
24
|
+
it "should call set_log with the arguments it was passed." do
|
25
|
+
pending("How do we catch an initialize in a spec?")
|
26
|
+
# Merb::Logger.should_receive(:set_log).with(Merb.log_file).and_return(true)
|
27
|
+
# Merb::Logger.new(Merb.log_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#set_log" do
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
@logger = Merb::Logger.new(Merb.log_file)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set the log level to :warn (4) when second parameter is :warn" do
|
38
|
+
Merb::Logger.new(Merb.log_file, :warn).level.should eql(4)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set the log level to :debug (0) when Merb.environment is development" do
|
42
|
+
Merb.should_receive(:environment).twice.and_return("development")
|
43
|
+
@logger.set_log(Merb.log_path / "development.log")
|
44
|
+
@logger.level.should eql(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the log level to :error (6) when Merb.environment is production" do
|
48
|
+
Merb.should_receive(:environment).twice.and_return("production")
|
49
|
+
@logger.set_log(Merb.log_path / "production.log")
|
50
|
+
@logger.level.should eql(4)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should initialize the buffer to an empty array" do
|
54
|
+
@logger.buffer.should eql([])
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should default the delimiter to ' ~ '" do
|
58
|
+
@logger.delimiter.should eql(" ~ ")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should assign the newly created object to Merb.logger" do
|
62
|
+
@logger = Merb::Logger.new(Merb.log_file)
|
63
|
+
Merb.logger.should eql(@logger)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#flush" do
|
69
|
+
|
70
|
+
before(:each) do
|
71
|
+
@logger = Merb::Logger.new(Merb.log_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should immediately return if the buffer is empty" do
|
75
|
+
@logger.should_not_receive(:write_method)
|
76
|
+
@logger.flush
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should call the write_method with the stringified contents of the buffer if the buffer is non-empty" do
|
80
|
+
@logger.send(:<<, "a message")
|
81
|
+
@logger.send(:<<, "another message")
|
82
|
+
@logger.log.should_receive(:write_method).with(" ~ a message\n ~ another message\n")
|
83
|
+
@logger.flush
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#close" do
|
89
|
+
before(:each) do
|
90
|
+
@logger = Merb::Logger.new(Merb.log_file)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should flush the buffer before closing" do
|
94
|
+
# TODO: how to specify order? eg. flush then close
|
95
|
+
@logger.should_receive(:flush)
|
96
|
+
@logger.log.should_receive(:close)
|
97
|
+
@logger.close
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call the close method if the log responds to close" do
|
101
|
+
@logger.log.should_receive(:close)
|
102
|
+
@logger.close
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should set the stored log attribute to nil" do
|
106
|
+
@logger.close
|
107
|
+
@logger.log.should eql(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "<<" do
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "level methods" do
|
117
|
+
|
118
|
+
before(:all) do
|
119
|
+
@logger = Merb::Logger.new(Merb.log_file)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should provide a #debug method which can be used to log" do
|
123
|
+
@logger.should respond_to(:debug)
|
124
|
+
@logger.should_receive(:<<).with("message").and_return(true)
|
125
|
+
@logger.debug("message")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should provide a #info method which can be used to log" do
|
129
|
+
@logger.should respond_to(:info)
|
130
|
+
@logger.should_receive(:<<).with("message").and_return(true)
|
131
|
+
@logger.info("message")
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should provide a #warn method which can be used to log" do
|
135
|
+
@logger.should respond_to(:warn)
|
136
|
+
@logger.should_receive(:<<).with("message").and_return(true)
|
137
|
+
@logger.warn("message")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should provide a #error method which can be used to log" do
|
141
|
+
@logger.should respond_to(:error)
|
142
|
+
@logger.should_receive(:<<).with("message").and_return(true)
|
143
|
+
@logger.error("message")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should provide a #fatal method which can be used to log" do
|
147
|
+
@logger.should respond_to(:fatal)
|
148
|
+
@logger.should_receive(:<<).with("message").and_return(true)
|
149
|
+
@logger.fatal("message")
|
150
|
+
end
|
151
|
+
|
152
|
+
# TODO: add positive and negative tests for each of the methods below:
|
153
|
+
it "should provide a #debug? method" do
|
154
|
+
@logger.should respond_to(:debug?)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should provide a #info? method" do
|
158
|
+
@logger.should respond_to(:info?)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should provide a #warn? method" do
|
162
|
+
@logger.should respond_to(:warn?)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should provide a #error? method" do
|
166
|
+
@logger.should respond_to(:error?)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should provide a #fatal? method" do
|
170
|
+
@logger.should respond_to(:fatal?)
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
@@ -0,0 +1 @@
|
|
1
|
+
6618
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Thu, 14 Feb 2008 17:24:16 GMT ~ info ~ Logfile created
|
2
|
+
Thu, 14 Feb 2008 17:24:16 GMT ~ Not Using Sessions
|
3
|
+
Thu, 14 Feb 2008 17:32:11 GMT ~ Not Using Sessions
|
4
|
+
Thu, 14 Feb 2008 17:34:04 GMT ~ Not Using Sessions
|
5
|
+
Thu, 14 Feb 2008 17:56:43 GMT ~ Not Using Sessions
|
6
|
+
Thu, 14 Feb 2008 17:57:29 GMT ~ Not Using Sessions
|
7
|
+
Thu, 14 Feb 2008 17:58:17 GMT ~ Not Using Sessions
|
8
|
+
Thu, 14 Feb 2008 21:20:41 GMT ~ Not Using Sessions
|
9
|
+
Fri, 15 Feb 2008 18:44:39 GMT ~ Not Using Sessions
|
10
|
+
Sun, 17 Feb 2008 15:32:32 GMT ~ Not Using Sessions
|
11
|
+
Sun, 17 Feb 2008 16:12:02 GMT ~ Not Using Sessions
|
12
|
+
Sun, 17 Feb 2008 16:21:37 GMT ~ Not Using Sessions
|
13
|
+
Mon, 25 Feb 2008 23:09:52 GMT ~ Not Using Sessions
|
14
|
+
Mon, 25 Feb 2008 23:11:49 GMT ~ Not Using Sessions
|
15
|
+
Mon, 25 Feb 2008 23:13:22 GMT ~ Not Using Sessions
|
16
|
+
~ Not Using Sessions
|
17
|
+
~ Not Using Sessions
|
18
|
+
~ Not Using Sessions
|
19
|
+
~ Not Using Sessions
|
20
|
+
~ Not Using Sessions
|
21
|
+
~ Not Using Sessions
|
22
|
+
~ Not Using Sessions
|
23
|
+
~ Not Using Sessions
|
24
|
+
~ Not Using Sessions
|
25
|
+
~ Not Using Sessions
|
26
|
+
~ Not Using Sessions
|
27
|
+
~ Not Using Sessions
|
28
|
+
~ Not Using Sessions
|
29
|
+
~ Not Using Sessions
|
30
|
+
~ Not Using Sessions
|
31
|
+
~ Not Using Sessions
|
32
|
+
~ Not Using Sessions
|
33
|
+
~ Not Using Sessions
|
34
|
+
~ Not Using Sessions
|
35
|
+
~ Not Using Sessions
|
36
|
+
~ Not Using Sessions
|
37
|
+
~ Not Using Sessions
|
38
|
+
~ Not Using Sessions
|
39
|
+
~ Not Using Sessions
|
40
|
+
~ Not Using Sessions
|
41
|
+
~ Not Using Sessions
|
42
|
+
~ Not Using Sessions
|
43
|
+
~ Not Using Sessions
|
44
|
+
~ Not Using Sessions
|
45
|
+
~ Not Using Sessions
|
46
|
+
~ Not Using Sessions
|
47
|
+
~ Not Using Sessions
|
48
|
+
~ Not Using Sessions
|
49
|
+
~ Not Using Sessions
|
50
|
+
~ Not Using Sessions
|
51
|
+
~ Not Using Sessions
|
52
|
+
~ Not Using Sessions
|
53
|
+
~ Not Using Sessions
|
54
|
+
~ Not Using Sessions
|
55
|
+
~ Not Using Sessions
|
56
|
+
~ Not Using Sessions
|
57
|
+
~ Not Using Sessions
|
58
|
+
~ Not Using Sessions
|
59
|
+
~ Not Using Sessions
|
@@ -0,0 +1 @@
|
|
1
|
+
7319
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
Merb.start :environment => 'test',
|
3
|
+
:merb_root => File.dirname(__FILE__) / "directory"
|
4
|
+
|
5
|
+
describe "The reloader" do
|
6
|
+
|
7
|
+
def reload!
|
8
|
+
Merb::BootLoader::ReloadClasses.reload
|
9
|
+
end
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
@reload_file = File.dirname(__FILE__) / "directory" / "app" / "controllers" / "reload.rb"
|
13
|
+
File.open(@reload_file, "w") do |f|
|
14
|
+
@text = <<-END
|
15
|
+
|
16
|
+
class Reloader < Application
|
17
|
+
end
|
18
|
+
|
19
|
+
class Hello < Application
|
20
|
+
end
|
21
|
+
END
|
22
|
+
f.puts @text
|
23
|
+
end
|
24
|
+
|
25
|
+
sleep 0.6
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should reload files that were changed" do
|
29
|
+
defined?(Hello).should_not be_nil
|
30
|
+
defined?(Reloader).should_not be_nil
|
31
|
+
defined?(Reloader2).should be_nil
|
32
|
+
|
33
|
+
sleep 0.6
|
34
|
+
|
35
|
+
File.open(@reload_file, "w") do |f|
|
36
|
+
f.puts <<-END
|
37
|
+
|
38
|
+
class Reloader < Application
|
39
|
+
end
|
40
|
+
|
41
|
+
class Reloader2
|
42
|
+
end
|
43
|
+
END
|
44
|
+
end
|
45
|
+
|
46
|
+
sleep 0.6
|
47
|
+
|
48
|
+
defined?(Hello).should be_nil
|
49
|
+
defined?(Reloader).should_not be_nil
|
50
|
+
defined?(Reloader2).should_not be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should remove classes for _abstract_subclasses" do
|
54
|
+
File.open(@reload_file, "w") do |f|
|
55
|
+
f.puts <<-END
|
56
|
+
|
57
|
+
class Reloader < Application
|
58
|
+
end
|
59
|
+
|
60
|
+
class Reloader2 < Application
|
61
|
+
end
|
62
|
+
END
|
63
|
+
end
|
64
|
+
|
65
|
+
sleep 0.6
|
66
|
+
|
67
|
+
Merb::AbstractController._abstract_subclasses.should include("Reloader")
|
68
|
+
Merb::AbstractController._abstract_subclasses.should include("Reloader2")
|
69
|
+
defined?(Hello).should be_nil
|
70
|
+
defined?(Reloader).should_not be_nil
|
71
|
+
defined?(Reloader2).should_not be_nil
|
72
|
+
end
|
73
|
+
|
74
|
+
after :each do
|
75
|
+
sleep 0.6
|
76
|
+
File.open(@reload_file, "w") do |f|
|
77
|
+
f.puts @text
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
require "mongrel"
|
3
|
+
|
4
|
+
describe Merb::Request do
|
5
|
+
it "should handle file upload for multipart/form-data posts" do
|
6
|
+
file = Struct.new(:read, :filename, :path).
|
7
|
+
new("This is a text file with some small content in it.", "sample.txt", "sample.txt")
|
8
|
+
m = Merb::Test::MultipartRequestHelper::Post.new :file => file
|
9
|
+
body, head = m.to_multipart
|
10
|
+
request = fake_request({:request_method => "POST", :content_type => head, :content_length => body.length}, :req => body)
|
11
|
+
request.params[:file].should_not be_nil
|
12
|
+
request.params[:file][:tempfile].class.should == Tempfile
|
13
|
+
request.params[:file][:content_type].should == 'text/plain'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
2
|
+
require "mongrel"
|
3
|
+
|
4
|
+
describe Merb::Request, "#method" do
|
5
|
+
|
6
|
+
[:get, :head, :put, :delete].each do |method|
|
7
|
+
it "should use the HTTP if it was a #{method.to_s.upcase}" do
|
8
|
+
fake_request(:request_method => method.to_s).method.should == method
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should use the _method body params for #{method.to_s.upcase} when it came in as a POST" do
|
12
|
+
request = fake_request({:request_method => "POST"}, :post_body => "_method=#{method}")
|
13
|
+
request.method.should == method
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should use the _method query params for #{method.to_s.upcase} when it came in as a POST" do
|
17
|
+
Merb::Request.parse_multipart_params = false
|
18
|
+
request = fake_request(:request_method => "POST", :query_string => "_method=#{method}")
|
19
|
+
request.method.should == method
|
20
|
+
end
|
21
|
+
|
22
|
+
[:get, :head, :put, :delete].each do |meth|
|
23
|
+
it "should return #{method == meth} when calling #{meth}? and the method is :#{method}" do
|
24
|
+
request = fake_request({:request_method => method.to_s})
|
25
|
+
request.send("#{meth}?").should == (method == meth)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should default to POST if the _method is not defined" do
|
31
|
+
request = fake_request({:request_method => "POST"}, :post_body => "_method=zed")
|
32
|
+
request.method.should == :post
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should raise an error if an unknown method is used" do
|
36
|
+
request = fake_request({:request_method => "foo"})
|
37
|
+
running {request.method}.should raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe Merb::Request, " query and body params" do
|
43
|
+
|
44
|
+
before(:all) { Merb::BootLoader::Dependencies.enable_json_gem }
|
45
|
+
|
46
|
+
{"foo=bar&baz=bat" => {"foo" => "bar", "baz" => "bat"},
|
47
|
+
"foo[]=bar&foo[]=baz" => {"foo" => ["bar", "baz"]},
|
48
|
+
"foo[1]=bar&foo[2]=baz" => {"foo" => {"1" => "bar", "2" => "baz"}}}.each do |query, parse|
|
49
|
+
|
50
|
+
it "should convert #{query.inspect} to #{parse.inspect} in the query string" do
|
51
|
+
request = fake_request({:query_string => query})
|
52
|
+
request.stub!(:route_params).and_return({})
|
53
|
+
request.params.should == parse
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should convert #{query.inspect} to #{parse.inspect} in the post body" do
|
57
|
+
request = fake_request({}, :post_body => query)
|
58
|
+
request.stub!(:route_params).and_return({})
|
59
|
+
request.params.should == parse
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should support JSON params" do
|
65
|
+
request = fake_request({:content_type => "application/json"}, :req => %{{"foo": "bar"}})
|
66
|
+
request.stub!(:route_params).and_return({})
|
67
|
+
request.params.should == {"foo" => "bar"}
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should support XML params" do
|
71
|
+
request = fake_request({:content_type => "application/xml"}, :req => %{<foo bar="baz"><baz/></foo>})
|
72
|
+
request.stub!(:route_params).and_return({})
|
73
|
+
request.params.should == {"foo" => {"baz" => nil, "bar" => "baz"}}
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe Merb::Request, "#remote_ip" do
|
79
|
+
it "should be able to get the remote IP of a request with X_FORWARDED_FOR" do
|
80
|
+
request = fake_request({:http_x_forwarded_for => "www.example.com"})
|
81
|
+
request.remote_ip.should == "www.example.com"
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be able to get the remote IP when some of the X_FORWARDED_FOR are local" do
|
85
|
+
request = fake_request({:http_x_forwarded_for => "192.168.2.1,127.0.0.1,www.example.com"})
|
86
|
+
request.remote_ip.should == "www.example.com"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be able to get the remote IP when it's in REMOTE_ADDR" do
|
90
|
+
request = fake_request({:remote_addr => "www.example.com"})
|
91
|
+
request.remote_ip.should == "www.example.com"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe Merb::Request, "#cookies" do
|
96
|
+
|
97
|
+
it "should take cookies in the HTTP_COOKIE environment variable" do
|
98
|
+
request = fake_request({:http_cookie => "merb=canhascookie; version=1"})
|
99
|
+
request.cookies.should == {"merb" => "canhascookie", "version" => "1"}
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should handle badly formatted cookies" do
|
103
|
+
request = fake_request({:http_cookie => "merb=; ; also=hats"})
|
104
|
+
request.cookies.should == {"merb" => "", "also" => "hats", "" => nil}
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Merb::Request, " misc" do
|
110
|
+
|
111
|
+
it "should know if a request is an XHR" do
|
112
|
+
request = fake_request({:http_x_requested_with => "XMLHttpRequest"})
|
113
|
+
request.should be_xhr
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should know if the protocol is http or https (when HTTPS is on)" do
|
117
|
+
request = fake_request({:https => "on"})
|
118
|
+
request.protocol.should == "https://"
|
119
|
+
request.should be_ssl
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should know if the protocol is http or https (when HTTP_X_FORWARDED_PROTO is https)" do
|
123
|
+
request = fake_request({:http_x_forwarded_proto => "https"})
|
124
|
+
request.protocol.should == "https://"
|
125
|
+
request.should be_ssl
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should know if the protocol is http or https (when it's regular HTTP)" do
|
129
|
+
request = fake_request({})
|
130
|
+
request.protocol.should == "http://"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should get the content-length" do
|
134
|
+
request = fake_request({:content_length => "300"})
|
135
|
+
request.content_length.should == 300
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should be able to get the path from the URI (stripping trailing /)" do
|
139
|
+
request = fake_request({:request_uri => "foo/bar/baz/?bat"})
|
140
|
+
request.path.should == "foo/bar/baz"
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should be able to get the path from the URI (joining multiple //)" do
|
144
|
+
request = fake_request({:request_uri => "foo/bar//baz/?bat"})
|
145
|
+
request.path.should == "foo/bar/baz"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should get the remote port" do
|
149
|
+
request = fake_request({:server_port => "80"})
|
150
|
+
request.port.should == 80
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should get the parts of the remote subdomain" do
|
154
|
+
request = fake_request({:http_host => "zoo.boom.foo.com"})
|
155
|
+
request.subdomains.should == ["zoo", "boom"]
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should get the parts of the remote subdomain when there's an irregular TLD number" do
|
159
|
+
request = fake_request({:http_host => "foo.bar.co.uk"})
|
160
|
+
request.subdomains(2).should == ["foo"]
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should get the full domain (not including subdomains and not including the port)" do
|
164
|
+
request = fake_request({:http_host => "www.foo.com:80"})
|
165
|
+
request.domain.should == "foo.com"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should get the full domain from an irregular TLD" do
|
169
|
+
request = fake_request({:http_host => "www.foo.co.uk:80"})
|
170
|
+
request.domain(2).should == "foo.co.uk"
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should get the host (with X_FORWARDED_HOST)" do
|
174
|
+
request = fake_request({:http_x_forwarded_host => "www.example.com"})
|
175
|
+
request.host.should == "www.example.com"
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should get the host (without X_FORWARDED_HOST)" do
|
179
|
+
request = fake_request({:http_host => "www.example.com"})
|
180
|
+
request.host.should == "www.example.com"
|
181
|
+
end
|
182
|
+
|
183
|
+
{:http_referer => ["referer", "http://referer.com"],
|
184
|
+
:request_uri => ["uri", "http://uri.com/uri"],
|
185
|
+
:http_user_agent => ["user_agent", "mozilla"],
|
186
|
+
:server_name => ["server_name", "apache"],
|
187
|
+
:http_accept_encoding => ["accept_encoding", "application/json"],
|
188
|
+
:script_name => ["script_name", "foo"],
|
189
|
+
:http_cache_control => ["cache_control", "no-cache"],
|
190
|
+
:http_accept_language => ["accept_language", "en"],
|
191
|
+
:server_software => ["server_software", "apache"],
|
192
|
+
:http_keep_alive => ["keep_alive", "300"],
|
193
|
+
:http_accept_charset => ["accept_charset", "UTF-8"],
|
194
|
+
:http_version => ["version", "1.1"],
|
195
|
+
:gateway_inteface => ["gateway", "CGI/1.2"],
|
196
|
+
:http_connection => ["connection", "keep-alive"],
|
197
|
+
:path_info => ["path_info", "foo/bar/baz"],
|
198
|
+
}.each do |env, vars|
|
199
|
+
|
200
|
+
it "should be able to get the #{env.to_s.upcase}" do
|
201
|
+
request = fake_request({env => vars[1]})
|
202
|
+
request.send(vars[0]).should == vars[1]
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|