public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Add a bunch of pretty advanced spec examples for nested matches in routes.
Michael S. Klishin (author)
Fri May 16 16:39:12 -0700 2008
commit  c53276953f5ad83c328c0efebadfd599ef6f91a4
tree    3cbafce3c990e42ee0911555985377c544b6e876
parent  28d86fa31c6409e406d96c6b0642e8d3e27644b6
...
1
2
3
4
 
5
6
7
 
8
9
10
11
12
13
 
14
15
16
 
17
18
19
20
21
22
 
23
24
25
 
26
27
28
29
30
31
 
32
33
34
 
35
36
37
38
39
40
 
41
42
43
 
44
45
46
...
48
49
50
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
...
1
2
3
 
4
5
6
 
7
8
9
10
11
12
 
13
14
15
 
16
17
18
19
20
21
 
22
23
24
 
25
26
27
28
29
30
 
31
32
33
 
34
35
36
37
38
39
 
40
41
42
 
43
44
45
46
...
48
49
50
 
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -1,46 +1,46 @@
0
 require File.join(File.dirname(__FILE__), "spec_helper")
0
 
0
 describe "A route derived from the blocks of #match" do
0
-
0
+
0
   it "should inherit the :controller option." do
0
     Merb::Router.prepare do |r|
0
- r.match('/alpha', :controller=>'Alphas') do |alpha|
0
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
0
         alpha.match('').to(:action=>'normal')
0
       end
0
     end
0
     route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'normal')
0
   end
0
-
0
+
0
   it "should inherit the :action option." do
0
     Merb::Router.prepare do |r|
0
- r.match('/alpha', :action=>'wierd') do |alpha|
0
+ r.match('/alpha', :action=>'wierd') do |alpha|
0
         alpha.match('').to(:controller=>'Alphas')
0
       end
0
     end
0
     route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'wierd')
0
   end
0
-
0
+
0
   it "should inherit the default :action of 'index'" do
0
     Merb::Router.prepare do |r|
0
- r.match('/alpha', :controller=>'Alphas') do |alpha|
0
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
0
         alpha.match('').to({})
0
       end
0
     end
0
     route_to('/alpha').should have_route(:controller=>'Alphas',:action=>'index')
0
   end
0
-
0
+
0
   it "should make use of the :params option" do
0
     Merb::Router.prepare do |r|
0
- r.match('/alpha', :controller=>'Alphas', :params =>{:key=>'value'}) do |alpha|
0
+ r.match('/alpha', :controller=>'Alphas', :params =>{:key=>'value'}) do |alpha|
0
         alpha.match('').to(:action=>'normal',:key2=>'value2')
0
       end
0
     end
0
     route_to('/alpha').should have_route(:controller=>'Alphas',:key=>'value',:action=>'normal',:key2=>'value2')
0
   end
0
-
0
+
0
   it "should inherit the parameters through many levels" do
0
     Merb::Router.prepare do |r|
0
- r.match('/alpha', :controller=>'Alphas') do |alpha|
0
+ r.match('/alpha', :controller=>'Alphas') do |alpha|
0
         alpha.match('/beta', :action=>'normal') do |beta|
0
           beta.match('/:id').to(:id=>':id')
0
         end
0
@@ -48,6 +48,51 @@
0
     end
0
     route_to('/alpha/beta/gamma').should have_route(:controller=>'Alphas',:action=>'normal', :id=>'gamma')
0
   end
0
-
0
+
0
+ it "allows wrapping of nested routes all having shared argument" do
0
+ Merb::Router.prepare do |r|
0
+ r.match('/:language') do |i18n|
0
+ i18n.match!('/:controller/:action')
0
+ end
0
+ end
0
+ route_to('/fr/hotels/search').should have_route(:controller => 'hotels', :action => "search", :language => "fr")
0
+ end
0
+
0
+ it "allows wrapping of nested routes all having shared argument" do
0
+ Merb::Router.prepare do |r|
0
+ r.match(/\/?(.*)?/).to(:language => "[1]") do |l|
0
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
0
+ end
0
+ end
0
+
0
+ route_to('/en/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :language => "en", :id => "london")
0
+ end
0
+
0
+ it "allows wrapping of nested routes all having shared OPTIONAL argument" do
0
+ Merb::Router.prepare do |r|
0
+ r.match(/\/?(.*)?/).to(:language => "[1]") do |l|
0
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
0
+ end
0
+ end
0
+
0
+ route_to('/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :id => "london")
0
+ end
0
+
0
+ it "allows wrapping of nested routes all having shared argument with PREDEFINED VALUES" do
0
+ Merb::Router.prepare do |r|
0
+ r.match(/\/?(en|es|fr|be|nl)?/).to(:language => "[1]") do |l|
0
+ l.match("/guides/:action/:id").to(:controller => "tour_guides")
0
+ end
0
+ end
0
+
0
+ route_to('/nl/guides/search/denboss').should have_route(:controller => 'tour_guides', :action => "search", :id => "denboss", :language => "nl")
0
+ route_to('/es/guides/search/barcelona').should have_route(:controller => 'tour_guides', :action => "search", :id => "barcelona", :language => "es")
0
+ route_to('/fr/guides/search/lille').should have_route(:controller => 'tour_guides', :action => "search", :id => "lille", :language => "fr")
0
+ route_to('/en/guides/search/london').should have_route(:controller => 'tour_guides', :action => "search", :id => "london", :language => "en")
0
+ route_to('/be/guides/search/brussels').should have_route(:controller => 'tour_guides', :action => "search", :id => "brussels", :language => "be")
0
+
0
+ route_to('/guides/search/brussels').should have_route(:controller => 'tour_guides', :action => "search", :id => "brussels")
0
+ route_to('/se/guides/search/stokholm').should have_route(:controller => 'tour_guides', :action => "search", :id => "stokholm", :language => nil)
0
+ end
0
 end

Comments

  • mattetti Fri May 16 16:43:50 -0700 2008

    awesome!