Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Enumerates routed controllers and actions and checks if they exist in the code (simple and quick, without corner cases). Tested on Rails 3.2.8

View quick_route_tester.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Rails.application.eager_load!
all_routes = Rails.application.routes.routes
 
controllers=ApplicationController.descendants
#controller_names = controllers.collect {|c| c.to_s.underscore.sub('_controller','') }
controller_names={}
controllers.each {|c|
controller_names[c.to_s]=c.to_s.underscore.sub('_controller','')
}.size
 
missing_stuff_names = {}
 
all_routes.each {|route|
routed_controller = route.defaults[:controller]
routed_action = route.defaults[:action]
next unless routed_controller
#puts "routed_controller: #{routed_controller} , routed_action: #{routed_action}"
unless controller_names.values.include? routed_controller
#controller is routed but totally missing from code
missing_stuff_names[routed_controller]||=[]
missing_stuff_names[routed_controller] << routed_action
pp "#{routed_controller} totally missing, should also have action: #{routed_action}"
else
unless controller_names.key(routed_controller).constantize.action_methods.to_a.include? routed_action
#controller is present in code but misses some routed actions
missing_stuff_names[routed_controller]||=[]
missing_stuff_names[routed_controller] << routed_action
pp "#{routed_controller} missing action: #{routed_action}"
end
end
}.size
 
pp missing_stuff_names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.