Note that there are some explanatory texts on larger screens.

plurals
  1. PORSpec for routes and testing routes.rb specifically
    primarykey
    data
    text
    <p>I'm trying to write test for my costume routes, along with non existing routes.</p> <p>For the examples down here I have two problems: </p> <ol> <li>It matches the actions that don't exist on my controller, so it doesn't really match to see if my controller have those actions, it just matches the syntax</li> <li>the <code>should_not be_routable</code> doesn't work, which kind of goes back to the above problem of it doesn't check against my controller or the <code>routes.rb</code> file to see if the route should exist.</li> </ol> <p>This one passes and is all good:</p> <pre><code>it "should route to method1" do { :get =&gt; '/my_controller/method1' }.should route_to(:controller =&gt; 'my_controller', :action =&gt; 'method1') end </code></pre> <p>this one fails, so it doesn't even check to see if I have a method zz defined in my controller or routes file.</p> <pre><code>it "should not route to zz" do { :get =&gt; '/my_controller/zz' }.should_not be_routable end </code></pre> <p>the error I get is:</p> <pre><code>MyController routing zz should route to rescan Failure/Error: { :get =&gt; '/my_controller/zz' }.should_not be_routable expected {:get=&gt;"/client_rescan/zz"} not to be routable, but it routes to {:controller=&gt;"my_controller", :action=&gt;"zz"} </code></pre> <p>So it obviously doesn't look at my routes file at all...</p> <p>This is another example of it doesn't look at my routes file, in my routes I have ' resources :client_rescan, :only => [:index] ' and when I do <code>rake routes</code> it doesn't show delete as expected, but the test doesn't look at those:</p> <pre><code>it "should not have route to delete" do { :delete =&gt; '/my_controller/1'}.should_not be_routable end </code></pre> <p>The Failure I get is the following. Which looks like it doesn't even see the delete function:</p> <pre><code> Failure/Error: { :delete =&gt; '/my_controller/1'}.should_not be_routable expected {:delete=&gt;"/my_controller/1"} not to be routable, but it routes to {:controller=&gt;"my_controller", :action=&gt;"1"} </code></pre> <p>Another problem is my post routes to index in the test:</p> <pre><code>it "should not have route to post" do { :post =&gt; '/my_controller' }.should_not be_routable end </code></pre> <p>The Failure I get is:</p> <pre><code> Failure/Error: { :post =&gt; '/my_controller' }.should_not be_routable expected {:post=&gt;"/my_controller"} not to be routable, but it routes to {:controller=&gt;"my_controller", :action=&gt;"index"} </code></pre> <p>this is content of my routes.rb file</p> <pre><code>require 'resque/server' require 'resque_scheduler' Cdc::Application.routes.draw do mount Resque::Server.new, :at =&gt; 'resque' Resque.schedule = YAML.load_file(File.join(File.dirname(__FILE__), 'resque_schedule.yml')) # load the schedule devise_for :users, :controllers =&gt; { :sessions =&gt; "sessions", :registrations =&gt; "registrations" } [:assessments, :security_assessments, :privacy_assessments].each do |assessment_type| resources assessment_type, :controller =&gt; :assessments do resources :rsz do post 'review', :on =&gt; :member get 'judgement', :on =&gt; :member end get :judgement, :on =&gt; :member resources :samples do get 'download', :on =&gt; :member end resources :asm_reviews do post :request_review, :on =&gt; :collection end end end resources :account_creator match "/images/captcha/*file_name" =&gt; "captcha#show" ## this is where my route is!! :) resources :my_controller, :only =&gt; [:index] do collection do get :rescan get :cancel end end match "alert_queue/words" =&gt; "alert_queue#words" resources :alert_queue match "calls_to_action/start/:id" =&gt; "calls_to_action#start", :id =&gt; /\d+/ match "calls_to_action/close/:id" =&gt; "calls_to_action#close", :id =&gt; /\d+/ match "calls_to_action/comment/:id" =&gt; "calls_to_action#comment", :id =&gt; /\d+/ match "calls_to_action/multiclose" =&gt; "calls_to_action#multiclose" match "calls_to_action/multiscan" =&gt; "calls_to_action#multiscan" match "application_instances/multiclose" =&gt; "application_instances#multiclose" match "application_instances/multiscan" =&gt; "application_instances#multiscan" resources :code_categories do resources :code_families do resources :code_family_versions end end resources :code_policy_items resources :application_instances do collection do post :resque_statuses end resources :code_indices resources :application_analysis get "smali/:smali_path", :as =&gt; :smali, :on =&gt; :member, :action =&gt; :smali, :smali_path =&gt; /.*/ member do get :file get :strings get :dump get :alerts get :correlations get :signers get :icon get :resque_status get :assets get :new_code_index get :class_list get :heuristic_hits get :engine_artifacts post :rescan post :attach_artifact post :engine_artifact, :action =&gt; :attach_engine_artifact resources :alerts end post "multiscan", :on =&gt; :collection, :action =&gt; :multiscan post "multiclose", :on =&gt; :collection, :action=&gt; :multiclose post "engines/:engine_name/:engine_version/assertions/:cookie", :on =&gt; :member, :action =&gt; :register_assertion_set, :as =&gt; :register_assertion_set, :engine_name =&gt; /[^\/]+/, :engine_version =&gt; /[^\/]+/, :cookie =&gt; /[^\/]+/ post "engines/:engine_name/:engine_version/network_data", :on =&gt; :member, :action =&gt; :register_network_data, :as =&gt; :register_network_data, :engine_name =&gt; /[^\/]+/, :engine_version =&gt; /[^\/]+/ post "assets", :on =&gt; :member, :action =&gt; :register_asset_set, :as =&gt; :register_asset_set end # index gets the list of families, show gets the assertion types for that family resources :assertion_families resources :artifacts resources :dashboard do collection do get :last_app_instance end end match '/direct_downloads/' =&gt; 'direct_downloads#index' root :to =&gt; "stats#index" match '/' =&gt; 'stats#index' match 'explorer/query/:format' =&gt; 'explorer#query' match '/:controller(/:action(/:id))' end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload