GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
a few more specs for pattern matching
automatthew (author)
Thu Aug 21 20:02:13 -0700 2008
commit  6e07a8141af4bd79fd2105e2938498fe4ff50190
tree    03bb393302b3fd78e42aaf106b3ff7b7e0bfb132
parent  939cfa2aa52743884698d568302a99499979ac0e
...
71
72
73
74
 
75
76
77
78
79
 
80
81
82
...
89
90
91
92
93
94
95
96
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
99
100
...
71
72
73
 
74
75
76
77
78
 
79
80
81
82
...
89
90
91
 
 
 
 
 
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
0
@@ -71,12 +71,12 @@ describe "In a mapping's path-matcher" do
0
       
0
       it "may match string literals" do
0
         mappings do
0
- on( :get => [ 'kilroy', 'was', 'here'] ) { 'Hello from Kilroy' }
0
+ on( :get => %w{ kilroy was here } ) { 'Hello from Kilroy' }
0
         end
0
         
0
         mock_request.get('/kilroy/was/here').body.should == 'Hello from Kilroy'
0
         
0
- # doesn't work for partial matches.
0
+ # prove it doesn't work for partial matches.
0
         mock_request.get('/kilroy/was').status.should == 404
0
       end
0
       
0
@@ -89,12 +89,24 @@ describe "In a mapping's path-matcher" do
0
         
0
       end
0
       
0
- # it "may use hashes to specify placeholders with custom regexes" do
0
- # mapping.on( :get => [ :prisoner, { :prisoner_id => /9430|24601/ } ] ) { "I am Jean Valjean!" }
0
- #
0
- # mock_request.get("/prisoner/9430").body.should == "I am Jean Valjean!"
0
- # mock_request.get("/prisoner/9431").status.should == 404
0
- # end
0
+ it "may use hashes to specify placeholders with custom regexes" do
0
+ mappings do
0
+ on( :get => [ "prisoner", { :prisoner_id => /9430|24601/ } ] ) { "I am Jean Valjean!" }
0
+ end
0
+
0
+ mock_request.get("/prisoner/9430").body.should == "I am Jean Valjean!"
0
+ mock_request.get("/prisoner/9431").status.should == 404
0
+ end
0
+
0
+ it "may use hash placeholder with value of true, to glom up all remaining components" do
0
+ mappings do
0
+ on( :get => [ :first, { :rest => true } ] ) do
0
+ [ params['first'], params['rest'].join('-') ].join(', ')
0
+ end
0
+ end
0
+
0
+ mock_request.get("/one/two/three/four").body.should == "one, two-three-four"
0
+ end
0
       
0
       it "saves placeholder matches as params" do
0
         mappings do

Comments

    No one has commented yet.