Skip to content

Commit

Permalink
Make recognize try to constantize controller to see if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Dec 2, 2009
1 parent 30ae353 commit 7fe19d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions actionpack/lib/action_dispatch/routing/route_set.rb
Expand Up @@ -28,6 +28,7 @@ def call(env)
end

if env['action_controller.recognize']
controller(params)
[200, {}, params]
else
controller = controller(params)
Expand All @@ -41,6 +42,8 @@ def controller(params)
controller = "#{params[:controller].camelize}Controller"
ActiveSupport::Inflector.constantize(controller)
end
rescue NameError => e
raise ActionController::RoutingError, e.message
end

def merge_default_action!(params)
Expand Down
2 changes: 0 additions & 2 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -1851,11 +1851,9 @@ def test_recognize_path
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009'}, @routes.recognize_path('/blog/2009', :method => :get))
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009', :month => '01'}, @routes.recognize_path('/blog/2009/01', :method => :get))
assert_equal({:controller => 'posts', :action => 'show_date', :year => '2009', :month => '01', :day => '01'}, @routes.recognize_path('/blog/2009/01/01', :method => :get))
assert_raise(ActionController::ActionControllerError) { @routes.recognize_path('/blog/123456789', :method => :get) }

assert_equal({:controller => 'archive', :action => 'index', :year => '2010'}, @routes.recognize_path('/archive/2010'))
assert_equal({:controller => 'archive', :action => 'index'}, @routes.recognize_path('/archive'))
assert_raise(ActionController::ActionControllerError) { @routes.recognize_path('/archive/january') }

assert_equal({:controller => 'people', :action => 'index'}, @routes.recognize_path('/people', :method => :get))
assert_equal({:controller => 'people', :action => 'index', :format => 'xml'}, @routes.recognize_path('/people.xml', :method => :get))
Expand Down
13 changes: 12 additions & 1 deletion actionpack/test/lib/controller/fake_controllers.rb
@@ -1,37 +1,48 @@
class << Object; alias_method :const_available?, :const_defined?; end

class ContentController < ActionController::Base; end
class NotAController; end

module Admin
class << self; alias_method :const_available?, :const_defined?; end
class AccountsController < ActionController::Base; end
class NewsFeedController < ActionController::Base; end
class PostsController < ActionController::Base; end
class StuffController < ActionController::Base; end
class UserController < ActionController::Base; end
class UsersController < ActionController::Base; end
end

module Api
class UsersController < ActionController::Base; end
class ProductsController < ActionController::Base; end
end

# TODO: Reduce the number of test controllers we use
class AccountController < ActionController::Base; end
class AddressesController < ActionController::Base; end
class ArchiveController < ActionController::Base; end
class ArticlesController < ActionController::Base; end
class BarController < ActionController::Base; end
class BlogController < ActionController::Base; end
class BooksController < ActionController::Base; end
class BraveController < ActionController::Base; end
class CarsController < ActionController::Base; end
class CcController < ActionController::Base; end
class CController < ActionController::Base; end
class ElsewhereController < ActionController::Base; end
class FooController < ActionController::Base; end
class GeocodeController < ActionController::Base; end
class HiController < ActionController::Base; end
class ImageController < ActionController::Base; end
class NewsController < ActionController::Base; end
class NotesController < ActionController::Base; end
class PeopleController < ActionController::Base; end
class PostsController < ActionController::Base; end
class SessionsController < ActionController::Base; end
class StuffController < ActionController::Base; end
class SubpathBooksController < ActionController::Base; end
class SymbolsController < ActionController::Base; end
class UserController < ActionController::Base; end
class WeblogController < ActionController::Base; end

# For speed test
Expand Down

0 comments on commit 7fe19d4

Please sign in to comment.