joshbuddy-usher 0.5.1 → 0.5.2

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.
@@ -16,21 +16,60 @@ describe "Usher route recognition" do
16
16
  route_set.reset!
17
17
  end
18
18
 
19
- it "should recognize a specific domain name" do
20
- target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http'})
21
- route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https'})
22
- route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'http'})).path.route.should == target_route
23
- end
24
-
25
- it "should recognize a regex domain name" do
26
- target_route = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:domain => /^admin.*$/})
27
- route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:domain => 'www.host.com'})
28
- route_set.recognize(build_request({:method => 'get', :path => '/sample', :domain => 'admin.host.com'})).path.route.should == target_route
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
@@ -129,48 +168,12 @@ describe "Usher route recognition" do
129
168
 
130
169
  it "should recognize a format-style literal" do
131
170
  target_route = route_set.add_route('/:action.html', :controller => 'sample', :action => 'action')
132
- 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")
133
172
  end
134
173
 
135
174
  it "should recognize a format-style variable along side another variable" do
136
175
  target_route = route_set.add_route('/:action.:format', :controller => 'sample', :action => 'action')
137
- 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']])
138
- end
139
-
140
- it "should recognize a specific route when several http-style restrictions are used" do
141
- target_route_http_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
142
- target_route_http_www = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'www.spec.com'})
143
- target_route_https_msie = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :user_agent => 'MSIE 6.0'})
144
- target_route_https_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action2', :conditions => {:protocol => 'https', :domain => 'admin.spec.com'})
145
- 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
146
- 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
147
- 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
148
- 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
149
- end
150
-
151
- it "should correctly fix that tree if conditionals are used later" do
152
- noop_route = route_set.add_route('/noop', :controller => 'products', :action => 'noop')
153
- product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
154
- route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).path.route.should == noop_route
155
- route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).path.route.should == product_show_route
156
- end
157
-
158
- it "should use conditionals that are boolean" do
159
- # hijacking user_agent
160
- insecure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => false, :method => 'get'})
161
- secure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => true, :method => 'get'})
162
-
163
- 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
164
- 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
165
- end
166
-
167
- it "should use conditionals that are arrays" do
168
- # hijacking user_agent
169
- www_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['www'], :method => 'get'})
170
- admin_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:subdomains => ['admin'], :method => 'get'})
171
-
172
- admin_product_show_route.should == route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :subdomains => ['admin'], :user_agent => true})).path.route
173
- 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')
174
177
  end
175
178
 
176
179
  it "should use a requirement (proc) on incoming variables" do
@@ -194,5 +197,20 @@ describe "Usher route recognition" do
194
197
  proc {route_set.recognize(build_request({:method => 'get', :path => '/products/show/qweasd', :domain => 'admin.host.com'}))}.should raise_error
195
198
  end
196
199
 
197
-
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
198
216
  end
@@ -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: joshbuddy-usher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
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-22 00:00:00 -07:00
12
+ date: 2009-08-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,6 +48,7 @@ files:
48
48
  - lib/usher/interface/rails2_2_interface.rb
49
49
  - lib/usher/interface/rails2_2_interface/mapper.rb
50
50
  - lib/usher/interface/rails2_3_interface.rb
51
+ - lib/usher/interface/rails3_interface.rb
51
52
  - lib/usher/node.rb
52
53
  - lib/usher/route.rb
53
54
  - lib/usher/route/path.rb
@@ -76,6 +77,7 @@ files:
76
77
  - spec/private/recognize_spec.rb
77
78
  - spec/private/request_method_spec.rb
78
79
  - spec/spec.opts
80
+ - spec/spec_helper.rb
79
81
  has_rdoc: false
80
82
  homepage: http://github.com/joshbuddy/usher
81
83
  licenses:
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  version:
99
101
  requirements: []
100
102
 
101
- rubyforge_project:
103
+ rubyforge_project: joshbuddy-usher
102
104
  rubygems_version: 1.3.5
103
105
  signing_key:
104
106
  specification_version: 3
@@ -120,3 +122,4 @@ test_files:
120
122
  - spec/private/rails2_3/recognize_spec.rb
121
123
  - spec/private/recognize_spec.rb
122
124
  - spec/private/request_method_spec.rb
125
+ - spec/spec_helper.rb