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
|
@@ -22,9 +22,9 @@ describe Merb::Logger do
|
|
|
22
22
|
|
|
23
23
|
describe "#new" do
|
|
24
24
|
it "should call set_log with the arguments it was passed." do
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
logger = Merb::Logger.allocate # create an object sans initialization
|
|
26
|
+
logger.should_receive(:set_log).with('a partridge', 'a pear tree', 'a time bomb').and_return(true)
|
|
27
|
+
logger.send(:initialize, 'a partridge', 'a pear tree', 'a time bomb')
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -102,6 +102,12 @@ describe Merb::Logger do
|
|
|
102
102
|
@logger.close
|
|
103
103
|
end
|
|
104
104
|
|
|
105
|
+
it "shouldn't call the close method if the log is a terminal" do
|
|
106
|
+
@logger.log.should_receive(:tty?).and_return(true)
|
|
107
|
+
@logger.log.should_not_receive(:close)
|
|
108
|
+
@logger.close
|
|
109
|
+
end
|
|
110
|
+
|
|
105
111
|
it "should set the stored log attribute to nil" do
|
|
106
112
|
@logger.close
|
|
107
113
|
@logger.log.should eql(nil)
|
|
@@ -172,4 +178,4 @@ describe Merb::Logger do
|
|
|
172
178
|
|
|
173
179
|
end
|
|
174
180
|
|
|
175
|
-
end
|
|
181
|
+
end
|
|
@@ -57,3 +57,16 @@ Mon, 25 Feb 2008 23:13:22 GMT ~ Not Using Sessions
|
|
|
57
57
|
~ Not Using Sessions
|
|
58
58
|
~ Not Using Sessions
|
|
59
59
|
~ Not Using Sessions
|
|
60
|
+
~ Not Using Sessions
|
|
61
|
+
~ Not Using Sessions
|
|
62
|
+
~ Not Using Sessions
|
|
63
|
+
~ Not Using Sessions
|
|
64
|
+
~ Not Using Sessions
|
|
65
|
+
~ Not Using Sessions
|
|
66
|
+
~ Not Using Sessions
|
|
67
|
+
~ Not Using Sessions
|
|
68
|
+
~ Not Using Sessions
|
|
69
|
+
~ Not Using Sessions
|
|
70
|
+
~ Not Using Sessions
|
|
71
|
+
~ Not Using Sessions
|
|
72
|
+
~ Not Using Sessions
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
|
2
2
|
Merb.start :environment => 'test',
|
|
3
3
|
:merb_root => File.dirname(__FILE__) / "directory"
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
describe "The reloader" do
|
|
6
|
+
SLEEP_TIME = 0.5
|
|
6
7
|
|
|
7
8
|
def reload!
|
|
8
9
|
Merb::BootLoader::ReloadClasses.reload
|
|
9
10
|
end
|
|
10
|
-
|
|
11
|
+
|
|
11
12
|
before :all do
|
|
12
13
|
@reload_file = File.dirname(__FILE__) / "directory" / "app" / "controllers" / "reload.rb"
|
|
13
14
|
File.open(@reload_file, "w") do |f|
|
|
14
15
|
@text = <<-END
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
class Reloader < Application
|
|
17
18
|
end
|
|
18
19
|
|
|
@@ -21,20 +22,20 @@ describe "The reloader" do
|
|
|
21
22
|
END
|
|
22
23
|
f.puts @text
|
|
23
24
|
end
|
|
24
|
-
|
|
25
|
-
sleep
|
|
25
|
+
|
|
26
|
+
sleep SLEEP_TIME
|
|
26
27
|
end
|
|
27
|
-
|
|
28
|
+
|
|
28
29
|
it "should reload files that were changed" do
|
|
29
30
|
defined?(Hello).should_not be_nil
|
|
30
31
|
defined?(Reloader).should_not be_nil
|
|
31
32
|
defined?(Reloader2).should be_nil
|
|
32
|
-
|
|
33
|
-
sleep
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
sleep SLEEP_TIME
|
|
35
|
+
|
|
35
36
|
File.open(@reload_file, "w") do |f|
|
|
36
37
|
f.puts <<-END
|
|
37
|
-
|
|
38
|
+
|
|
38
39
|
class Reloader < Application
|
|
39
40
|
end
|
|
40
41
|
|
|
@@ -43,17 +44,17 @@ describe "The reloader" do
|
|
|
43
44
|
END
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
sleep
|
|
47
|
-
|
|
47
|
+
sleep SLEEP_TIME
|
|
48
|
+
|
|
48
49
|
defined?(Hello).should be_nil
|
|
49
50
|
defined?(Reloader).should_not be_nil
|
|
50
51
|
defined?(Reloader2).should_not be_nil
|
|
51
52
|
end
|
|
52
|
-
|
|
53
|
+
|
|
53
54
|
it "should remove classes for _abstract_subclasses" do
|
|
54
55
|
File.open(@reload_file, "w") do |f|
|
|
55
56
|
f.puts <<-END
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
class Reloader < Application
|
|
58
59
|
end
|
|
59
60
|
|
|
@@ -61,20 +62,20 @@ describe "The reloader" do
|
|
|
61
62
|
end
|
|
62
63
|
END
|
|
63
64
|
end
|
|
64
|
-
|
|
65
|
-
sleep
|
|
66
|
-
|
|
65
|
+
|
|
66
|
+
sleep SLEEP_TIME
|
|
67
|
+
|
|
67
68
|
Merb::AbstractController._abstract_subclasses.should include("Reloader")
|
|
68
|
-
Merb::AbstractController._abstract_subclasses.should include("Reloader2")
|
|
69
|
+
Merb::AbstractController._abstract_subclasses.should include("Reloader2")
|
|
69
70
|
defined?(Hello).should be_nil
|
|
70
71
|
defined?(Reloader).should_not be_nil
|
|
71
|
-
defined?(Reloader2).should_not be_nil
|
|
72
|
+
defined?(Reloader2).should_not be_nil
|
|
72
73
|
end
|
|
73
|
-
|
|
74
|
+
|
|
74
75
|
after :each do
|
|
75
|
-
sleep
|
|
76
|
+
sleep SLEEP_TIME
|
|
76
77
|
File.open(@reload_file, "w") do |f|
|
|
77
78
|
f.puts @text
|
|
78
79
|
end
|
|
79
80
|
end
|
|
80
|
-
end
|
|
81
|
+
end
|
|
@@ -45,6 +45,8 @@ describe Merb::Request, " query and body params" do
|
|
|
45
45
|
|
|
46
46
|
{"foo=bar&baz=bat" => {"foo" => "bar", "baz" => "bat"},
|
|
47
47
|
"foo[]=bar&foo[]=baz" => {"foo" => ["bar", "baz"]},
|
|
48
|
+
"foo[][bar]=1&foo[][bar]=2" => {"foo" => [{"bar" => "1"},{"bar" => "2"}]},
|
|
49
|
+
"foo[bar][][baz]=1&foo[bar][][baz]=2" => {"foo" => {"bar" => [{"baz" => "1"},{"baz" => "2"}]}},
|
|
48
50
|
"foo[1]=bar&foo[2]=baz" => {"foo" => {"1" => "bar", "2" => "baz"}}}.each do |query, parse|
|
|
49
51
|
|
|
50
52
|
it "should convert #{query.inspect} to #{parse.inspect} in the query string" do
|
|
@@ -12,6 +12,9 @@ Merb::Router.prepare do |r|
|
|
|
12
12
|
r.resource :foo do |f|
|
|
13
13
|
f.resources :comments
|
|
14
14
|
end
|
|
15
|
+
r.resources :domains, :keys => [:domain] do |d|
|
|
16
|
+
d.resources :emails, :keys => [:username]
|
|
17
|
+
end
|
|
15
18
|
end
|
|
16
19
|
|
|
17
20
|
describe "nested resources routes" do
|
|
@@ -31,4 +34,8 @@ describe "nested resources routes" do
|
|
|
31
34
|
it "should match a get to /foo/comments to the comments controller and index action" do
|
|
32
35
|
route_to('/foo/comments', :method => :get).should have_route(:controller => 'comments', :action => 'index', :id => nil)
|
|
33
36
|
end
|
|
37
|
+
|
|
38
|
+
it "should match a get to /domains/merbivore_com/emails to the emails controller and index action with domain => 'merbivore_com" do
|
|
39
|
+
route_to('/domains/merbivore_com/emails', :method => :get).should have_route(:controller => 'emails', :action => 'index', :username => nil, :domain => 'merbivore_com')
|
|
40
|
+
end
|
|
34
41
|
end
|
|
@@ -54,4 +54,49 @@ describe "resources routes" do
|
|
|
54
54
|
it "should match a get to /blogposts/1/delete to the blogposts controller and the delete action with id 1" do
|
|
55
55
|
route_to('/blogposts/1/delete', :method => :get).should have_route(:controller => 'blogposts', :action => 'delete', :id => "1")
|
|
56
56
|
end
|
|
57
|
-
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
describe "resources routes with named keys" do
|
|
61
|
+
before :each do
|
|
62
|
+
Merb::Router.prepare do |r|
|
|
63
|
+
r.resources :emails, :keys => ["username", "domain"]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should match a get to /emails/bidule/merbivore_com to the emails controller and the show action with username => 'bidule', domain => 'merbivore_com'" do
|
|
68
|
+
route_to('/emails/bidule/merbivore_com', :method => :get).should have_route(:controller => 'emails', :action => 'show', :username => "bidule", :domain => "merbivore_com")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should match a put to /emails/bidule/merbivore_com to the emails controller and the update action with username => 'bidule', domain => 'merbivore_com'" do
|
|
72
|
+
route_to('/emails/bidule/merbivore_com', :method => :put).should have_route(:controller => 'emails', :action => 'update', :username => "bidule", :domain => "merbivore_com")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should match a delete to /emails/bidule/merbivore_com to the emails controller and the destroy action with username => 'bidule', domain => 'merbivore_com'" do
|
|
76
|
+
route_to('/emails/bidule/merbivore_com', :method => :delete).should have_route(:controller => 'emails', :action => 'destroy', :username => "bidule", :domain => "merbivore_com")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should match a get to /emails/bidule/merbivore_com/edit to the emails controller and the destroy action with username => 'bidule', domain => 'merbivore_com'" do
|
|
80
|
+
route_to('/emails/bidule/merbivore_com/edit', :method => :get).should have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should match a get to /emails/bidule/merbivore_com;edit to the emails controller and the destroy action with username => 'bidule', domain => 'merbivore_com'" do
|
|
84
|
+
route_to('/emails/bidule/merbivore_com;edit', :method => :get).should have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "should not match a put to /emails/bidule/merbivore_com/edit" do
|
|
88
|
+
# not sure which of these is the best way to specify what I mean - so they're both in...
|
|
89
|
+
route_to('/emails/bidule/merbivore_com/edit', :method => :put).should have_nil_route
|
|
90
|
+
route_to('/emails/bidule/merbivore_com/edit', :method => :put).should_not have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "should not match a put to /emails/bidule/merbivore_com;edit" do
|
|
94
|
+
# not sure which of these is the best way to specify what I mean - so they're both in...
|
|
95
|
+
route_to('/emails/bidule/merbivore_com;edit', :method => :put).should have_nil_route
|
|
96
|
+
route_to('/emails/bidule/merbivore_com;edit', :method => :put).should_not have_route(:controller => 'emails', :action => 'edit', :username => "bidule", :domain => "merbivore_com")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should match a get to /emails/bidule/merbivore_com/delete to the emails controller and the delete action with username => 'bidule', domain => 'merbivore_com'" do
|
|
100
|
+
route_to('/emails/bidule/merbivore_com/delete', :method => :get).should have_route(:controller => 'emails', :action => 'delete', :username => "bidule", :domain => "merbivore_com")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -24,12 +24,16 @@ describe "Routes that are restricted based on incoming params" do
|
|
|
24
24
|
|
|
25
25
|
it "should allow you to restrict routes to POST requests" do
|
|
26
26
|
Merb::Router.prepare do |r|
|
|
27
|
-
r.match("/:controller/create/:id").
|
|
27
|
+
r.match("/:controller/create/:id", :method => :post).
|
|
28
28
|
to(:action => "create")
|
|
29
29
|
end
|
|
30
30
|
route_to("/foo/create/12", :method => "post").should have_route(
|
|
31
31
|
:controller => "foo", :action => "create", :id => "12"
|
|
32
32
|
)
|
|
33
|
+
|
|
34
|
+
route_to("/foo/create/12", :method => "get").should_not have_route(
|
|
35
|
+
:controller => "foo", :action => "create", :id => "12"
|
|
36
|
+
)
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
it "should allow you to restrict routes based on protocol" do
|
|
@@ -374,5 +374,29 @@ module Merb::Test::Rspec
|
|
|
374
374
|
end
|
|
375
375
|
end
|
|
376
376
|
end
|
|
377
|
+
|
|
378
|
+
describe Provide do
|
|
379
|
+
class TestController < Merb::Controller
|
|
380
|
+
provides :xml
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
it 'should match for formats a controller class provides' do
|
|
384
|
+
Provide.new( :xml ).matches?( TestController ).should be_true
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
it 'should match for formats a controller instance provides' do
|
|
388
|
+
t = TestController.new( fake_request )
|
|
389
|
+
Provide.new( :xml ).matches?( t ).should be_true
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
it 'should not match for formats a controller class does not provide' do
|
|
393
|
+
Provide.new( :yaml ).matches?( TestController ).should be_false
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
it 'should not match for formats a controller instance does not provide' do
|
|
397
|
+
t = TestController.new( fake_request )
|
|
398
|
+
Provide.new( :yaml ).matches?( t ).should be_false
|
|
399
|
+
end
|
|
400
|
+
end
|
|
377
401
|
end
|
|
378
|
-
end
|
|
402
|
+
end
|
|
@@ -27,4 +27,12 @@ class SpecHelperController < Merb::Controller
|
|
|
27
27
|
def destroy
|
|
28
28
|
Merb::Test::ControllerAssertionMock.called(:destroy)
|
|
29
29
|
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module Namespaced
|
|
33
|
+
class SpecHelperController < Merb::Controller
|
|
34
|
+
def index
|
|
35
|
+
Merb::Test::ControllerAssertionMock.called(:index)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
30
38
|
end
|
|
@@ -26,11 +26,46 @@ describe Merb::Test::RequestHelper do
|
|
|
26
26
|
controller.params[:name].should == "Fred"
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
it "should not hit the router to match
|
|
29
|
+
it "should not hit the router to match its route" do
|
|
30
30
|
Merb::Router.should_not_receive(:match)
|
|
31
31
|
dispatch_to(@controller_klass, :index)
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
|
+
|
|
35
|
+
describe "#dispatch_with_basic_authentication_to" do
|
|
36
|
+
|
|
37
|
+
before(:all) do
|
|
38
|
+
@controller_klass = Merb::Test::DispatchController
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should dispatch to the given controller and action" do
|
|
42
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
43
|
+
|
|
44
|
+
dispatch_with_basic_authentication_to(@controller_klass, :index, "Fred", "secret")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "should dispatch to the given controller and action with authentication token" do
|
|
48
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
49
|
+
|
|
50
|
+
controller = dispatch_with_basic_authentication_to(@controller_klass, :show, "Fred", "secret")
|
|
51
|
+
|
|
52
|
+
controller.request.env["X_HTTP_AUTHORIZATION"].should == "Basic #{Base64.encode64("Fred:secret")}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should dispatch to the given controller and action with authentication token and params" do
|
|
56
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
|
|
57
|
+
|
|
58
|
+
controller = dispatch_with_basic_authentication_to(@controller_klass, :show, "Fred", "secret", :name => "Fred")
|
|
59
|
+
|
|
60
|
+
controller.request.env["X_HTTP_AUTHORIZATION"].should == "Basic #{Base64.encode64("Fred:secret")}"
|
|
61
|
+
controller.params[:name].should == "Fred"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it "should not hit the router to match its route" do
|
|
65
|
+
Merb::Router.should_not_receive(:match)
|
|
66
|
+
dispatch_with_basic_authentication_to(@controller_klass, :index, "Fred", "secret")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
34
69
|
|
|
35
70
|
describe "#get" do
|
|
36
71
|
before(:each) do
|
|
@@ -125,6 +160,22 @@ describe Merb::Test::RequestHelper do
|
|
|
125
160
|
controller.params[:id].should == "my_id"
|
|
126
161
|
end
|
|
127
162
|
end
|
|
163
|
+
|
|
164
|
+
describe "#request" do
|
|
165
|
+
before(:each) do
|
|
166
|
+
Merb::Router.prepare do |r|
|
|
167
|
+
r.namespace :namespaced do |namespaced|
|
|
168
|
+
namespaced.resources :spec_helper_controller
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "should get namespaced index action" do
|
|
174
|
+
Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
|
|
175
|
+
controller = request("/namespaced/spec_helper_controller")
|
|
176
|
+
controller.class.should == Namespaced::SpecHelperController
|
|
177
|
+
end
|
|
178
|
+
end
|
|
128
179
|
end
|
|
129
180
|
|
|
130
181
|
module Merb::Test::RequestHelper
|
|
@@ -10,7 +10,7 @@ end
|
|
|
10
10
|
class IDish
|
|
11
11
|
attr_accessor :id
|
|
12
12
|
alias_method :to_param, :id
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def initialize(id)
|
|
15
15
|
@id = id
|
|
16
16
|
end
|
|
@@ -18,7 +18,7 @@ end
|
|
|
18
18
|
|
|
19
19
|
describe Merb::Test::Rspec::RouteMatchers do
|
|
20
20
|
include Merb::Test::RouteHelper
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
before(:each) do
|
|
23
23
|
Merb::Router.prepare do |r|
|
|
24
24
|
r.match("/", :method => :get).to(:controller => "test_controller", :action => "get").name(:getter)
|
|
@@ -26,94 +26,96 @@ describe Merb::Test::Rspec::RouteMatchers do
|
|
|
26
26
|
r.match("/:id").to(:controller => "test_controller", :action => "get").name(:with_id)
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
describe "#route_to" do
|
|
31
31
|
it "should work with the request_to helper" do
|
|
32
32
|
request_to("/", :get).should route_to(TestController, :get)
|
|
33
33
|
request_to("/", :post).should_not route_to(TestController, :get)
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
it "should work with the url helper and ParamMatcher" do
|
|
37
37
|
idish = IDish.new(rand(1000).to_s)
|
|
38
38
|
request_to(url(:with_id, idish)).should route_to(TestController, :get).with(idish)
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
module Merb::Test::Rspec::RouteMatchers
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
describe RouteToMatcher do
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
it "should work with snake cased controllers" do
|
|
47
47
|
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
it "should work with camel cased controllers" do
|
|
51
51
|
RouteToMatcher.new(TestController, :get).matches?(:controller => "TestController", :action => "get").should be_true
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
it "should work with symbol or string controller name" do
|
|
55
55
|
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "get").should be_true
|
|
56
56
|
RouteToMatcher.new(TestController, :get).matches?(:controller => :test_controller, :action => :get)
|
|
57
57
|
end
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
it "should not pass if the controllers do not match" do
|
|
60
60
|
RouteToMatcher.new(TestController, :get).matches?(:controller => "other_controller", :action => "get").should be_false
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
it "should not pass if the actions do not match" do
|
|
64
64
|
RouteToMatcher.new(TestController, :get).matches?(:controller => "test_controller", :action => "post").should be_false
|
|
65
65
|
end
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
it "should not pass if the parameters do not the ParameterMatcher" do
|
|
68
68
|
route_matcher = RouteToMatcher.new(TestController, :get)
|
|
69
69
|
route_matcher.with(:id => "123")
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
route_matcher.matches?(:controller => "test_case", :action => "get", :id => "456").should be_false
|
|
72
72
|
end
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
describe "#with" do
|
|
75
75
|
it "should add a ParameterMatcher" do
|
|
76
76
|
ParameterMatcher.should_receive(:new).with(:id => "123")
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
route_matcher = RouteToMatcher.new(TestController, :get)
|
|
79
79
|
route_matcher.with(:id => "123")
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
describe "#failure_message" do
|
|
84
84
|
it "should include the expected controller and action" do
|
|
85
|
-
RouteToMatcher.new(TestController, :any_action)
|
|
85
|
+
matcher = RouteToMatcher.new(TestController, :any_action)
|
|
86
|
+
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
|
87
|
+
matcher.failure_message.should include("TestController#any_action")
|
|
86
88
|
end
|
|
87
|
-
|
|
89
|
+
|
|
88
90
|
it "should include the target controller and action in camel case" do
|
|
89
91
|
matcher = RouteToMatcher.new(TestController, :any_action)
|
|
90
92
|
matcher.matches?(:controller => "target_controller", :action => "target_action")
|
|
91
93
|
matcher.failure_message.should include("TargetController#target_action")
|
|
92
94
|
end
|
|
93
95
|
end
|
|
94
|
-
|
|
96
|
+
|
|
95
97
|
describe "#negative_failure_message" do
|
|
96
98
|
it "should include the expected controller and action" do
|
|
97
99
|
RouteToMatcher.new(TestController, :any_action).negative_failure_message.should include("TestController#any_action")
|
|
98
100
|
end
|
|
99
101
|
end
|
|
100
102
|
end
|
|
101
|
-
|
|
103
|
+
|
|
102
104
|
describe ParameterMatcher do
|
|
103
105
|
it "should work with a Hash as the parameter argument" do
|
|
104
106
|
ParameterMatcher.new(:param => "abc").matches?(:param => "abc").should be_true
|
|
105
107
|
end
|
|
106
|
-
|
|
108
|
+
|
|
107
109
|
it "should work with an object as the parameter argument" do
|
|
108
110
|
ParameterMatcher.new(IDish.new(1234)).matches?(:id => 1234).should be_true
|
|
109
111
|
end
|
|
110
|
-
|
|
112
|
+
|
|
111
113
|
describe "#failure_message" do
|
|
112
114
|
it "should include the expected parameters hash" do
|
|
113
115
|
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
114
116
|
ParameterMatcher.new(parameter_hash).failure_message.should include(parameter_hash.inspect)
|
|
115
117
|
end
|
|
116
|
-
|
|
118
|
+
|
|
117
119
|
it "should include the actual parameters hash" do
|
|
118
120
|
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
119
121
|
matcher = ParameterMatcher.new(:id => 123)
|
|
@@ -121,7 +123,7 @@ describe Merb::Test::Rspec::RouteMatchers do
|
|
|
121
123
|
matcher.failure_message.should include(parameter_hash.inspect)
|
|
122
124
|
end
|
|
123
125
|
end
|
|
124
|
-
|
|
126
|
+
|
|
125
127
|
describe "#negative_failure_message" do
|
|
126
128
|
it "should include the expected parameters hash" do
|
|
127
129
|
parameter_hash = {:parent_id => "123", :child_id => "abc"}
|
|
@@ -130,4 +132,4 @@ describe Merb::Test::Rspec::RouteMatchers do
|
|
|
130
132
|
end
|
|
131
133
|
end
|
|
132
134
|
end
|
|
133
|
-
end
|
|
135
|
+
end
|