Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created August 26, 2010 18:05
Show Gist options
  • Save bogdan/551880 to your computer and use it in GitHub Desktop.
Save bogdan/551880 to your computer and use it in GitHub Desktop.
namespace :routes do
task :check => [:environment] do
STANDARD_METHODS = %w(index new create show edit update destroy)
SUPPORT_CONTROLLERS = [ "ApplicationController", /BaseController$/]
unexisted_controllers = []
unexisted_actions = []
bound_controllers = []
ActionController::Routing::Routes.routes.each do |route|
controller_path = route.requirements[:controller]
if controller_path
bound_controllers << controller_path
action_name = route.requirements[:action]
controller_name = controller_path.camelize + "Controller"
begin
controller_class = controller_name.constantize
unless controller_class.public_instance_methods.include?(action_name) || STANDARD_METHODS.include?(action_name)
unexisted_actions << "#{route.requirements.inspect}: #{controller_name} don't have public method :#{action_name}"
end
rescue NameError => error
unexisted_controllers << "#{controller_path}: #{error}"
end
end
end
puts "Unbound controllers:"
ActionController::Base.subclasses.each do |controller|
routing_name = controller.underscore.sub(/_controller$/, "")
unless bound_controllers.include?(routing_name)
SUPPORT_CONTROLLERS.each do |matcher|
unless matcher.match(routing_name)
puts "\t#{controller}: Not present in routes"
end
end
end
end
puts "Unexisted controllers:"
unexisted_controllers.uniq.each do |error|
puts "\t#{error}"
end
puts "Unexisted actions:"
unexisted_actions.uniq.each do |error|
puts "\t#{error}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment