usher 0.5.5 → 0.5.6
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.
- data/VERSION.yml +1 -1
- data/lib/usher/interface/rack_interface.rb +26 -14
- data/lib/usher/interface/rails3_interface.rb +2 -1
- data/lib/usher/node.rb +5 -1
- data/spec/private/rack/dispatch_spec.rb +9 -3
- data/spec/private/rack/generate_spec.rb +41 -0
- data/spec/private/recognize_spec.rb +8 -1
- metadata +4 -2
data/VERSION.yml
CHANGED
@@ -62,8 +62,8 @@ class Usher
|
|
62
62
|
determine_respondant(response).call(env)
|
63
63
|
end
|
64
64
|
|
65
|
-
def generate(route,
|
66
|
-
@
|
65
|
+
def generate(route, options = nil)
|
66
|
+
@router.generator.generate(route, options)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Allows a hook to be placed for sub classes to make use of between matching
|
@@ -71,14 +71,17 @@ class Usher
|
|
71
71
|
#
|
72
72
|
# @api plugin
|
73
73
|
def after_match(env, response)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
params = response.path.route.default_values ?
|
75
|
+
response.path.route.default_values.merge(Hash[response.params]) :
|
76
|
+
Hash[response.params]
|
77
|
+
|
78
|
+
env['usher.params'] ?
|
79
|
+
env['usher.params'].merge!(params) :
|
80
|
+
env['usher.params'] = params
|
81
|
+
|
82
|
+
# consume the path_info to the script_name
|
83
|
+
# response.remaining_path
|
84
|
+
consume_path!(env, response) if response.partial_match?
|
82
85
|
end
|
83
86
|
|
84
87
|
# Determines which application to respond with.
|
@@ -89,10 +92,19 @@ class Usher
|
|
89
92
|
#
|
90
93
|
# @api private
|
91
94
|
def determine_respondant(response)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
unless response
|
96
|
+
app
|
97
|
+
else
|
98
|
+
respondant = response.path.route.destination
|
99
|
+
respondant = app unless respondant.respond_to?(:call)
|
100
|
+
respondant
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Consume the path from path_info to script_name
|
105
|
+
def consume_path!(env, response)
|
106
|
+
env["SCRIPT_NAME"] = (env["SCRIPT_NAME"] + response.matched_path) || ""
|
107
|
+
env["PATH_INFO"] = response.remaining_path || ""
|
96
108
|
end
|
97
109
|
end
|
98
110
|
end
|
@@ -26,12 +26,13 @@ class Usher
|
|
26
26
|
@configurations_files << file
|
27
27
|
end
|
28
28
|
|
29
|
-
def reload
|
29
|
+
def reload
|
30
30
|
@usher.reset!
|
31
31
|
@configurations_files.each do |c|
|
32
32
|
Kernel.load(c)
|
33
33
|
end
|
34
34
|
end
|
35
|
+
alias_method :reload!, :reload
|
35
36
|
|
36
37
|
def call(env)
|
37
38
|
request = ActionDispatch::Request.new(env)
|
data/lib/usher/node.rb
CHANGED
@@ -4,7 +4,11 @@ class Usher
|
|
4
4
|
|
5
5
|
class Node
|
6
6
|
|
7
|
-
Response
|
7
|
+
class Response < Struct.new(:path, :params, :remaining_path, :matched_path)
|
8
|
+
def partial_match?
|
9
|
+
!remaining_path.nil?
|
10
|
+
end
|
11
|
+
end
|
8
12
|
|
9
13
|
attr_reader :normal, :greedy, :request
|
10
14
|
attr_accessor :terminates, :request_method_type, :parent, :value, :request_methods
|
@@ -90,10 +90,10 @@ describe "Usher (for rack) route dispatching" do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
describe "SCRIPT_NAME & PATH_INFO" do
|
93
|
-
it "
|
93
|
+
it "shouldn't update the script name for a fully consumed route" do
|
94
94
|
@app.should_receive(:call).once.with do |e|
|
95
|
-
e['SCRIPT_NAME'].should == "
|
96
|
-
e['PATH_INFO'].should == ""
|
95
|
+
e['SCRIPT_NAME'].should == ""
|
96
|
+
e['PATH_INFO'].should == "/foo"
|
97
97
|
end
|
98
98
|
route_set.call(Rack::MockRequest.env_for("/foo"))
|
99
99
|
end
|
@@ -117,6 +117,12 @@ describe "Usher (for rack) route dispatching" do
|
|
117
117
|
route_set.call(Rack::MockRequest.env_for("/foo/bar/bad/leftovers"))
|
118
118
|
end
|
119
119
|
|
120
|
+
it "should not modify SCRIPT_NAME in place since thin freezes it" do
|
121
|
+
@app.should_receive(:call).once
|
122
|
+
env = Rack::MockRequest.env_for("/foo/bar/good")
|
123
|
+
env["SCRIPT_NAME"] = "".freeze
|
124
|
+
route_set.call(env)
|
125
|
+
end
|
120
126
|
end
|
121
127
|
|
122
128
|
describe "dupping" do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'lib/usher'
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
|
5
|
+
route_set = Usher::Interface.for(:rack)
|
6
|
+
route_set.extend(CallWithMockRequestMixin)
|
7
|
+
|
8
|
+
describe "Usher (for rack) route generation" do
|
9
|
+
before(:each) do
|
10
|
+
route_set.reset!
|
11
|
+
@app = MockApp.new("Hello World!")
|
12
|
+
route_set.add("/fixed").name(:fixed)
|
13
|
+
route_set.add("/simple/:simple_var")
|
14
|
+
route_set.add("/named/simple/:named_simple_var").name(:simple)
|
15
|
+
route_set.add("/optional(/:optional_var)")
|
16
|
+
route_set.add("/named/optional(/:named_optional_var)").name(:optional)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "named routes" do
|
20
|
+
it "should generate a fixed path" do
|
21
|
+
route_set.generate(:fixed).should == "/fixed"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should generate a basic path route" do
|
25
|
+
route_set.generate(nil, :simple_var => "simple_var").should == "/simple/simple_var"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should generate a named path route" do
|
29
|
+
route_set.generate(:simple, :named_simple_var => "the_var").should == "/named/simple/the_var"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should generate a route with options" do
|
33
|
+
route_set.generate(nil, :optional_var => "var").should == "/optional/var"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should generate a named route with options" do
|
37
|
+
route_set.generate(:optional).should == "/named/optional"
|
38
|
+
route_set.generate(:optional, :named_optional_var => "the_var").should == "/named/optional/the_var"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -223,6 +223,13 @@ describe "Usher route recognition" do
|
|
223
223
|
route_set.recognize(build_request({:method => 'post', :path => '/foo/bar'})).should.nil?
|
224
224
|
end
|
225
225
|
|
226
|
+
it "should not match partially when a route is not set as partially matched" do
|
227
|
+
route = route_set.add_route("/foo", :foo => :bar)
|
228
|
+
route_set.recognize(build_request(:path => "/foo")).path.route.should == route
|
229
|
+
route_set.recognize(build_request(:path => "/foo/bar")).should be_nil
|
230
|
+
end
|
231
|
+
|
232
|
+
|
226
233
|
end
|
227
234
|
|
228
235
|
describe "dup safety" do
|
@@ -271,4 +278,4 @@ describe "Usher route recognition" do
|
|
271
278
|
end
|
272
279
|
|
273
280
|
end
|
274
|
-
end
|
281
|
+
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.5.
|
4
|
+
version: 0.5.6
|
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-09-
|
12
|
+
date: 2009-09-15 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- spec/private/parser_spec.rb
|
69
69
|
- spec/private/path_spec.rb
|
70
70
|
- spec/private/rack/dispatch_spec.rb
|
71
|
+
- spec/private/rack/generate_spec.rb
|
71
72
|
- spec/private/rails2_2/compat.rb
|
72
73
|
- spec/private/rails2_2/generate_spec.rb
|
73
74
|
- spec/private/rails2_2/path_spec.rb
|
@@ -115,6 +116,7 @@ test_files:
|
|
115
116
|
- spec/private/parser_spec.rb
|
116
117
|
- spec/private/path_spec.rb
|
117
118
|
- spec/private/rack/dispatch_spec.rb
|
119
|
+
- spec/private/rack/generate_spec.rb
|
118
120
|
- spec/private/rails2_2/compat.rb
|
119
121
|
- spec/private/rails2_2/generate_spec.rb
|
120
122
|
- spec/private/rails2_2/path_spec.rb
|