usher 0.4.8 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -1
- data/Rakefile +5 -29
- data/VERSION.yml +2 -2
- data/lib/usher.rb +126 -37
- data/lib/usher/grapher.rb +5 -4
- data/lib/usher/interface.rb +12 -5
- data/lib/usher/interface/email_interface.rb +1 -1
- data/lib/usher/interface/rack_interface.rb +31 -13
- data/lib/usher/interface/rails2_2_interface.rb +3 -4
- data/lib/usher/interface/rails2_3_interface.rb +3 -4
- data/lib/usher/interface/rails3_interface.rb +57 -0
- data/lib/usher/node.rb +121 -73
- data/lib/usher/route.rb +45 -11
- data/lib/usher/route/path.rb +50 -11
- data/lib/usher/route/util.rb +65 -0
- data/lib/usher/route/variable.rb +22 -11
- data/lib/usher/splitter.rb +4 -141
- data/lib/usher/util.rb +6 -0
- data/lib/usher/util/generate.rb +129 -0
- data/lib/usher/util/parser.rb +145 -0
- data/spec/private/email/recognize_spec.rb +2 -4
- data/spec/private/generate_spec.rb +86 -32
- data/spec/private/grapher_spec.rb +5 -6
- data/spec/private/parser_spec.rb +75 -0
- data/spec/private/path_spec.rb +35 -4
- data/spec/private/rack/dispatch_spec.rb +100 -15
- data/spec/private/recognize_spec.rb +88 -50
- data/spec/spec_helper.rb +22 -0
- metadata +13 -7
- data/lib/usher/generate.rb +0 -131
- data/spec/private/split_spec.rb +0 -76
data/spec/private/path_spec.rb
CHANGED
@@ -36,18 +36,27 @@ describe "Usher route adding" do
|
|
36
36
|
route_set.add_named_route(:route, '/bad/route', :controller => 'sample').should == route_set.named_routes[:route]
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should allow named routes to be added" do
|
40
|
+
route_set.add_named_route(:route, '/bad/route', :controller => 'sample').should == route_set.named_routes[:route]
|
41
|
+
route_set.route_count.should == 1
|
42
|
+
route_set.named_routes.size == 1
|
43
|
+
route_set.delete_named_route(:route, '/bad/route', :controller => 'sample')
|
44
|
+
route_set.route_count.should == 0
|
45
|
+
route_set.named_routes.size == 0
|
46
|
+
end
|
47
|
+
|
39
48
|
it "should calculate depths for nodes" do
|
40
49
|
route_set.add_named_route(:route, '/bad/route/three/four')
|
41
|
-
route_set.
|
42
|
-
route_set.
|
50
|
+
route_set.root.depth.should == 0
|
51
|
+
route_set.root.lookup['/'].depth.should == 1
|
43
52
|
end
|
44
53
|
|
45
54
|
it "should pp for nodes" do
|
46
55
|
route_set.add_named_route(:route, '/bad/route/three/four')
|
47
|
-
route_set.
|
56
|
+
route_set.root.depth.should == 0
|
48
57
|
old_out = $stdout
|
49
58
|
$stdout = (output = StringIO.new)
|
50
|
-
route_set.
|
59
|
+
route_set.root.lookup['/'].lookup['bad'].lookup['/'].pp
|
51
60
|
$stdout = old_out
|
52
61
|
output.rewind
|
53
62
|
output.read.should == <<-HEREDOC
|
@@ -64,5 +73,27 @@ describe "Usher route adding" do
|
|
64
73
|
8: "four" true
|
65
74
|
HEREDOC
|
66
75
|
end
|
76
|
+
|
77
|
+
describe "merging paths" do
|
78
|
+
before do
|
79
|
+
@r1 = route_set.add_route("/foo/bar")
|
80
|
+
@r2 = route_set.add_route("/other(/:baz)")
|
81
|
+
@p1 = @r1.paths.first
|
82
|
+
@p2 = @r2.paths.first
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should craete a new path object" do
|
86
|
+
@p1.merge(@p2).should_not eql(@p1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should mash the parts together" do
|
90
|
+
@p1.merge(@p2).parts.should == (@p1.parts + @p2.parts).flatten
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should maintain the route owner" do
|
94
|
+
@p1.merge(@p2).route.should == @p1.route
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
67
98
|
|
68
99
|
end
|
@@ -1,29 +1,114 @@
|
|
1
1
|
require 'lib/usher'
|
2
|
-
|
3
2
|
require 'rack'
|
4
3
|
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
5
5
|
route_set = Usher::Interface.for(:rack)
|
6
|
+
route_set.extend(CallWithMockRequestMixin)
|
6
7
|
|
7
8
|
describe "Usher (for rack) route dispatching" do
|
8
|
-
|
9
9
|
before(:each) do
|
10
10
|
route_set.reset!
|
11
|
+
@app = MockApp.new("Hello World!")
|
12
|
+
route_set.add('/sample').to(@app)
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
describe "HTTP GET" do
|
16
|
+
it "should dispatch a request" do
|
17
|
+
response = route_set.call_with_mock_request
|
18
|
+
response.body.should eql("Hello World!")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should write usher.params" do
|
22
|
+
response = route_set.call_with_mock_request
|
23
|
+
@app.env["usher.params"].should == {}
|
24
|
+
end
|
18
25
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
|
27
|
+
describe "HTTP POST" do
|
28
|
+
before(:each) do
|
29
|
+
bad_app = MockApp.new("You shouldn't get here if you are using POST")
|
30
|
+
route_set.add('/sample').to(bad_app)
|
31
|
+
route_set.add('/sample', :requirements => {:request_method => 'POST'}).to(@app)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should dispatch a request" do
|
35
|
+
response = route_set.call_with_mock_request
|
36
|
+
response.body.should eql("Hello World!")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should write usher.params" do
|
40
|
+
response = route_set.call_with_mock_request("/sample", :request_method => 'POST')
|
41
|
+
@app.env["usher.params"].should == {}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should returns HTTP 404 if route doesn't exist" do
|
46
|
+
response = route_set.call_with_mock_request("/not-existing-url")
|
47
|
+
response.status.should eql(404)
|
27
48
|
end
|
28
49
|
|
50
|
+
describe "mounted rack instances" do
|
51
|
+
before do
|
52
|
+
@bad_app = mock("bad_app")
|
53
|
+
|
54
|
+
@usher2 = Usher::Interface.for(:rack)
|
55
|
+
@usher2.add("/good" ).to(@app)
|
56
|
+
@usher2.add("/bad" ).match_partially!.to(@bad_app)
|
57
|
+
@usher2.add("/some(/:foo)").to(@app)
|
58
|
+
|
59
|
+
route_set.add("/foo/:bar", :default_values => {:foo => "foo"}).match_partially!.to(@usher2)
|
60
|
+
route_set.add("/foo", :default_values => {:controller => :foo}).to(@app)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should match the route without nesting" do
|
64
|
+
@app.should_receive(:call).once.with{ |e| e['usher.params'].should == {:controller => :foo}}
|
65
|
+
route_set.call(Rack::MockRequest.env_for("/foo"))
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should route through the first route, and the second to the app" do
|
69
|
+
@app.should_receive(:call).once.with{|e| e['usher.params'].should == {:bar => "bar", :foo => "foo"}}
|
70
|
+
result = route_set.call(Rack::MockRequest.env_for("/foo/bar/good"))
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should go through to the bad app" do
|
74
|
+
@bad_app.should_receive(:call).once.with{|e| e['usher.params'].should == {:bar => "some_bar", :foo => "foo"}}
|
75
|
+
result = route_set.call(Rack::MockRequest.env_for("/foo/some_bar/bad"))
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should match optional routes paramters" do
|
79
|
+
@app.should_receive(:call).once.with{|e| e['usher.params'].should == {:bar => "bar", :foo => "a_different_foo"}}
|
80
|
+
route_set.call(Rack::MockRequest.env_for("/foo/bar/some/a_different_foo"))
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "SCRIPT_NAME & PATH_INFO" do
|
84
|
+
it "should update the script name for a fully consumed route" do
|
85
|
+
@app.should_receive(:call).once.with do |e|
|
86
|
+
e['SCRIPT_NAME'].should == "/foo"
|
87
|
+
e['PATH_INFO'].should == ""
|
88
|
+
end
|
89
|
+
route_set.call(Rack::MockRequest.env_for("/foo"))
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should update the script name and path info for a partially consumed route" do
|
93
|
+
@app.should_receive(:call).once.with do |e|
|
94
|
+
e['SCRIPT_NAME'].should == "/partial"
|
95
|
+
e['PATH_INFO'].should == "/bar/baz"
|
96
|
+
end
|
97
|
+
|
98
|
+
route_set.add("/partial").match_partially!.to(@app)
|
99
|
+
route_set.call(Rack::MockRequest.env_for("/partial/bar/baz"))
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should consume the path through a mounted usher" do
|
103
|
+
@bad_app.should_receive(:call).once.with do |e|
|
104
|
+
e['SCRIPT_NAME'].should == "/foo/bar/bad"
|
105
|
+
e['PATH_INFO'].should == "/leftovers"
|
106
|
+
end
|
107
|
+
|
108
|
+
route_set.call(Rack::MockRequest.env_for("/foo/bar/bad/leftovers"))
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
29
114
|
end
|
@@ -16,21 +16,60 @@ describe "Usher route recognition" do
|
|
16
16
|
route_set.reset!
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
describe 'request conditions' do
|
20
|
+
|
21
|
+
it "should recognize a specific domain name" do
|
22
|
+
target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'})
|
23
|
+
route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https'})
|
24
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).path.route.should == target_route
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should recognize a regex domain name" do
|
28
|
+
target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:domain => /^admin.*$/})
|
29
|
+
route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:domain => 'www.host.com'})
|
30
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :domain => 'admin.host.com'})).path.route.should == target_route
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should recognize a specific route when several http-style restrictions are used" do
|
34
|
+
target_route_http_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
|
35
|
+
target_route_http_www = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'www.spec.com'})
|
36
|
+
target_route_https_msie = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :user_agent => 'MSIE 6.0'})
|
37
|
+
target_route_https_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :domain => 'admin.spec.com'})
|
38
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_http_admin
|
39
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'www.spec.com', :user_agent => nil})).path.route.should == target_route_http_www
|
40
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => 'MSIE 6.0'})).path.route.should == target_route_https_msie
|
41
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_https_admin
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should correctly fix that tree if conditionals are used later" do
|
45
|
+
noop_route = route_set.add_route('/noop', :controller => 'products', :action => 'noop')
|
46
|
+
product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
|
47
|
+
route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).path.route.should == noop_route
|
48
|
+
route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).path.route.should == product_show_route
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use conditionals that are boolean" do
|
52
|
+
# hijacking user_agent
|
53
|
+
insecure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => false, :method => 'get'})
|
54
|
+
secure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => true, :method => 'get'})
|
55
|
+
|
56
|
+
secure_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com', :user_agent => true})).path.route
|
57
|
+
insecure_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com', :user_agent => false})).path.route
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should use conditionals that are arrays" do
|
61
|
+
# hijacking user_agent
|
62
|
+
www_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['www'], :method => 'get'})
|
63
|
+
admin_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['admin'], :method => 'get'})
|
64
|
+
|
65
|
+
admin_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['admin'], :user_agent => true})).path.route
|
66
|
+
www_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['www'], :user_agent => false})).path.route
|
67
|
+
end
|
29
68
|
end
|
30
69
|
|
31
70
|
it "should recognize a format-style variable" do
|
32
71
|
target_route = route_set.add_route('/sample.:format', :controller => 'sample', :action => 'action')
|
33
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:format , 'html']])
|
72
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:format , 'html']], nil, "/sample.html")
|
34
73
|
end
|
35
74
|
|
36
75
|
it "should recognize a glob-style variable" do
|
@@ -93,6 +132,26 @@ describe "Usher route recognition" do
|
|
93
132
|
route_set.recognize(build_request({:method => 'get', :path => '/test/part/hello/again/123/hello/again/onemore'})).params.should == [[:test, ['hello', 'again', '123', 'hello', 'again']], [:party, 'onemore']]
|
94
133
|
end
|
95
134
|
|
135
|
+
it "should recgonize a greedy regex single variable" do
|
136
|
+
target_route = route_set.add_route('/test/part/{!test,one/more/time}')
|
137
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more/time'})).path.route.should == target_route
|
138
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more/time'})).params.should == [[:test, 'one/more/time']]
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should recgonize a greedy regex that matches across / and not" do
|
142
|
+
target_route = route_set.add_route('/test/part/{!test,one/more|one}')
|
143
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more'})).path.route.should == target_route
|
144
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more'})).params.should == [[:test, 'one/more']]
|
145
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one'})).path.route.should == target_route
|
146
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one'})).params.should == [[:test, 'one']]
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should recgonize a greedy regex single variable with static parts after" do
|
150
|
+
target_route = route_set.add_route('/test/part/{!test,one/more/time}/help')
|
151
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more/time/help'})).path.route.should == target_route
|
152
|
+
route_set.recognize(build_request({:method => 'get', :path => '/test/part/one/more/time/help'})).params.should == [[:test, 'one/more/time']]
|
153
|
+
end
|
154
|
+
|
96
155
|
it "should recgonize two glob-style variables separated by a static part" do
|
97
156
|
target_route = route_set.add_route('/*format/innovate/*onemore')
|
98
157
|
response = route_set.recognize(build_request({:method => 'get', :path => '/sample/html/innovate/apple'}))
|
@@ -109,48 +168,12 @@ describe "Usher route recognition" do
|
|
109
168
|
|
110
169
|
it "should recognize a format-style literal" do
|
111
170
|
target_route = route_set.add_route('/:action.html', :controller => 'sample', :action => 'action')
|
112
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample']])
|
171
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample']], nil, "/sample.html")
|
113
172
|
end
|
114
173
|
|
115
174
|
it "should recognize a format-style variable along side another variable" do
|
116
175
|
target_route = route_set.add_route('/:action.:format', :controller => 'sample', :action => 'action')
|
117
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample'], [:format, 'html']])
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should recognize a specific route when several http-style restrictions are used" do
|
121
|
-
target_route_http_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
|
122
|
-
target_route_http_www = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'www.spec.com'})
|
123
|
-
target_route_https_msie = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :user_agent => 'MSIE 6.0'})
|
124
|
-
target_route_https_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :domain => 'admin.spec.com'})
|
125
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_http_admin
|
126
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http', :domain => 'www.spec.com', :user_agent => nil})).path.route.should == target_route_http_www
|
127
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => 'MSIE 6.0'})).path.route.should == target_route_https_msie
|
128
|
-
route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => nil})).path.route.should == target_route_https_admin
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should correctly fix that tree if conditionals are used later" do
|
132
|
-
noop_route = route_set.add_route('/noop', :controller => 'products', :action => 'noop')
|
133
|
-
product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
|
134
|
-
route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).path.route.should == noop_route
|
135
|
-
route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).path.route.should == product_show_route
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should use conditionals that are boolean" do
|
139
|
-
# hijacking user_agent
|
140
|
-
insecure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => false, :method => 'get'})
|
141
|
-
secure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => true, :method => 'get'})
|
142
|
-
|
143
|
-
secure_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com', :user_agent => true})).path.route
|
144
|
-
insecure_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com', :user_agent => false})).path.route
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should use conditionals that are arrays" do
|
148
|
-
# hijacking user_agent
|
149
|
-
www_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['www'], :method => 'get'})
|
150
|
-
admin_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['admin'], :method => 'get'})
|
151
|
-
|
152
|
-
admin_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['admin'], :user_agent => true})).path.route
|
153
|
-
www_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['www'], :user_agent => false})).path.route
|
176
|
+
route_set.recognize(build_request({:method => 'get', :path => '/sample.html', :domain => 'admin.host.com'})).should == Usher::Node::Response.new(target_route.paths.first, [[:action , 'sample'], [:format, 'html']], nil, '/sample.html')
|
154
177
|
end
|
155
178
|
|
156
179
|
it "should use a requirement (proc) on incoming variables" do
|
@@ -174,5 +197,20 @@ describe "Usher route recognition" do
|
|
174
197
|
proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error
|
175
198
|
end
|
176
199
|
|
177
|
-
|
200
|
+
describe "partial recognition" do
|
201
|
+
it "should partially match a route" do
|
202
|
+
route = route_set.add_route("/foo")
|
203
|
+
route.match_partially!
|
204
|
+
route_set.recognize(build_request(:method => "get", :path => "/foo/bar")).should == Usher::Node::Response.new(route.paths.first, [], "/bar", '/foo')
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should partially match a route and use request conditions" do
|
208
|
+
route = route_set.add_route("/foo", :conditions => {:method => 'get'})
|
209
|
+
route.match_partially!
|
210
|
+
|
211
|
+
route_set.recognize(build_request({:method => 'get', :path => '/foo/bar'})).path.route.should == route
|
212
|
+
route_set.recognize(build_request({:method => 'post', :path => '/foo/bar'})).should.nil?
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
178
216
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module CallWithMockRequestMixin
|
2
|
+
def call_with_mock_request(url = "/sample", method = "GET", params = Hash.new)
|
3
|
+
params.merge!(:method => method)
|
4
|
+
request = Rack::MockRequest.new(self)
|
5
|
+
request.request(method, url, params)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class MockApp
|
10
|
+
attr_accessor :status, :headers, :body, :env
|
11
|
+
def initialize(body)
|
12
|
+
@status = 200
|
13
|
+
@headers = {"Content-Type" => "text/html"}
|
14
|
+
@body = body
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@env = env
|
19
|
+
@headers.merge("Content-Length" => @body.length.to_s)
|
20
|
+
[@status, @headers, [@body]]
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hull
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.
|
23
|
+
version: 0.0.6
|
24
24
|
version:
|
25
25
|
description: A general purpose routing library
|
26
26
|
email: joshbuddy@gmail.com
|
@@ -38,7 +38,6 @@ files:
|
|
38
38
|
- VERSION.yml
|
39
39
|
- lib/usher.rb
|
40
40
|
- lib/usher/exceptions.rb
|
41
|
-
- lib/usher/generate.rb
|
42
41
|
- lib/usher/grapher.rb
|
43
42
|
- lib/usher/interface.rb
|
44
43
|
- lib/usher/interface/email_interface.rb
|
@@ -49,16 +48,22 @@ files:
|
|
49
48
|
- lib/usher/interface/rails2_2_interface.rb
|
50
49
|
- lib/usher/interface/rails2_2_interface/mapper.rb
|
51
50
|
- lib/usher/interface/rails2_3_interface.rb
|
51
|
+
- lib/usher/interface/rails3_interface.rb
|
52
52
|
- lib/usher/node.rb
|
53
53
|
- lib/usher/route.rb
|
54
54
|
- lib/usher/route/path.rb
|
55
55
|
- lib/usher/route/request_method.rb
|
56
|
+
- lib/usher/route/util.rb
|
56
57
|
- lib/usher/route/variable.rb
|
57
58
|
- lib/usher/splitter.rb
|
59
|
+
- lib/usher/util.rb
|
60
|
+
- lib/usher/util/generate.rb
|
61
|
+
- lib/usher/util/parser.rb
|
58
62
|
- rails/init.rb
|
59
63
|
- spec/private/email/recognize_spec.rb
|
60
64
|
- spec/private/generate_spec.rb
|
61
65
|
- spec/private/grapher_spec.rb
|
66
|
+
- spec/private/parser_spec.rb
|
62
67
|
- spec/private/path_spec.rb
|
63
68
|
- spec/private/rack/dispatch_spec.rb
|
64
69
|
- spec/private/rails2_2/compat.rb
|
@@ -71,8 +76,8 @@ files:
|
|
71
76
|
- spec/private/rails2_3/recognize_spec.rb
|
72
77
|
- spec/private/recognize_spec.rb
|
73
78
|
- spec/private/request_method_spec.rb
|
74
|
-
- spec/private/split_spec.rb
|
75
79
|
- spec/spec.opts
|
80
|
+
- spec/spec_helper.rb
|
76
81
|
has_rdoc: true
|
77
82
|
homepage: http://github.com/joshbuddy/usher
|
78
83
|
licenses: []
|
@@ -97,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
102
|
requirements: []
|
98
103
|
|
99
104
|
rubyforge_project: joshbuddy-usher
|
100
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.5
|
101
106
|
signing_key:
|
102
107
|
specification_version: 3
|
103
108
|
summary: A general purpose routing library
|
@@ -105,6 +110,7 @@ test_files:
|
|
105
110
|
- spec/private/email/recognize_spec.rb
|
106
111
|
- spec/private/generate_spec.rb
|
107
112
|
- spec/private/grapher_spec.rb
|
113
|
+
- spec/private/parser_spec.rb
|
108
114
|
- spec/private/path_spec.rb
|
109
115
|
- spec/private/rack/dispatch_spec.rb
|
110
116
|
- spec/private/rails2_2/compat.rb
|
@@ -117,4 +123,4 @@ test_files:
|
|
117
123
|
- spec/private/rails2_3/recognize_spec.rb
|
118
124
|
- spec/private/recognize_spec.rb
|
119
125
|
- spec/private/request_method_spec.rb
|
120
|
-
- spec/
|
126
|
+
- spec/spec_helper.rb
|