merb-core 0.9.2
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/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,30 @@
|
|
|
1
|
+
class SpecHelperController < Merb::Controller
|
|
2
|
+
|
|
3
|
+
def index
|
|
4
|
+
Merb::Test::ControllerAssertionMock.called(:index)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
Merb::Test::ControllerAssertionMock.called(:show)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def edit
|
|
12
|
+
Merb::Test::ControllerAssertionMock.called(:edit)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new
|
|
16
|
+
Merb::Test::ControllerAssertionMock.called(:new)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create
|
|
20
|
+
Merb::Test::ControllerAssertionMock.called(:create)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def update
|
|
24
|
+
Merb::Test::ControllerAssertionMock.called(:update)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def destroy
|
|
28
|
+
Merb::Test::ControllerAssertionMock.called(:destroy)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
Merb.start :environment => 'test', :log_level => :fatal
|
|
4
|
+
|
|
5
|
+
Dir[File.join(File.dirname(__FILE__), "controllers/**/*.rb")].each do |f|
|
|
6
|
+
require f
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Merb::Test::MultipartRequestHelper do
|
|
10
|
+
|
|
11
|
+
describe "#dispatch_multipart_to" do
|
|
12
|
+
|
|
13
|
+
before(:all) do
|
|
14
|
+
@controller_klass = Merb::Test::DispatchController
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should dispatch to the given controller and action" do
|
|
18
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
19
|
+
|
|
20
|
+
dispatch_multipart_to(@controller_klass, :index)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should dispatch to the given controller and action with params" do
|
|
24
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
25
|
+
|
|
26
|
+
controller = dispatch_multipart_to(@controller_klass, :show, :name => "Fred")
|
|
27
|
+
controller.params[:name].should == "Fred"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should handle a file object when used as a param" do
|
|
31
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
32
|
+
file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
|
|
33
|
+
File.open( file_name ) do |file|
|
|
34
|
+
controller = dispatch_multipart_to(@controller_klass, :show, :my_file => file)
|
|
35
|
+
file_params = controller.params[:my_file]
|
|
36
|
+
file_params[:content_type].should == "text/plain"
|
|
37
|
+
file_params[:size].should == File.size(file_name)
|
|
38
|
+
file_params[:tempfile].should be_a_kind_of(File)
|
|
39
|
+
file_params[:filename].should == "multipart_upload_text_file.txt"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#multipart_post" do
|
|
45
|
+
before(:each) do
|
|
46
|
+
Merb::Router.prepare do |r|
|
|
47
|
+
r.resources :spec_helper_controller
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should post to the create action" do
|
|
52
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
|
|
53
|
+
multipart_post("/spec_helper_controller")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should post to the create action with params" do
|
|
57
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
|
|
58
|
+
controller = multipart_post("/spec_helper_controller", :name => "Harry")
|
|
59
|
+
controller.params[:name].should == "Harry"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should upload a file to the action using multipart" do
|
|
63
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
|
|
64
|
+
file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
|
|
65
|
+
File.open( file_name ) do |file|
|
|
66
|
+
controller = multipart_post("/spec_helper_controller", :my_file => file)
|
|
67
|
+
file_params = controller.params[:my_file]
|
|
68
|
+
file_params[:content_type].should == "text/plain"
|
|
69
|
+
file_params[:size].should == File.size(file_name)
|
|
70
|
+
file_params[:tempfile].should be_a_kind_of(File)
|
|
71
|
+
file_params[:filename].should == "multipart_upload_text_file.txt"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "#multipart_put" do
|
|
78
|
+
before(:each) do
|
|
79
|
+
Merb::Router.prepare do |r|
|
|
80
|
+
r.resources :spec_helper_controller
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
it "should put to the update action multipart" do
|
|
84
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
|
|
85
|
+
multipart_put("/spec_helper_controller/1")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should put to the update action with multipart params" do
|
|
89
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
|
|
90
|
+
controller = multipart_put("/spec_helper_controller/my_id", :name => "Harry")
|
|
91
|
+
controller.params[:name].should == "Harry"
|
|
92
|
+
controller.params[:id].should == "my_id"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should upload a file to the action using multipart" do
|
|
96
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
|
|
97
|
+
file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
|
|
98
|
+
File.open( file_name ) do |file|
|
|
99
|
+
controller = multipart_put("/spec_helper_controller/my_id", :my_file => file)
|
|
100
|
+
controller.params[:id].should == "my_id"
|
|
101
|
+
file_params = controller.params[:my_file]
|
|
102
|
+
file_params[:content_type].should == "text/plain"
|
|
103
|
+
file_params[:size].should == File.size(file_name)
|
|
104
|
+
file_params[:tempfile].should be_a_kind_of(File)
|
|
105
|
+
file_params[:filename].should == "multipart_upload_text_file.txt"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
module Merb::Test::MultipartRequestHelper
|
|
112
|
+
describe Param, '#to_multipart' do
|
|
113
|
+
it "should represent the key and value correctly" do
|
|
114
|
+
param = Param.new('foo', 'bar')
|
|
115
|
+
param.to_multipart.should == %(Content-Disposition: form-data; name="foo"\r\n\r\nbar\r\n)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe FileParam, '#to_multipart' do
|
|
120
|
+
it "should represent the key, filename and content correctly" do
|
|
121
|
+
param = FileParam.new('foo', '/bar.txt', 'baz')
|
|
122
|
+
param.to_multipart.should == %(Content-Disposition: form-data; name="foo"; filename="/bar.txt"\r\nContent-Type: text/plain\r\n\r\nbaz\r\n)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe Post, '#push_params(params) param parsing' do
|
|
127
|
+
before(:each) do
|
|
128
|
+
@fake_return_param = mock('fake return_param')
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should create Param from params when param doesn't respond to read" do
|
|
132
|
+
params = { 'normal' => 'normal_param' }
|
|
133
|
+
Param.should_receive(:new).with('normal', 'normal_param').and_return(@fake_return_param)
|
|
134
|
+
Post.new.push_params(params)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should create FileParam from params when param does response to read" do
|
|
138
|
+
file_param = mock('file param')
|
|
139
|
+
file_param.should_receive(:read).and_return('file contents')
|
|
140
|
+
file_param.should_receive(:path).and_return('file.txt')
|
|
141
|
+
params = { 'file' => file_param }
|
|
142
|
+
FileParam.should_receive(:new).with('file', 'file.txt', 'file contents').and_return(@fake_return_param)
|
|
143
|
+
Post.new.push_params(params)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
describe Post, '#to_multipart' do
|
|
148
|
+
it "should create a multipart request from the params" do
|
|
149
|
+
file_param = mock('file param')
|
|
150
|
+
file_param.should_receive(:read).and_return('file contents')
|
|
151
|
+
file_param.should_receive(:path).and_return('file.txt')
|
|
152
|
+
params = { 'file' => file_param, 'normal' => 'normal_param' }
|
|
153
|
+
multipart = Post.new(params)
|
|
154
|
+
query, content_type = multipart.to_multipart
|
|
155
|
+
content_type.should == "multipart/form-data, boundary=----------0xKhTmLbOuNdArY"
|
|
156
|
+
query.should == "------------0xKhTmLbOuNdArY\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\r\nContent-Type: text/plain\r\n\r\nfile contents\r\n------------0xKhTmLbOuNdArY\r\nContent-Disposition: form-data; name=\"normal\"\r\n\r\nnormal_param\r\n------------0xKhTmLbOuNdArY--"
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
File With Some Text In It For Testing Multipart Uploads
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
Merb.start :environment => 'test', :log_level => :fatal
|
|
4
|
+
|
|
5
|
+
Dir[File.join(File.dirname(__FILE__), "controllers/**/*.rb")].each do |f|
|
|
6
|
+
require f
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe Merb::Test::RequestHelper do
|
|
10
|
+
describe "#dispatch_to" do
|
|
11
|
+
|
|
12
|
+
before(:all) do
|
|
13
|
+
@controller_klass = Merb::Test::DispatchController
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should dispatch to the given controller and action" do
|
|
17
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
18
|
+
|
|
19
|
+
dispatch_to(@controller_klass, :index)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should dispatch to the given controller and action with params" do
|
|
23
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
24
|
+
|
|
25
|
+
controller = dispatch_to(@controller_klass, :show, :name => "Fred")
|
|
26
|
+
controller.params[:name].should == "Fred"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should not hit the router to match it's route" do
|
|
30
|
+
Merb::Router.should_not_receive(:match)
|
|
31
|
+
dispatch_to(@controller_klass, :index)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#get" do
|
|
36
|
+
before(:each) do
|
|
37
|
+
Merb::Router.prepare do |r|
|
|
38
|
+
r.resources :spec_helper_controller
|
|
39
|
+
r.match("/:controller/:action/:custom").to(:controller => ":controller")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should perform the index action when used with a get" do
|
|
44
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
45
|
+
get("/spec_helper_controller")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should perform the index action and have params available" do
|
|
49
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
50
|
+
controller = get("/spec_helper_controller", :name => "Harry")
|
|
51
|
+
controller.params[:name].should == "Harry"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should evaluate in the context of the controller in the block" do
|
|
55
|
+
get("/spec_helper_controller") do |controller|
|
|
56
|
+
controller.class.should == SpecHelperController
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should allow for custom router params" do
|
|
61
|
+
controller = get("/spec_helper_controller/index/my_custom_stuff")
|
|
62
|
+
controller.params[:custom].should == "my_custom_stuff"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should get the show action" do
|
|
66
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
67
|
+
controller = get("/spec_helper_controller/my_id")
|
|
68
|
+
controller.params[:id].should == "my_id"
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe "#post" do
|
|
73
|
+
before(:each) do
|
|
74
|
+
Merb::Router.prepare do |r|
|
|
75
|
+
r.resources :spec_helper_controller
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should post to the create action" do
|
|
80
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
|
|
81
|
+
post("/spec_helper_controller")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should post to the create action with params" do
|
|
85
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
|
|
86
|
+
controller = post("/spec_helper_controller", :name => "Harry")
|
|
87
|
+
controller.params[:name].should == "Harry"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
describe "#put" do
|
|
92
|
+
before(:each) do
|
|
93
|
+
Merb::Router.prepare do |r|
|
|
94
|
+
r.resources :spec_helper_controller
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
it "should put to the update action" do
|
|
98
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
|
|
99
|
+
put("/spec_helper_controller/1")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "should put to the update action with params" do
|
|
103
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
|
|
104
|
+
controller = put("/spec_helper_controller/my_id", :name => "Harry")
|
|
105
|
+
controller.params[:name].should == "Harry"
|
|
106
|
+
controller.params[:id].should == "my_id"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
describe "#delete" do
|
|
111
|
+
before(:each) do
|
|
112
|
+
Merb::Router.prepare do |r|
|
|
113
|
+
r.resources :spec_helper_controller
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
it "should put to the update action" do
|
|
117
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:destroy)
|
|
118
|
+
delete("/spec_helper_controller/1")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "should put to the update action with params" do
|
|
122
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:destroy)
|
|
123
|
+
controller = delete("/spec_helper_controller/my_id", :name => "Harry")
|
|
124
|
+
controller.params[:name].should == "Harry"
|
|
125
|
+
controller.params[:id].should == "my_id"
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
module Merb::Test::RequestHelper
|
|
131
|
+
describe FakeRequest, ".new(env = {}, req = StringIO.new)" do
|
|
132
|
+
it "should create request with default enviroment, minus rack.input" do
|
|
133
|
+
@mock = FakeRequest.new
|
|
134
|
+
@mock.env.except('rack.input').should == FakeRequest::DEFAULT_ENV
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should override default env values passed in HTTP format" do
|
|
138
|
+
@mock = FakeRequest.new('HTTP_ACCEPT' => 'nothing')
|
|
139
|
+
@mock.env['HTTP_ACCEPT'].should == 'nothing'
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it "should override default env values passed in symbol format" do
|
|
143
|
+
@mock = FakeRequest.new(:http_accept => 'nothing')
|
|
144
|
+
@mock.env['HTTP_ACCEPT'].should == 'nothing'
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should set rack input to an empty StringIO" do
|
|
148
|
+
@mock = FakeRequest.new
|
|
149
|
+
@mock.env['rack.input'].should be_kind_of(StringIO)
|
|
150
|
+
@mock.env['rack.input'].read.should == ''
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
class TestController < Merb::Controller
|
|
4
|
+
def get(id = nil); end
|
|
5
|
+
def post; end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
describe Merb::Test::RouteHelper do
|
|
9
|
+
before(:each) do
|
|
10
|
+
Merb::Router.prepare do |r|
|
|
11
|
+
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
|
|
12
|
+
r.match("/", :method => :post).to(:controller => "test_controller", :action => "post")
|
|
13
|
+
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "#url" do
|
|
18
|
+
it "should use Merb::Router" do
|
|
19
|
+
url(:getter).should == "/"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should work with a model as the parameter" do
|
|
23
|
+
model = mock(:model)
|
|
24
|
+
model.stub!(:id).and_return("123")
|
|
25
|
+
url(:with_id, model).should == "/123"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should work with a parameters hash" do
|
|
29
|
+
url(:with_id, :id => 123).should == "/123"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe "#request_to" do
|
|
34
|
+
it "should GET if no method is given" do
|
|
35
|
+
request_to("/")[:action].should == "get"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should return a hash" do
|
|
39
|
+
Hash.should === request_to("/")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should contain the controller in the result" do
|
|
43
|
+
request_to("/")[:controller].should == "test_controller"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should contain the action in the result" do
|
|
47
|
+
request_to("/")[:action].should == "get"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should contain any parameters in the result" do
|
|
51
|
+
request_to("/123")[:id].should == "123"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
|
+
|
|
3
|
+
Merb.start :environment => 'test', :log_level => :fatal
|
|
4
|
+
|
|
5
|
+
class TestController < Merb::Controller
|
|
6
|
+
def get(id = nil); end
|
|
7
|
+
def post; end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class IDish
|
|
11
|
+
attr_accessor :id
|
|
12
|
+
alias_method :to_param, :id
|
|
13
|
+
|
|
14
|
+
def initialize(id)
|
|
15
|
+
@id = id
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe Merb::Test::Rspec::RouteMatchers do
|
|
20
|
+
include Merb::Test::RouteHelper
|
|
21
|
+
|
|
22
|
+
before(:each) do
|
|
23
|
+
Merb::Router.prepare do |r|
|
|
24
|
+
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
|
|
25
|
+
r.match("/", :method => :post).to(:controller => "test_controller", :action => "post")
|
|
26
|
+
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "#route_to" do
|
|
31
|
+
it "should work with the request_to helper" do
|
|
32
|
+
request_to("/", :get).should route_to(TestController, :get)
|
|
33
|
+
request_to("/", :post).should_not route_to(TestController, :get)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should work with the url helper and ParamMatcher" do
|
|
37
|
+
idish = IDish.new(rand(1000).to_s)
|
|
38
|
+
request_to(url(:with_id, idish)).should route_to(TestController, :get).with(idish)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
module Merb::Test::Rspec::RouteMatchers
|
|
43
|
+
|
|
44
|
+
describe RouteToMatcher do
|
|
45
|
+
|
|
46
|
+
it "should work with snake cased controllers" do
|
|
47
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should work with camel cased controllers" do
|
|
51
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "TestController", :action => "get").should be_true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should work with symbol or string controller name" do
|
|
55
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
|
56
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => :test_controller, :action => :get)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should not pass if the controllers do not match" do
|
|
60
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "other_controller", :action => "get").should be_false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should not pass if the actions do not match" do
|
|
64
|
+
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "post").should be_false
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should not pass if the parameters do not the ParameterMatcher" do
|
|
68
|
+
route_matcher = RouteToMatcher.new(TestController, :get)
|
|
69
|
+
route_matcher.with(:id => "123")
|
|
70
|
+
|
|
71
|
+
route_matcher.matches?(:controller => "test_case", :action => "get", :id => "456").should be_false
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe "#with" do
|
|
75
|
+
it "should add a ParameterMatcher" do
|
|
76
|
+
ParameterMatcher.should_receive(:new).with(:id => "123")
|
|
77
|
+
|
|
78
|
+
route_matcher = RouteToMatcher.new(TestController, :get)
|
|
79
|
+
route_matcher.with(:id => "123")
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe "#failure_message" do
|
|
84
|
+
it "should include the expected controller and action" do
|
|
85
|
+
RouteToMatcher.new(TestController, :any_action).failure_message.should include("TestController#any_action")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "should include the target controller and action in camel case" do
|
|
89
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
|
90
|
+
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
|
91
|
+
matcher.failure_message.should include("TargetController#target_action")
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
describe "#negative_failure_message" do
|
|
96
|
+
it "should include the expected controller and action" do
|
|
97
|
+
RouteToMatcher.new(TestController, :any_action).negative_failure_message.should include("TestController#any_action")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
describe ParameterMatcher do
|
|
103
|
+
it "should work with a Hash as the parameter argument" do
|
|
104
|
+
ParameterMatcher.new(:param => "abc").matches?(:param => "abc").should be_true
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should work with an object as the parameter argument" do
|
|
108
|
+
ParameterMatcher.new(IDish.new(1234)).matches?(:id => 1234).should be_true
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
describe "#failure_message" do
|
|
112
|
+
it "should include the expected parameters hash" do
|
|
113
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
114
|
+
ParameterMatcher.new(parameter_hash).failure_message.should include(parameter_hash.inspect)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should include the actual parameters hash" do
|
|
118
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
119
|
+
matcher = ParameterMatcher.new(:id => 123)
|
|
120
|
+
matcher.matches?(parameter_hash)
|
|
121
|
+
matcher.failure_message.should include(parameter_hash.inspect)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
describe "#negative_failure_message" do
|
|
126
|
+
it "should include the expected parameters hash" do
|
|
127
|
+
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
128
|
+
ParameterMatcher.new(parameter_hash).negative_failure_message.should include(parameter_hash.inspect)
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|