4

i would like to add a route that is only available in test environment, so i would prefer not to pollute routes.rb file. i cannot seem to find a working way to add a route dynamically after original routes were drawn. i tried this https://gist.github.com/1351762 but that didn't quite work

How can I add a new route after routes.rb has already loaded and processed all the routes?

2 Answers 2

5

The with_routing test helper redefines routes within a block.

 with_routing do |map|
   map.draw do
    resources :test, only: [:show]
   end

   get :show
   assert assigns(:test)
 end
3

After some tries and errors, I found that:

Rails.application.routes.eval_block(Proc.new do                                                                             
  get "/backdoor", :to => "backdoors#backdoor"                                                                         
end)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.