usher 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,7 @@ regex allows.
68
68
  * <tt>/product/hello/world</tt>
69
69
  * <tt>/product/hello</tt>
70
70
 
71
+
71
72
  ==== Static
72
73
 
73
74
  Static parts of literal character sequences. For instance, <tt>/path/something.html</tt> would match only the same path.
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 5
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -4,6 +4,22 @@ class Usher
4
4
  module Interface
5
5
  class RackInterface
6
6
 
7
+ attr_reader :router
8
+
9
+ class Builder < Rack::Builder
10
+
11
+ def initialize(&block)
12
+ @usher = Usher::Interface::RackInterface.new
13
+ super
14
+ end
15
+
16
+ def map(path, options = nil, &block)
17
+ @usher.add(path, options).to(&block)
18
+ @ins << @usher unless @ins.last == @usher
19
+ end
20
+
21
+ end
22
+
7
23
  def initialize(&blk)
8
24
  @router = Usher.new(:request_methods => [:request_method, :host, :port, :scheme], :generator => Usher::Util::Generators::URL.new)
9
25
  instance_eval(&blk) if blk
@@ -145,7 +145,7 @@ class Usher
145
145
  end
146
146
 
147
147
  current_node = self
148
- until parts.size.zero?
148
+ while !parts.size.zero? || current_node.exclusive_type
149
149
  key = parts.shift
150
150
  target_node = case key
151
151
  when Route::RequestMethod
@@ -174,11 +174,13 @@ class Usher
174
174
  current_node.send(lookup_method)[nil] ||= Node.new(current_node, key)
175
175
  end
176
176
  else
177
+
177
178
  current_node.upgrade_lookup if key.is_a?(Regexp)
178
179
  current_node.lookup[key] ||= Node.new(current_node, key)
179
180
  end
180
181
  current_node = target_node
181
182
  end
183
+
182
184
  current_node.terminates = destination
183
185
  end
184
186
 
@@ -9,10 +9,14 @@ describe "Usher (for rack) route dispatching" do
9
9
  before(:each) do
10
10
  route_set.reset!
11
11
  @app = MockApp.new("Hello World!")
12
- route_set.add('/sample').to(@app)
13
12
  end
14
13
 
15
14
  describe "HTTP GET" do
15
+ before(:each) do
16
+ route_set.reset!
17
+ route_set.add('/sample', :conditions => {:request_method => 'GET'}).to(@app)
18
+ end
19
+
16
20
  it "should dispatch a request" do
17
21
  response = route_set.call_with_mock_request
18
22
  response.body.should eql("Hello World!")
@@ -26,18 +30,23 @@ describe "Usher (for rack) route dispatching" do
26
30
 
27
31
  describe "HTTP POST" do
28
32
  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)
33
+ route_set.reset!
34
+ route_set.add('/sample', :conditions => {:request_method => 'POST'}).to(@app)
35
+ route_set.add('/sample').to(MockApp.new("You shouldn't get here if you are using POST"))
32
36
  end
33
37
 
34
- it "should dispatch a request" do
35
- response = route_set.call_with_mock_request
38
+ it "should dispatch a POST request" do
39
+ response = route_set.call_with_mock_request('/sample', 'POST')
36
40
  response.body.should eql("Hello World!")
37
41
  end
38
42
 
43
+ it "shouldn't dispatch a GET request" do
44
+ response = route_set.call_with_mock_request('/sample', 'GET')
45
+ response.body.should eql("You shouldn't get here if you are using POST")
46
+ end
47
+
39
48
  it "should write usher.params" do
40
- response = route_set.call_with_mock_request("/sample", :request_method => 'POST')
49
+ response = route_set.call_with_mock_request("/sample", 'POST')
41
50
  @app.env["usher.params"].should == {}
42
51
  end
43
52
  end
@@ -31,10 +31,10 @@ describe "Usher route recognition" do
31
31
  end
32
32
 
33
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'})
34
+ target_route_http_admin = route_set.add_route('/sample', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
35
+ target_route_http_www = route_set.add_route('/sample', :conditions => {:protocol => 'http', :domain => 'www.spec.com'})
36
+ target_route_https_msie = route_set.add_route('/sample', :conditions => {:protocol => 'https', :user_agent => 'MSIE 6.0'})
37
+ target_route_https_admin = route_set.add_route('/sample', :conditions => {:protocol => 'https', :domain => 'admin.spec.com'})
38
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
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
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
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.2
4
+ version: 0.5.3
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-08-26 00:00:00 -04:00
12
+ date: 2009-08-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency