require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe "Routing" do describe "Paths Generated by Custom Routes:" do # paths generated by custom routes it "should have a path for showing the email form" do { :get => "/catalog/email" }.should route_to(:controller => 'catalog', :action => 'email') end it "should have a path for sending the email" do { :post => "/catalog/email" }.should route_to(:controller => 'catalog', :action => 'email') end it "should map {:controller => 'catalog', :action => 'sms'} to /catalog/sms" do { :get => "/catalog/sms" }.should route_to(:controller => 'catalog', :action => 'sms') end it "should map { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do { :get => "/catalog/666" }.should route_to(:controller => 'catalog', :action => 'show', :id => "666") end it "should map {:controller => 'catalog', :id => '111', :action => 'librarian_view'} to /catalog/111/librarian_view" do { :get => "/catalog/111/librarian_view" }.should route_to(:controller => 'catalog', :action => 'librarian_view', :id => "111") { :get => librarian_view_catalog_path('111') }.should route_to(:controller => 'catalog', :action => 'librarian_view', :id => "111") end end describe "catalog_path for SolrDocument", :test => true do it "should route correctly" do { :get => catalog_path(SolrDocument.new(:id => 'asdf')) }.should route_to(:controller => 'catalog', :action => 'show', :id => 'asdf') end context "should escape solr document ids" do it "should pass-through url-valid ids" do { :get => catalog_path(SolrDocument.new(:id => 'qwerty'))}.should route_to(:controller => 'catalog', :action => 'show', :id => 'qwerty') end it "should route url-like ids" do pending "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though" { :get => catalog_path(SolrDocument.new(:id => 'http://example.com'))}.should route_to(:controller => 'catalog', :action => 'show', :id => 'http://example.com') end it "should route ids with whitespace" do { :get => catalog_path(SolrDocument.new(:id => 'mm 123')) }.should route_to(:controller => 'catalog', :action => 'show', :id => 'mm 123') end it "should route ids with a literal '+'" do { :get => catalog_path(SolrDocument.new(:id => 'this+that')) }.should route_to(:controller => 'catalog', :action => 'show', :id => 'this+that') end it "should route ids with a literal '/" do pending "This works if you configure your routing to have very liberal constraints on :id.. not sure how to go about testing it though" { :get => catalog_path(SolrDocument.new(:id => 'and/or')) }.should route_to(:controller => 'catalog', :action => 'show', :id => 'and/or') end end end end