spec/recognize_spec.rb in joshbuddy-usher-0.3.0 vs spec/recognize_spec.rb in joshbuddy-usher-0.3.2
- old
+ new
@@ -34,16 +34,16 @@
target_route = route_set.add_route('/sample.:format', :controller => 'sample', :action => 'action')
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']])
end
it "should recognize a format-style literal" do
- target_route = route_set.add_route(':action.html', :controller => 'sample', :action => 'action')
+ target_route = route_set.add_route('/:action.html', :controller => 'sample', :action => 'action')
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']])
end
it "should recognize a format-style variable along side another variable" do
- target_route = route_set.add_route(':action.:format', :controller => 'sample', :action => 'action')
+ target_route = route_set.add_route('/:action.:format', :controller => 'sample', :action => 'action')
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']])
end
it "should recognize a specific route when several http-style restrictions are used" do
target_route_http_admin = route_set.add_route('/sample', :controller => 'sample', :action => 'action', :conditions => {:protocol => 'http', :domain => 'admin.spec.com'})
@@ -55,13 +55,22 @@
target_route_https_msie.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => 'MSIE 6.0'})).first).should == true
target_route_https_admin.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/sample', :protocol => 'https', :domain => 'admin.spec.com', :user_agent => nil})).first).should == true
end
it "should correctly fix that tree if conditionals are used later" do
- noop_route = route_set.add_route('noop', :controller => 'products', :action => 'noop')
+ noop_route = route_set.add_route('/noop', :controller => 'products', :action => 'noop')
product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:method => 'get'})
noop_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/noop', :domain => 'admin.host.com'})).first).should == true
product_show_route.paths.include?(route_set.recognize(build_request({:method => 'get', :path => '/products/show/123', :domain => 'admin.host.com'})).first).should == true
+ end
+
+ it "should use conditionals that are boolean" do
+ # hijacking user_agent
+ insecure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => false, :method => 'get'})
+ secure_product_show_route = route_set.add_route('/products/show/:id', :id => /\d+/, :conditions => {:user_agent => true, :method => 'get'})
+
+ 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
+ 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
end
it "should use a transformer (proc) on incoming variables" do
route_set.add_route('/:controller/:action/:id', :transformers => {:id => proc{|v| v.to_i}})
route_set.recognize(build_request({:method => 'get', :path => '/products/show/123asd', :domain => 'admin.host.com'})).params.rassoc(123).first.should == :id
\ No newline at end of file