merb 0.4.2 → 0.5.0

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.
Files changed (108) hide show
  1. data/README +21 -14
  2. data/Rakefile +157 -108
  3. data/SVN_REVISION +1 -0
  4. data/app_generators/merb/templates/Rakefile +20 -4
  5. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +1 -1
  6. data/app_generators/merb/templates/config/boot.rb +1 -1
  7. data/app_generators/merb/templates/config/dependencies.rb +3 -3
  8. data/app_generators/merb/templates/config/merb.yml +5 -0
  9. data/app_generators/merb/templates/config/merb_init.rb +3 -3
  10. data/app_generators/merb/templates/script/destroy +3 -0
  11. data/app_generators/merb/templates/script/generate +1 -1
  12. data/app_generators/merb/templates/spec/spec_helper.rb +2 -2
  13. data/app_generators/merb/templates/test/test_helper.rb +1 -1
  14. data/app_generators/merb_plugin/merb_plugin_generator.rb +4 -0
  15. data/bin/merb +1 -3
  16. data/lib/merb.rb +144 -76
  17. data/lib/merb/abstract_controller.rb +6 -5
  18. data/lib/merb/assets.rb +119 -0
  19. data/lib/merb/boot_loader.rb +217 -0
  20. data/lib/merb/caching.rb +1 -1
  21. data/lib/merb/caching/action_cache.rb +1 -1
  22. data/lib/merb/caching/fragment_cache.rb +1 -1
  23. data/lib/merb/caching/store/file_cache.rb +1 -1
  24. data/lib/merb/config.rb +290 -0
  25. data/lib/merb/controller.rb +5 -5
  26. data/lib/merb/core_ext/get_args.rb +1 -0
  27. data/lib/merb/core_ext/hash.rb +182 -169
  28. data/lib/merb/core_ext/kernel.rb +57 -26
  29. data/lib/merb/dispatcher.rb +6 -6
  30. data/lib/merb/drb_server.rb +1 -1
  31. data/lib/merb/generators/merb_generator_helpers.rb +7 -6
  32. data/lib/merb/logger.rb +1 -1
  33. data/lib/merb/mail_controller.rb +3 -4
  34. data/lib/merb/mailer.rb +2 -2
  35. data/lib/merb/mixins/basic_authentication.rb +2 -2
  36. data/lib/merb/mixins/controller.rb +1 -1
  37. data/lib/merb/mixins/general_controller.rb +13 -20
  38. data/lib/merb/mixins/inline_partial.rb +32 -0
  39. data/lib/merb/mixins/render.rb +3 -3
  40. data/lib/merb/mixins/responder.rb +1 -1
  41. data/lib/merb/mixins/view_context.rb +159 -33
  42. data/lib/merb/mongrel_handler.rb +9 -9
  43. data/lib/merb/plugins.rb +1 -1
  44. data/lib/merb/request.rb +25 -1
  45. data/lib/merb/router.rb +264 -226
  46. data/lib/merb/server.rb +66 -560
  47. data/lib/merb/session/cookie_store.rb +14 -13
  48. data/lib/merb/session/mem_cache_session.rb +20 -10
  49. data/lib/merb/session/memory_session.rb +21 -11
  50. data/lib/merb/template.rb +2 -2
  51. data/lib/merb/template/erubis.rb +3 -33
  52. data/lib/merb/template/haml.rb +8 -3
  53. data/lib/merb/test/fake_request.rb +8 -3
  54. data/lib/merb/test/helper.rb +66 -22
  55. data/lib/merb/test/rspec.rb +9 -155
  56. data/lib/merb/test/rspec_matchers/controller_matchers.rb +117 -0
  57. data/lib/merb/test/rspec_matchers/markup_matchers.rb +98 -0
  58. data/lib/merb/upload_handler.rb +2 -1
  59. data/lib/merb/version.rb +38 -3
  60. data/lib/merb/view_context.rb +1 -2
  61. data/lib/tasks/merb.rake +11 -11
  62. data/merb_generators/part_controller/USAGE +5 -0
  63. data/merb_generators/part_controller/part_controller_generator.rb +27 -0
  64. data/merb_generators/part_controller/templates/controller.rb +8 -0
  65. data/merb_generators/part_controller/templates/helper.rb +5 -0
  66. data/merb_generators/part_controller/templates/index.html.erb +3 -0
  67. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +1 -1
  68. data/script/destroy +14 -0
  69. data/script/generate +14 -0
  70. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +9 -1
  71. data/spec/fixtures/controllers/render_spec_controllers.rb +5 -5
  72. data/spec/fixtures/models/router_spec_models.rb +10 -0
  73. data/spec/merb/abstract_controller_spec.rb +2 -2
  74. data/spec/merb/assets_spec.rb +207 -0
  75. data/spec/merb/caching_spec.rb +2 -2
  76. data/spec/merb/controller_spec.rb +7 -2
  77. data/spec/merb/cookie_store_spec.rb +1 -1
  78. data/spec/merb/core_ext/class_spec.rb +97 -0
  79. data/spec/merb/core_ext/enumerable_spec.rb +27 -0
  80. data/spec/merb/core_ext/hash_spec.rb +251 -0
  81. data/spec/merb/core_ext/inflector_spec.rb +34 -0
  82. data/spec/merb/core_ext/kernel_spec.rb +25 -0
  83. data/spec/merb/core_ext/numeric_spec.rb +26 -0
  84. data/spec/merb/core_ext/object_spec.rb +47 -0
  85. data/spec/merb/core_ext/string_spec.rb +22 -0
  86. data/spec/merb/core_ext/symbol_spec.rb +7 -0
  87. data/spec/merb/dependency_spec.rb +22 -0
  88. data/spec/merb/dispatch_spec.rb +23 -12
  89. data/spec/merb/fake_request_spec.rb +8 -0
  90. data/spec/merb/generator_spec.rb +140 -21
  91. data/spec/merb/handler_spec.rb +5 -5
  92. data/spec/merb/mail_controller_spec.rb +3 -3
  93. data/spec/merb/render_spec.rb +1 -1
  94. data/spec/merb/responder_spec.rb +3 -3
  95. data/spec/merb/router_spec.rb +260 -191
  96. data/spec/merb/server_spec.rb +5 -5
  97. data/spec/merb/upload_handler_spec.rb +7 -0
  98. data/spec/merb/version_spec.rb +33 -0
  99. data/spec/merb/view_context_spec.rb +217 -59
  100. data/spec/spec_generator_helper.rb +15 -0
  101. data/spec/spec_helper.rb +5 -3
  102. data/spec/spec_helpers/url_shared_behaviour.rb +5 -7
  103. metadata +32 -7
  104. data/lib/merb/caching/store/memcache.rb +0 -20
  105. data/lib/merb/mixins/form_control.rb +0 -332
  106. data/lib/patch +0 -69
  107. data/spec/merb/core_ext_spec.rb +0 -464
  108. data/spec/merb/form_control_mixin_spec.rb +0 -431
@@ -7,7 +7,7 @@ describe MerbHandler, "process" do
7
7
  end
8
8
 
9
9
  def log_info_with( with_param )
10
- MERB_LOGGER.should_receive(:info).with( with_param )
10
+ Merb.logger.should_receive(:info).with( with_param )
11
11
  end
12
12
 
13
13
  before(:each) do
@@ -36,7 +36,7 @@ describe MerbHandler, "process" do
36
36
  @action = "ACTION"
37
37
  Merb::Dispatcher.stub!( :handle ).and_return( [@controller, @action] )
38
38
 
39
- MERB_LOGGER.stub!(:info)
39
+ Merb.logger.stub!(:info)
40
40
  end
41
41
 
42
42
  it "should return nil if the socket is closed" do
@@ -44,7 +44,7 @@ describe MerbHandler, "process" do
44
44
  do_process.should be_nil
45
45
  end
46
46
 
47
- it "should log the request URI to the MERB_LOGGER.info" do
47
+ it "should log the request URI to the Merb.logger.info" do
48
48
  log_info_with( /REQUEST_URI/ )
49
49
  do_process
50
50
  end
@@ -66,7 +66,7 @@ describe MerbHandler, "process" do
66
66
  end
67
67
 
68
68
  it "should ask the Dispatcher for the controller and action" do
69
- Merb::Dispatcher.should_receive( :handle ).with( @request, @response )
69
+ Merb::Dispatcher.should_receive( :handle ).with( @request, @response ).and_return( [@controller, @action] )
70
70
  do_process
71
71
  end
72
72
 
@@ -75,7 +75,7 @@ describe MerbHandler, "process" do
75
75
  @head = {}
76
76
  Merb::Dispatcher.should_receive( :handle ).and_raise( Exception )
77
77
  @response.should_receive( :send_status ).with( 500 )
78
- MERB_LOGGER.should_receive(:error)
78
+ Merb.logger.should_receive(:error)
79
79
  do_process
80
80
  end
81
81
 
@@ -5,8 +5,8 @@ module Merb
5
5
  self._template_root = File.expand_path(File.join(File.dirname(__FILE__), '..', "fixtures/mailers/views"))
6
6
  end
7
7
  end
8
- Merb::Server.load_controller_template_path_cache
9
- Merb::Server.load_erubis_inline_helpers
8
+ Merb::BootLoader.load_controller_template_path_cache
9
+ Merb::BootLoader.load_inline_helpers
10
10
 
11
11
  class Merb::Mailer
12
12
  self.delivery_method = :test_send
@@ -138,7 +138,7 @@ describe "A Merb Mail controller" do
138
138
  end
139
139
 
140
140
  it "should log an error if there are no templates available" do
141
- MERB_LOGGER.should_receive(:error).once
141
+ Merb.logger.should_receive(:error).once
142
142
  deliver :tenth
143
143
  end
144
144
 
@@ -152,7 +152,7 @@ describe "rendering engines except XMLBuilder", :shared => true do
152
152
  end
153
153
 
154
154
  [true, false].each do |cache|
155
- Merb::Server.config[:cache_templates] = cache
155
+ Merb::Config[:cache_templates] = cache
156
156
 
157
157
  describe "Merb rendering in general#{" (caching enabled)" if cache}" do
158
158
  it "should render inline with Erubis" do
@@ -242,9 +242,9 @@ class CrazyResponderSpecController < Merb::Controller
242
242
  end
243
243
  end
244
244
 
245
- Merb::Server.load_action_arguments
246
- Merb::Server.load_controller_template_path_cache
247
- Merb::Server.load_erubis_inline_helpers
245
+ Merb::BootLoader.load_action_arguments
246
+ Merb::BootLoader.load_controller_template_path_cache
247
+ Merb::BootLoader.load_inline_helpers
248
248
 
249
249
  describe "A Merb Responder's Content Negotiation" do
250
250
 
@@ -3,11 +3,24 @@ require 'benchmark'
3
3
  include Benchmark
4
4
 
5
5
  require FIXTURES / 'models/router_spec_models'
6
- $TESTING = true
7
6
 
8
- # OpenStruct fails to return 'method' correctly, which we require for our Request object
7
+ # OpenStruct fails to return :method correctly,
8
+ # which we require for our Request object.
9
9
  class SimpleRequest < OpenStruct
10
- def method() @table[:method] end
10
+ def method
11
+ @table[:method]
12
+ end
13
+ end
14
+
15
+ def generate(*args)
16
+ Merb::Router.generate *args
17
+ end
18
+
19
+ describe 'generate helper' do
20
+ it 'should reference Merb::Router method of the same name' do
21
+ Merb::Router.should_receive(:generate).with(:test)
22
+ generate :test
23
+ end
11
24
  end
12
25
 
13
26
  describe Merb::Router::CachedProc do
@@ -16,7 +29,7 @@ describe Merb::Router::CachedProc do
16
29
  cc = Merb::Router::CachedProc.new(regexp)
17
30
  Merb::Router::CachedProc[cc.index].cache.should == regexp
18
31
  end
19
-
32
+
20
33
  it "should register a proc" do
21
34
  testproc = proc { puts 'test' }
22
35
  cc = Merb::Router::CachedProc.new(testproc)
@@ -74,14 +87,14 @@ describe Merb::Router do
74
87
  end
75
88
 
76
89
  it "should have a spec helper to match routes" do
77
- Merb::Router.prepare{ |r| r.default_routes }
78
- with_route("/pages/show/1", "GET") do |params|
79
- params[:controller].should == "pages"
80
- params[:action].should == "show"
81
- params[:id].should == "1"
82
- end
90
+ Merb::Router.prepare { |r| r.default_routes }
91
+ with_route('/pages/show/1', 'GET') do |params|
92
+ params[:controller].should == 'pages'
93
+ params[:action].should == 'show'
94
+ params[:id].should == '1'
95
+ end
83
96
  end
84
-
97
+
85
98
  # it "should be fast" do
86
99
  # Merb::Router.prepare do |r|
87
100
  # r.resource :icon
@@ -121,10 +134,10 @@ describe Merb::Router, "when doing route matching with a big set of example rout
121
134
  Set.new(hash.keys).should == Set.new(keys)
122
135
  end
123
136
 
124
- before(:all) do
137
+ before :all do
125
138
  Merb::Router.prepare do |r|
126
- # A simple route match, sends "/contact" to Info#contact
127
- # (i.e. the 'contact' method inside the 'Info' controller)
139
+ # A simple route match, sends "/contact" to Info#contact,
140
+ # i.e. the 'contact' method inside the 'Info' controller
128
141
  r.match("/contact").
129
142
  to(:controller => "info", :action => "contact")
130
143
 
@@ -166,7 +179,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
166
179
  # Use square-bracket notation to replace param results with captures from the path
167
180
  r.match(%r[^/movies/(\d+)-(\d+)-(\d+)$]).
168
181
  to(:controller => "movies", :movie_id => "[1][2][3]", :action => "show")
169
-
182
+
170
183
  # Use the second optional argument of 'match' to be more specific about the request;
171
184
  # in this case, only accept the POST method for the /movies/create action
172
185
  r.match("/movies/create", :method => "post").
@@ -176,12 +189,12 @@ describe Merb::Router, "when doing route matching with a big set of example rout
176
189
  # e.g. :user_agent[1] will be replaced with either 'MSIE' or 'Gecko' in the following case:
177
190
  r.match(%r[^/movies/(.+)], :user_agent => /(MSIE|Gecko)/).
178
191
  to(:controller => "movies", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
179
-
192
+
180
193
  # The 'match' method can also be called without the path string or regexp.
181
194
  # In this example, direct all insecure traffic to a Insecure#index
182
195
  r.match(:protocol => "http://").
183
196
  to(:controller => "insecure", :action => "index")
184
-
197
+
185
198
  # Use anonymous placeholders in place of the ugly-looking pattern, /([^\/.,;?]+)/
186
199
  r.match("/::/users/::").
187
200
  to(:controller => "users", :action => "[2]", :id => "[1]")
@@ -193,6 +206,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
193
206
  r.match('/admin').to(:namespace => 'admin') do |foo|
194
207
  foo.match('/foo').to(:controller => 'foo')
195
208
  end
209
+
196
210
  r.match('/foo').to(:controller => 'foo')
197
211
 
198
212
  # Putting it all together, and adding the requirement that we use an "admin" prefix on the
@@ -204,12 +218,12 @@ describe Merb::Router, "when doing route matching with a big set of example rout
204
218
  end.to(:controller => "users", :action => "default")
205
219
  # Note that the last line above sends all traffic in the "admin" subdomain to the
206
220
  # Admin::Users#default action if no other route is matched.
207
-
221
+
208
222
  # Create a deferred route. In this case, the decision of whether or not the route
209
223
  # is a match is made via the .xhr? call. Note that it's ok to put the hash in a
210
224
  # conditional because if the "if" statement is false, ruby returns nil (i.e. no match).
211
225
  r.match(%r[^/deferred]).defer_to do |request, params|
212
- {:controller => "ajax", :action => "index"} if request.xhr?
226
+ { :controller => "ajax", :action => "index" } if request.xhr?
213
227
  end
214
228
 
215
229
  # Use the placeholders in a the deferred route
@@ -218,14 +232,14 @@ describe Merb::Router, "when doing route matching with a big set of example rout
218
232
  end
219
233
  end
220
234
  end
221
-
235
+
222
236
  it "should connect '/contact' to Info#contact" do
223
237
  index, route = Merb::Router.match(SimpleRequest.new(:protocol => "http://", :path => '/contact'), {})
224
238
  route[:controller].should == "info"
225
239
  route[:action].should == "contact"
226
240
  should_only_have_keys(route, :controller, :action)
227
241
  end
228
-
242
+
229
243
  it "should use placeholders in the match and pass them along to the params" do
230
244
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/books/12/show'), {})
231
245
  route[:controller].should == "books"
@@ -233,7 +247,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
233
247
  route[:book_id].should == "12"
234
248
  should_only_have_keys(route, :controller, :action, :book_id)
235
249
  end
236
-
250
+
237
251
  it "should allow placeholders to be used in the params to construct results from matches" do
238
252
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/admin/accounts/users/index'), {})
239
253
  route[:controller].should == "accounts/users"
@@ -246,7 +260,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
246
260
  route[:id].should == "4"
247
261
  should_only_have_keys(route, :module, :controller, :action, :id)
248
262
  end
249
-
263
+
250
264
  it "should allow 'match' to use a block to factor out repetitive parts, merging the path as it goes" do
251
265
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/accounts/overview'), {})
252
266
  route[:controller].should == "accounts"
@@ -266,7 +280,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
266
280
  route[:controller].should == "accounts"
267
281
  route[:action].should == "reports"
268
282
  should_only_have_keys(route, :controller, :action)
269
-
283
+
270
284
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/slideshow/2'), {})
271
285
  route[:controller].should == "accounts"
272
286
  route[:action].should == "slideshow"
@@ -281,7 +295,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
281
295
  route[:id].should == "5"
282
296
  should_only_have_keys(route, :controller, :action, :id)
283
297
  end
284
-
298
+
285
299
  it "should be able to use square bracket notation to replace param results with captures from the path" do
286
300
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/123-1-9999'), {})
287
301
  route[:controller].should == "movies"
@@ -295,13 +309,13 @@ describe Merb::Router, "when doing route matching with a big set of example rout
295
309
  route[:controller].should be_nil
296
310
  route[:action].should be_nil
297
311
  should_only_have_keys(route)
298
-
312
+
299
313
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/create', :method => "post"), {})
300
314
  route[:controller].should == "movies"
301
315
  route[:action].should == "create"
302
316
  should_only_have_keys(route, :controller, :action)
303
317
  end
304
-
318
+
305
319
  it "should use variables from the 'match' as a result sent to the controller in the params hash" do
306
320
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/harry-potter-3', :user_agent => "Internet Explorer (MSIE)"), {})
307
321
  route[:controller].should == "movies"
@@ -322,7 +336,7 @@ describe Merb::Router, "when doing route matching with a big set of example rout
322
336
  route[:action].should == "index"
323
337
  should_only_have_keys(route, :controller, :action)
324
338
  end
325
-
339
+
326
340
  it "should use anonymous placeholders" do
327
341
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/5/users/show', :protocol => "https://"), {})
328
342
  route[:controller].should == "users"
@@ -335,8 +349,8 @@ describe Merb::Router, "when doing route matching with a big set of example rout
335
349
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/bar', :method => :get), {})
336
350
  route[:namespace].should == 'foo'
337
351
  route[:controller].should == 'bar'
338
- route[:action].should == 'index'
339
- should_only_have_keys(route, :namespace, :controller, :action)
352
+ route[:action].should == 'index'
353
+ should_only_have_keys(route, :namespace, :controller, :action)
340
354
  end
341
355
 
342
356
  it "should have namespace 'admin' if path is '/admin/foo'" do
@@ -344,14 +358,14 @@ describe Merb::Router, "when doing route matching with a big set of example rout
344
358
  route[:namespace].should == 'admin'
345
359
  route[:controller].should == 'foo'
346
360
  route[:action].should == 'index'
347
- should_only_have_keys(route, :namespace, :controller, :action)
361
+ should_only_have_keys(route, :namespace, :controller, :action)
348
362
  end
349
363
 
350
364
  it "should not have namespace if path is just '/foo'" do
351
365
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/foo', :method => :get), {})
352
366
  route[:controller].should == 'foo'
353
367
  route[:action].should == 'index'
354
- should_only_have_keys(route, :controller, :action)
368
+ should_only_have_keys(route, :controller, :action)
355
369
  end
356
370
 
357
371
  it "should send all admin.* domains to the 'admin/users' controller, and 'default' action" do
@@ -394,106 +408,105 @@ describe Merb::Router, "when doing route matching with a big set of example rout
394
408
  end
395
409
 
396
410
  describe Merb::Router, "with a single resource, 'blogposts' with 'comments'" do
397
- before(:each) do
411
+ before :each do
398
412
  Merb::Router.prepare do |r|
399
- r.resources :blogposts do |bposts|
400
- bposts.resources :comments
401
- end
413
+ r.resources :blogposts do |b|
414
+ b.resources :comments
415
+ end
402
416
  end
403
417
  end
404
-
418
+
405
419
  it "should match /blogposts" do
406
420
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts', :method => :get), {})
407
421
  route[:controller].should == 'blogposts'
408
422
  route[:action].should == 'index'
409
-
423
+
410
424
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts', :method => :post), {})
411
425
  route[:controller].should == 'blogposts'
412
426
  route[:action].should == 'create'
413
427
  end
414
-
428
+
415
429
  it "should match /blogposts/new" do
416
430
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/new', :method => :get), {})
417
431
  route[:controller].should == 'blogposts'
418
432
  route[:action].should == 'new'
419
- end
420
-
433
+ end
434
+
421
435
  it "should match /blogposts/1" do
422
436
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :get), {})
423
437
  route[:controller].should == 'blogposts'
424
438
  route[:action].should == 'show'
425
439
  route[:id].should == '1'
426
-
440
+
427
441
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :put), {})
428
442
  route[:controller].should == 'blogposts'
429
443
  route[:action].should == 'update'
430
444
  route[:id].should == '1'
431
-
445
+
432
446
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :delete), {})
433
447
  route[:controller].should == 'blogposts'
434
448
  route[:action].should == 'destroy'
435
449
  route[:id].should == '1'
436
450
  end
437
-
451
+
438
452
  it "should match /blogposts/1;edit" do
439
453
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1;edit', :method => :get), {})
440
454
  route[:controller].should == 'blogposts'
441
455
  route[:action].should == 'edit'
442
456
  route[:id].should == '1'
443
-
457
+
444
458
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1;edit', :method => :put), {})
445
459
  route[:controller].should be_nil
446
460
  route[:action].should be_nil
447
461
  end
448
-
462
+
449
463
  it "should match /blogposts/1/edit" do
450
464
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1/edit', :method => :get), {})
451
465
  route[:controller].should == 'blogposts'
452
466
  route[:action].should == 'edit'
453
467
  route[:id].should == '1'
454
-
468
+
455
469
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1/edit', :method => :put), {})
456
470
  route[:controller].should be_nil
457
471
  route[:action].should be_nil
458
472
  end
459
-
473
+
460
474
  it "should generate blogposts path" do
461
- Merb::Router.generate(:blogposts).should == '/blogposts'
475
+ generate(:blogposts).should == '/blogposts'
462
476
  end
463
-
477
+
464
478
  it "should generate blogpost path" do
465
- Merb::Router.generate(:blogpost, {:id => 1}).should == '/blogposts/1'
479
+ generate(:blogpost, :id => 1).should == '/blogposts/1'
466
480
  b = Blogposts.new
467
- Merb::Router.generate(:blogpost, b).should == '/blogposts/42'
468
- Merb::Router.generate(:blogpost, :id => b).should == '/blogposts/42'
481
+ generate(:blogpost, b).should == '/blogposts/42'
482
+ generate(:blogpost, :id => b).should == '/blogposts/42'
469
483
  end
470
-
484
+
471
485
  it "should generate new_blogpost path" do
472
- Merb::Router.generate(:new_blogpost).should == '/blogposts/new'
486
+ generate(:new_blogpost).should == '/blogposts/new'
473
487
  end
474
-
488
+
475
489
  it "should generate edit_blogpost path" do
476
- Merb::Router.generate(:edit_blogpost, {:id => 1}).should == '/blogposts/1/edit'
490
+ generate(:edit_blogpost, {:id => 1}).should == '/blogposts/1/edit'
477
491
  end
478
-
492
+
479
493
  it "should generate comments path" do
480
- c = Comment.new
481
- Merb::Router.generate(:comments, c).should == '/blogposts/42/comments'
494
+ c = Comment.new
495
+ generate(:comments, c).should == '/blogposts/42/comments'
482
496
  end
483
497
 
484
498
  it "should generate comment path" do
485
499
  c = Comment.new
486
- Merb::Router.generate(:comment, c).should == '/blogposts/42/comments/24'
500
+ generate(:comment, c).should == '/blogposts/42/comments/24'
487
501
  end
488
-
489
502
  end
490
503
 
491
504
 
492
505
  describe Merb::Router, "with resources using name_prefix, 'oranges' and 'ape'" do
493
- before(:each) do
506
+ before :each do
494
507
  Merb::Router.prepare do |r|
495
508
  r.resources :oranges, :name_prefix => "florida_"
496
- r.resource :ape, :name_prefix => "grape_"
509
+ r.resource :ape, :name_prefix => "grape_"
497
510
  end
498
511
  end
499
512
 
@@ -502,96 +515,147 @@ describe Merb::Router, "with resources using name_prefix, 'oranges' and 'ape'" d
502
515
  route[:controller].should == 'oranges'
503
516
  route[:action].should == 'index'
504
517
  end
505
-
518
+
506
519
  it "should generate florida_oranges path" do
507
- Merb::Router.generate(:florida_oranges).should == '/oranges'
520
+ generate(:florida_oranges).should == '/oranges'
508
521
  end
509
-
522
+
510
523
  it "should generate florida_orange path" do
511
- Merb::Router.generate(:florida_orange, {:id => 1}).should == '/oranges/1'
524
+ generate(:florida_orange, :id => 1).should == '/oranges/1'
512
525
  b = Blogposts.new
513
- Merb::Router.generate(:florida_orange, b).should == '/oranges/42'
514
- Merb::Router.generate(:florida_orange, :id => b).should == '/oranges/42'
526
+ generate(:florida_orange, b).should == '/oranges/42'
527
+ generate(:florida_orange, :id => b).should == '/oranges/42'
515
528
  end
516
529
 
517
530
  it "should generate new_florida_orange path" do
518
- Merb::Router.generate(:new_florida_orange).should == '/oranges/new'
531
+ generate(:new_florida_orange).should == '/oranges/new'
519
532
  end
520
533
 
521
534
  it "should generate edit_florida_orange path" do
522
- Merb::Router.generate(:edit_florida_orange, {:id => 1}).should == '/oranges/1/edit'
523
- end
535
+ generate(:edit_florida_orange, {:id => 1}).should == '/oranges/1/edit'
536
+ end
524
537
 
525
538
  it "should match /ape" do
526
539
  index, route = Merb::Router.match(SimpleRequest.new(:path => '/ape', :method => :get), {})
527
540
  route[:controller].should == 'ape'
528
541
  route[:action].should == 'show'
529
542
  end
530
-
543
+
531
544
  it "should generate grape_ape path" do
532
- Merb::Router.generate(:grape_ape).should == '/ape'
545
+ generate(:grape_ape).should == '/ape'
533
546
  end
534
-
547
+
535
548
  it "should generate new_grape_ape path" do
536
- Merb::Router.generate(:new_grape_ape).should == '/ape/new'
549
+ generate(:new_grape_ape).should == '/ape/new'
537
550
  end
538
551
 
539
552
  it "should generate edit_grape_ape path" do
540
- Merb::Router.generate(:edit_grape_ape).should == '/ape/edit'
541
- end
553
+ generate(:edit_grape_ape).should == '/ape/edit'
554
+ end
542
555
  end
543
556
 
544
557
  describe Merb::Router, "with resources using a collection action" do
545
- before(:each) do
558
+ before :each do
546
559
  Merb::Router.prepare do |r|
547
560
  r.resources :flowers, :collection => { :random => [:get] }
548
561
  end
549
562
  end
550
-
563
+
551
564
  it "should generate random_flowers path" do
552
- Merb::Router.generate(:random_flowers).should == '/flowers/random'
565
+ generate(:random_flowers).should == '/flowers/random'
566
+ end
567
+
568
+ it "should match GET to /flowers/random" do
569
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/random', :method => :get), {})
570
+ route[:controller].should == 'flowers'
571
+ route[:action].should == 'random'
572
+ end
573
+
574
+ it "should match GET to /flowers/random.xml" do
575
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/random.xml', :method => :get), {})
576
+ route[:controller].should == 'flowers'
577
+ route[:action].should == 'random'
578
+ route[:format].should == 'xml'
553
579
  end
580
+
554
581
  end
555
582
 
556
- describe Merb::Router, "with resources using a member action" do
557
- before(:each) do
583
+ describe Merb::Router, "with resources using a member action { :pick => [:get] }" do
584
+ before :each do
558
585
  Merb::Router.prepare do |r|
559
586
  r.resources :flowers, :member => { :pick => [:get] }
560
587
  end
561
588
  end
562
-
589
+
563
590
  it 'should generate pick_flower path' do
564
- Merb::Router.generate(:pick_flower, { :id => 1 }).should == '/flowers/1/pick'
591
+ generate(:pick_flower, :id => 1).should == '/flowers/1/pick'
592
+ end
593
+
594
+ it "should match GET to /flowers/2/pick" do
595
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :get), {})
596
+ route[:controller].should == 'flowers'
597
+ route[:action].should == 'pick'
598
+ route[:id].should == '2'
599
+ end
600
+
601
+ it "should not match POST to /flowers/2/pick" do
602
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :post), {})
603
+ route[:controller].should_not == 'flowers'
604
+ route[:action].should_not == 'pick'
605
+ route[:id].should_not == '2'
565
606
  end
607
+
608
+ it "should not match PUT to /flowers/2/pick" do
609
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :put), {})
610
+ route[:controller].should_not == 'flowers'
611
+ route[:action].should_not == 'pick'
612
+ route[:id].should_not == '2'
613
+ end
614
+
615
+ it "should not match DELETE to /flowers/2/pick" do
616
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :delete), {})
617
+ route[:controller].should_not == 'flowers'
618
+ route[:action].should_not == 'pick'
619
+ route[:id].should_not == '2'
620
+ end
621
+
622
+ it "should match GET to /flowers/2/pick.xml" do
623
+ index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick.xml', :method => :get), {})
624
+ route[:controller].should == 'flowers'
625
+ route[:action].should == 'pick'
626
+ route[:id].should == '2'
627
+ route[:format].should == 'xml'
628
+ end
629
+
566
630
  end
567
631
 
568
632
  describe Merb::Router::Behavior do
569
- before(:all) do
633
+ before :all do
570
634
  @behavior = Merb::Router::Behavior
571
635
  end
572
636
 
573
637
  it "should leave strings as strings and add ^...$ in the @conditions hash" do
574
- @behavior.new({:path => "/one/two"}).conditions[:path].should == "^/one/two$"
638
+ @behavior.new(:path => '/one/two').conditions[:path].should == '^/one/two$'
575
639
  end
576
-
640
+
577
641
  it "should replace special characters in strings with their escaped equivalents" do
578
- @behavior.new({:path => "test.xml"}).conditions[:path].should == "^test\\.xml$"
642
+ @behavior.new(:path => 'test.xml').conditions[:path].should == '^test\\.xml$'
579
643
  end
580
644
 
581
645
  it "should convert symbols to strings and add ^...$ in the @conditions hash" do
582
- @behavior.new({:method => :get}).conditions[:method].should == "^get$"
646
+ @behavior.new(:method => :get).conditions[:method].should == '^get$'
583
647
  end
584
648
 
585
649
  it "should convert regular expressions to strings in the @conditions hash" do
586
- @behavior.new({:protocol => /https?/}).conditions[:protocol].should == "https?"
650
+ @behavior.new(:protocol => /https?/).conditions[:protocol].should == 'https?'
587
651
  end
588
-
652
+
589
653
  it "should deduce placeholders from the @conditions hash" do
590
- ph = @behavior.new({:path => "/:controller/:action"}).placeholders
654
+ ph = @behavior.new(:path => '/:controller/:action').placeholders
591
655
  ph[:controller].should == [:path, 1]
592
656
  ph[:action].should == [:path, 2]
593
657
  end
594
-
658
+
595
659
  it "should deduce placeholders from the @conditions hash, even when they contain numbers" do
596
660
  ph = @behavior.new({:path => "/:part1/:part2"}).placeholders
597
661
  ph[:part1].should == [:path, 1]
@@ -599,40 +663,40 @@ describe Merb::Router::Behavior do
599
663
  end
600
664
 
601
665
  it "should deduce placeholders within regular expressions that contain prefixed captures" do
602
- ph = @behavior.new({:path => %r[/(\d+)/:controller/:action]}).placeholders
666
+ ph = @behavior.new(:path => %r[/(\d+)/:controller/:action]).placeholders
603
667
  ph[:controller].should == [:path, 2]
604
668
  ph[:action].should == [:path, 3]
605
-
606
- ph = @behavior.new({:path => %r[/:controller/:action/(\d+)]}).placeholders
669
+
670
+ ph = @behavior.new(:path => %r[/:controller/:action/(\d+)]).placeholders
607
671
  ph[:controller].should == [:path, 1]
608
672
  ph[:action].should == [:path, 2]
609
673
  end
610
674
 
611
675
  it "should deduce placeholder positions in nested captures" do
612
- ph = @behavior.new({:path => %r[(/(\d+)/:controller)/:action]}).placeholders
676
+ ph = @behavior.new(:path => %r[(/(\d+)/:controller)/:action]).placeholders
613
677
  ph[:controller].should == [:path, 3]
614
678
  ph[:action].should == [:path, 4]
615
-
616
- ph = @behavior.new({:path => %r[/(\d+)/(:controller)/:action]}).placeholders
679
+
680
+ ph = @behavior.new(:path => %r[/(\d+)/(:controller)/:action]).placeholders
617
681
  ph[:controller].should == [:path, 3]
618
682
  ph[:action].should == [:path, 4]
619
-
620
- ph = @behavior.new({:path => %r[/(\d+)/:controller/(:action)]}).placeholders
683
+
684
+ ph = @behavior.new(:path => %r[/(\d+)/:controller/(:action)]).placeholders
621
685
  ph[:controller].should == [:path, 2]
622
686
  ph[:action].should == [:path, 4]
623
-
624
- ph = @behavior.new({:path => %r[(/(\d+)/(:controller/((:action))))]}).placeholders
687
+
688
+ ph = @behavior.new(:path => %r[(/(\d+)/(:controller/((:action))))]).placeholders
625
689
  ph[:controller].should == [:path, 4]
626
690
  ph[:action].should == [:path, 7]
627
691
  end
628
692
 
629
693
  it "should replace any placeholders found within @conditions strings with segment regular expressions" do
630
- m = @behavior.new({:path => "/:my/:place:holders/:here"}).conditions
694
+ m = @behavior.new(:path => "/:my/:place:holders/:here").conditions
631
695
  m[:path].should == "^/([^/.,;?]+)/([^/.,;?]+)([^/.,;?]+)/([^/.,;?]+)$"
632
696
  end
633
697
 
634
698
  it "should set default values for params that came from placeholders" do
635
- p = @behavior.new({:path => "/:my/:place:holders/:here"}).params
699
+ p = @behavior.new(:path => "/:my/:place:holders/:here").params
636
700
  p[:my].should == ":my"
637
701
  p[:place].should == ":place"
638
702
  p[:holders].should == ":holders"
@@ -640,11 +704,11 @@ describe Merb::Router::Behavior do
640
704
  end
641
705
 
642
706
  it "should merge params with its ancestors" do
643
- b = @behavior.new({}, {:controller => "my_controller", :action => "index"})
644
- c = @behavior.new({}, {:action => "show"}, b)
645
- c.merged_params.should == {:controller => "my_controller", :action => "show"}
707
+ b = @behavior.new({}, { :controller => "my_controller", :action => "index" })
708
+ c = @behavior.new({}, { :action => "show" }, b)
709
+ c.merged_params.should == { :controller => "my_controller", :action => "show" }
646
710
  end
647
-
711
+
648
712
  # it "should have a default action and controller for merged params" do
649
713
  # a = @behavior.new
650
714
  # a.merged_params.should == {:controller => "application", :action => "index"}
@@ -655,37 +719,37 @@ describe Merb::Router::Behavior do
655
719
  # c = @behavior.new({}, {:action => "show"})
656
720
  # c.merged_params.should == {:controller => "application", :action => "show"}
657
721
  # end
658
-
722
+
659
723
  it "should merge conditions with its ancestors" do
660
- b = @behavior.new({:method => "get", :protocol => "http"})
661
- c = @behavior.new({:method => "put"}, {}, b)
662
- c.merged_conditions.should == {:method => "^put$", :protocol => "^http$"}
724
+ b = @behavior.new({ :method => "get", :protocol => "http" })
725
+ c = @behavior.new({ :method => "put" }, {}, b)
726
+ c.merged_conditions.should == { :method => "^put$", :protocol => "^http$" }
663
727
  end
664
728
 
665
729
  it "should merge placeholders with its ancestors" do
666
- b = @behavior.new({:method => "get", :protocol => ":ssl"}, {:action => ":method"})
667
- c = @behavior.new({:method => "put"}, {:action => ":ssl"}, b)
668
- c.merged_placeholders.should == {:ssl => [:protocol, 1]}
730
+ b = @behavior.new({ :method => "get", :protocol => ":ssl" }, { :action => ":method" })
731
+ c = @behavior.new({ :method => "put" }, { :action => ":ssl" }, b)
732
+ c.merged_placeholders.should == { :ssl => [:protocol, 1] }
669
733
  end
670
734
 
671
735
  it "should add the number of path captures in the ancestors' paths to placeholders that hold a place for :path captures" do
672
- b = @behavior.new({:path => "/:controller/:action"})
673
- b.placeholders.should == {:controller => [:path, 1], :action => [:path, 2]}
674
- c = @behavior.new({:path => "/:id"}, {}, b)
675
- c.placeholders.should == {:id => [:path, 1]}
736
+ b = @behavior.new(:path => "/:controller/:action")
737
+ b.placeholders.should == { :controller => [:path, 1], :action => [:path, 2] }
738
+ c = @behavior.new({ :path => "/:id" }, {}, b)
739
+ c.placeholders.should == { :id => [:path, 1] }
676
740
 
677
- c.merged_placeholders.should == {:controller => [:path, 1], :action => [:path, 2], :id => [:path, 3]}
741
+ c.merged_placeholders.should == { :controller => [:path, 1], :action => [:path, 2], :id => [:path, 3] }
678
742
  end
679
743
 
680
744
  it "should merge the :path differently than other @conditions keys -- it should concatenate" do
681
745
  b = @behavior.new({:method => "get", :protocol => "http"})
682
746
  c = @behavior.new({:path => "/test", :method => "put"}, {}, b)
683
747
  c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/test$"}
684
-
748
+
685
749
  b = @behavior.new({:path => "/test", :method => "get", :protocol => "http"})
686
750
  c = @behavior.new({:method => "put"}, {}, b)
687
751
  c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/test$"}
688
-
752
+
689
753
  b = @behavior.new({:path => "/admin", :method => "get", :protocol => "http"})
690
754
  c = @behavior.new({:path => "/test", :method => "put"}, {}, b)
691
755
  c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/admin/test$"}
@@ -696,7 +760,7 @@ describe Merb::Router::Behavior do
696
760
  cp = b.send(:compiled_params)
697
761
  cp[:controller].should == "path1"
698
762
  cp[:action].should == "path2"
699
-
763
+
700
764
  b = @behavior.new(
701
765
  {:path => "/admin/:controller/:action/:postfix", :method => "get"},
702
766
  {:controller => "/admin/:controller", :action => "neat_o_:action:postfix"})
@@ -704,7 +768,7 @@ describe Merb::Router::Behavior do
704
768
  cp[:controller].should == "\"/admin/\" + path1"
705
769
  cp[:action].should == "\"neat_o_\" + path2 + path3"
706
770
  end
707
-
771
+
708
772
  it "should allow a bracketed number such as [3] to compile to path3" do
709
773
  b = @behavior.new(
710
774
  {:path => "/admin/:controller/:action/(.+)", :method => "get"},
@@ -712,7 +776,7 @@ describe Merb::Router::Behavior do
712
776
  cp = b.send(:compiled_params)
713
777
  cp[:catchall].should == "path3"
714
778
  end
715
-
779
+
716
780
  it "should allow a backslash to escape an underscore in the compiled params" do
717
781
  b = @behavior.new(
718
782
  {:path => "/admin/:controller/:action", :method => "get"},
@@ -731,101 +795,106 @@ describe Merb::Router::Behavior do
731
795
  end
732
796
 
733
797
  it "should allow for conditional blocks using the 'defer_to' method" do
734
- b = @behavior.new({:path => "/admin"})
735
- route = b.defer_to { |request| {:controller => "late_bound", :action => "place"} }
798
+ b = @behavior.new(:path => '/admin')
799
+ route = b.defer_to { |request| { :controller => 'late_bound', :action => 'place' } }
736
800
  route.conditional_block.should be_an_instance_of(Proc)
737
801
  route.compile.should match(/block_result/m)
738
802
  end
739
803
  end
740
804
 
741
805
  describe Merb::Router::Behavior, "class methods" do
742
- before(:all) do
806
+ before :all do
743
807
  @b = Merb::Router::Behavior
744
808
  end
745
809
 
746
- it "should count opening parentheses" do
747
- @b.count_parens_up_to(" ( )", 1).should == 1
748
- @b.count_parens_up_to(" ( )", 50).should == 1
749
- @b.count_parens_up_to(" (() )", 1).should == 1
750
- @b.count_parens_up_to(" (() )", 2).should == 2
810
+ it 'should count opening parentheses' do
811
+ [[' ( )', 1, 1],
812
+ [' ( )', 50, 1],
813
+ [' (() )', 1, 1],
814
+ [' (() )', 2, 2]].each do |parens,limit,expected|
815
+ @b.count_parens_up_to(parens, limit).should == expected
816
+ end
817
+
751
818
  # TODO: skip escaped open parens
752
819
  end
753
820
 
754
- it "should concatenate strings without endcaps" do
755
- @b.concat_without_endcaps(nil, nil).should be_nil
756
- @b.concat_without_endcaps(nil, "^test").should == "^test"
757
- @b.concat_without_endcaps("my$", nil).should == "my$"
758
- @b.concat_without_endcaps("my", "test").should == "mytest"
759
- @b.concat_without_endcaps("my$", "test").should == "mytest"
760
- @b.concat_without_endcaps("my^", "test").should == "my^test"
761
- @b.concat_without_endcaps("my$", "^test").should == "mytest"
762
- @b.concat_without_endcaps("^my$", "^test$").should == "^mytest$"
821
+ it 'should concatenate strings without endcaps' do
822
+ [[nil, nil, nil],
823
+ [nil, '^test', '^test'],
824
+ ['my$', nil, 'my$'],
825
+ ['my', 'test', 'mytest'],
826
+ ['my$', 'test', 'mytest'],
827
+ ['my^', 'test', 'my^test'],
828
+ ['my$', '^test', 'mytest'],
829
+ ['^my$', '^test$', '^mytest$']].each do |str1, str2, expected|
830
+ @b.concat_without_endcaps(str1, str2).should == expected
831
+ end
763
832
  end
764
833
 
765
- it "should compile arrays with strings and symbols into code" do
766
- @b.array_to_code([:var, "this string"]).should == "var + \"this string\""
767
- @b.array_to_code(["one string"]).should == "\"one string\""
768
- @b.array_to_code(["string", :var, :var2, "other"]).should == "\"string\" + var + var2 + \"other\""
834
+ it 'should compile arrays with strings and symbols into code' do
835
+ [[[:var, 'this string'], %{var + "this string"}],
836
+ [['one string'], %{"one string"}],
837
+ [["string", :var, :var2, "other"], %{"string" + var + var2 + "other"}]].each do |array, expected|
838
+ @b.array_to_code(array).should == expected
839
+ end
769
840
  end
770
841
  end
771
842
 
772
- describe "Merb::Route", "rendered as a string" do
773
- before(:all) do
774
- Merb::Router.prepare do |r|
775
- r.default_routes
776
- end
843
+ describe Merb::Router::Route, 'rendered as a string' do
844
+ before :all do
845
+ Merb::Router.prepare { |r| r.default_routes }
777
846
  @routes = Merb::Router.routes
778
847
  end
779
848
 
780
- it "should show the default route" do
849
+ it 'should show the default route' do
781
850
  @routes.last.to_s.should == "/:controller(/:action(/:id)?)?(\\.:format)?"
782
851
  end
783
852
  end
784
853
 
785
- describe Merb::Router, "with resources using namespace 'admin'" do
786
- before(:each) do
854
+ describe Merb::Router, 'using namespaces' do
855
+ before :each do
787
856
  Merb::Router.prepare do |r|
788
- #Declare one in the nested style
789
- r.match(:host => /^.*$/).to(:namespace => 'admin') do |admin|
790
- admin.resources :oranges
857
+ r.namespace :admin do |a|
858
+ a.resources :namespace_block_resources
859
+ a.resource :namespace_block_resource
860
+ end
861
+
862
+ r.match :namespace => 'admin' do |a|
863
+ a.resources :match_block_resources
864
+ a.resource :match_block_resource
791
865
  end
792
- #Declare one in the non-nested style
793
- r.resources :ape, :namespace => 'admin'
794
- #Declare resources without a namespace to make sure it's not overridden
795
- r.resources :oranges
796
- r.resource :ape
866
+
867
+ r.resources :namespace_option_resources, :namespace => 'admin'
868
+ r.resource :namespace_option_resource, :namespace => 'admin'
869
+
870
+ r.resources :resources, :namespace => 'admin'
871
+ r.resource :resource, :namespace => 'admin'
872
+ r.resources :resources
873
+ r.resource :resource
874
+
875
+ r.resources :path_namespace_resources, :namespace => 'admin/supersecret'
876
+ r.resources :path_namespace_resource, :namespace => 'admin/supersecret'
797
877
  end
798
878
  end
799
879
 
800
- it "should generate admin_oranges path" do
801
- Merb::Router.generate(:admin_oranges).should == '/oranges'
802
- end
803
-
804
- it "should generate admin_orange path" do
805
- Merb::Router.generate(:admin_orange, {:id => 1}).should == '/oranges/1'
806
- b = Blogposts.new
807
- Merb::Router.generate(:admin_orange, b).should == '/oranges/42'
808
- Merb::Router.generate(:admin_orange, :id => b).should == '/oranges/42'
880
+ # Several ways to define a namespace. Perhaps too many?
881
+ %w( namespace_block match_block namespace_option ).each do |context|
882
+ %w( resources resource ).each do |r|
883
+ it "defines :#{r} in a :#{context} context" do
884
+ generate("admin_#{context}_#{r}").should == "/admin/#{context}_#{r}"
885
+ end
886
+ end
809
887
  end
810
888
 
811
- it "should generate new_admin_orange path" do
812
- Merb::Router.generate(:new_admin_orange).should == '/oranges/new'
889
+ it 'defines namespaces with path fragments' do
890
+ generate(:admin_supersecret_path_namespace_resources).should ==
891
+ '/admin/supersecret/path_namespace_resources'
813
892
  end
814
893
 
815
- it "should generate edit_admin_orange path" do
816
- Merb::Router.generate(:edit_admin_orange, {:id => 1}).should == '/oranges/1/edit'
817
- end
818
-
819
- it "should generate admin_ape path" do
820
- Merb::Router.generate(:admin_ape).should == '/ape'
821
- end
822
-
823
- it "should generate new_admin_ape path" do
824
- Merb::Router.generate(:new_admin_ape).should == '/ape/new'
894
+ it 'allows resources of the same name in different namespaces' do
895
+ %w( resources resource ).each do |r|
896
+ generate("admin_#{r}").should == "/admin/#{r}"
897
+ generate(r).should == "/#{r}"
898
+ end
825
899
  end
826
-
827
- it "should generate edit_admin_ape path" do
828
- Merb::Router.generate(:edit_admin_ape).should == '/ape/edit'
829
- end
830
-
831
900
  end