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:
Changes to behavior.rb to allow for :controller, :actions and :params 
options to be passed in

  modified:   lib/merb-core/dispatch/router/behavior.rb
  new file:   spec/public/router/nested_matches_spec.rb

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
startrader (author)
Thu May 15 20:28:58 -0700 2008
Michael S. Klishin (committer)
Fri May 16 15:11:44 -0700 2008
commit  47e48f25a89e065fd1aba6c122e28197daf24f2e
tree    69be000f81503e02b338eaffe2d3dc0a16d0992b
parent  56f5c097e66722e2f47f3ad7b77e01799d507d19
...
159
160
161
162
163
 
 
 
 
 
164
165
166
...
776
777
778
779
 
780
781
782
...
159
160
161
 
 
162
163
164
165
166
167
168
169
...
779
780
781
 
782
783
784
785
0
@@ -159,8 +159,11 @@
0
       # ==== Returns
0
       # Behavior:: The new behavior.
0
       def match_without_path(conditions = {})
0
- new_behavior = self.class.new(conditions, {}, self)
0
- conditions.delete :path if ['', '^$'].include?(conditions[:path])
0
+ params = conditions.delete(:params) || {} #parents params will be merged in Route#new
0
+ params[:controller] = conditions.delete(:controller) || params[:controller]
0
+ params[:action] = conditions.delete(:action) || params[:action]
0
+ params.delete_if{|_k,value| value.nil?}
0
+ new_behavior = self.class.new(conditions, params, self)
0
         yield new_behavior if block_given?
0
         new_behavior
0
       end
0
@@ -776,7 +779,7 @@
0
         compiled = {}
0
         params.each_pair do |key, value|
0
           unless value.is_a? String
0
- raise ArgumentError, "param value must be string (#{value.inspect})"
0
+ raise ArgumentError, "param value for #{key.to_s} must be string (#{value.inspect})"
0
           end
0
           result = []
0
           value = value.dup
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
47
48
49
50
51
52
0
@@ -1 +1,53 @@
0
+require File.join(File.dirname(__FILE__), "spec_helper")
0
+
0
+describe "A route derived from the blocks of #match" do
0
+
0
+ it "should inherit the :controller option." do
0
+ Merb::Router.prepare do |r|
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
+ it "should inherit the :action option." do
0
+ Merb::Router.prepare do |r|
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
+ it "should inherit the default :action of 'index'" do
0
+ Merb::Router.prepare do |r|
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
+ 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
+ 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
+ it "should inherit the parameters through many levels" do
0
+ Merb::Router.prepare do |r|
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
+ end
0
+ end
0
+ route_to('/alpha/beta/gamma').should have_route(:controller=>'Alphas',:action=>'normal', :id=>'gamma')
0
+ end
0
+
0
+end

Comments

    No one has commented yet.