mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Track all AC base subclasses as possible controllers for internal testing
This commit is contained in:
parent
5bc66f160d
commit
78129b1731
6 changed files with 48 additions and 90 deletions
|
@ -62,8 +62,20 @@ module ActionController
|
||||||
}
|
}
|
||||||
Base.session_store = nil
|
Base.session_store = nil
|
||||||
|
|
||||||
|
class << Routing
|
||||||
|
def possible_controllers
|
||||||
|
@@possible_controllers ||= []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
include ActionController::Testing
|
include ActionController::Testing
|
||||||
|
|
||||||
|
def self.inherited(klass)
|
||||||
|
name = klass.name.underscore.sub(/_controller$/, '')
|
||||||
|
ActionController::Routing.possible_controllers << name unless name.blank?
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.view_paths = FIXTURE_LOAD_PATH
|
Base.view_paths = FIXTURE_LOAD_PATH
|
||||||
|
|
|
@ -182,14 +182,6 @@ end
|
||||||
|
|
||||||
# a test case to exercise the new capabilities TestRequest & TestResponse
|
# a test case to exercise the new capabilities TestRequest & TestResponse
|
||||||
class ActionPackAssertionsControllerTest < ActionController::TestCase
|
class ActionPackAssertionsControllerTest < ActionController::TestCase
|
||||||
# let's get this party started
|
|
||||||
def setup
|
|
||||||
super
|
|
||||||
|
|
||||||
ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
|
|
||||||
ActionController::Routing::Routes.load_routes!
|
|
||||||
end
|
|
||||||
|
|
||||||
# -- assertion-based testing ------------------------------------------------
|
# -- assertion-based testing ------------------------------------------------
|
||||||
|
|
||||||
def test_assert_tag_and_url_for
|
def test_assert_tag_and_url_for
|
||||||
|
|
|
@ -44,11 +44,11 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_route_recognition_unescapes_path_components
|
def test_route_recognition_unescapes_path_components
|
||||||
options = { :controller => "controller",
|
options = { :controller => "content",
|
||||||
:action => "act#{@segment}ion",
|
:action => "act#{@segment}ion",
|
||||||
:variable => "var#{@segment}iable",
|
:variable => "var#{@segment}iable",
|
||||||
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
|
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
|
||||||
assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
|
assert_equal options, @set.recognize_path("/content/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_route_generation_allows_passing_non_string_values_to_generated_helper
|
def test_route_generation_allows_passing_non_string_values_to_generated_helper
|
||||||
|
@ -60,58 +60,6 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
class RoutingTest < Test::Unit::TestCase
|
class RoutingTest < Test::Unit::TestCase
|
||||||
def test_possible_controllers
|
|
||||||
true_controller_paths = ActionController::Routing.controller_paths
|
|
||||||
|
|
||||||
ActionController::Routing.use_controllers! nil
|
|
||||||
|
|
||||||
Object.send(:remove_const, :RAILS_ROOT) if defined?(::RAILS_ROOT)
|
|
||||||
Object.const_set(:RAILS_ROOT, File.dirname(__FILE__) + '/controller_fixtures')
|
|
||||||
|
|
||||||
ActionController::Routing.controller_paths = [
|
|
||||||
RAILS_ROOT, RAILS_ROOT + '/app/controllers', RAILS_ROOT + '/vendor/plugins/bad_plugin/lib'
|
|
||||||
]
|
|
||||||
|
|
||||||
assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort
|
|
||||||
ensure
|
|
||||||
if true_controller_paths
|
|
||||||
ActionController::Routing.controller_paths = true_controller_paths
|
|
||||||
end
|
|
||||||
ActionController::Routing.use_controllers! nil
|
|
||||||
Object.send(:remove_const, :RAILS_ROOT) rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_possible_controllers_are_reset_on_each_load
|
|
||||||
true_possible_controllers = ActionController::Routing.possible_controllers
|
|
||||||
true_controller_paths = ActionController::Routing.controller_paths
|
|
||||||
|
|
||||||
ActionController::Routing.use_controllers! nil
|
|
||||||
root = File.dirname(__FILE__) + '/controller_fixtures'
|
|
||||||
|
|
||||||
ActionController::Routing.controller_paths = []
|
|
||||||
assert_equal [], ActionController::Routing.possible_controllers
|
|
||||||
|
|
||||||
ActionController::Routing.controller_paths = [
|
|
||||||
root, root + '/app/controllers', root + '/vendor/plugins/bad_plugin/lib'
|
|
||||||
]
|
|
||||||
ActionController::Routing::Routes.load!
|
|
||||||
|
|
||||||
assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort
|
|
||||||
ensure
|
|
||||||
ActionController::Routing.controller_paths = true_controller_paths
|
|
||||||
ActionController::Routing.use_controllers! true_possible_controllers
|
|
||||||
Object.send(:remove_const, :RAILS_ROOT) rescue nil
|
|
||||||
|
|
||||||
ActionController::Routing::Routes.reload!
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_with_controllers
|
|
||||||
c = %w(admin/accounts admin/users account pages)
|
|
||||||
ActionController::Routing.with_controllers c do
|
|
||||||
assert_equal c, ActionController::Routing.possible_controllers
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_normalize_unix_paths
|
def test_normalize_unix_paths
|
||||||
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config)
|
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config)
|
||||||
paths = ActionController::Routing.normalize_paths(load_paths)
|
paths = ActionController::Routing.normalize_paths(load_paths)
|
||||||
|
@ -1815,22 +1763,20 @@ class RouteSetTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_slashes_are_implied
|
def test_slashes_are_implied
|
||||||
ActionController::Routing.with_controllers(['foo']) do
|
|
||||||
['/:controller/:action/:id/', '/:controller/:action/:id',
|
['/:controller/:action/:id/', '/:controller/:action/:id',
|
||||||
':controller/:action/:id', '/:controller/:action/:id/'
|
':controller/:action/:id', '/:controller/:action/:id/'
|
||||||
].each do |path|
|
].each do |path|
|
||||||
@set = nil
|
@set = nil
|
||||||
set.draw { |map| map.connect(path) }
|
set.draw { |map| map.connect(path) }
|
||||||
|
|
||||||
assert_equal '/foo', set.generate(:controller => 'foo', :action => 'index')
|
assert_equal '/content', set.generate(:controller => 'content', :action => 'index')
|
||||||
assert_equal '/foo/list', set.generate(:controller => 'foo', :action => 'list')
|
assert_equal '/content/list', set.generate(:controller => 'content', :action => 'list')
|
||||||
assert_equal '/foo/show/1', set.generate(:controller => 'foo', :action => 'show', :id => '1')
|
assert_equal '/content/show/1', set.generate(:controller => 'content', :action => 'show', :id => '1')
|
||||||
|
|
||||||
assert_equal({:controller => "foo", :action => "index"}, set.recognize_path('/foo'))
|
assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content'))
|
||||||
assert_equal({:controller => "foo", :action => "index"}, set.recognize_path('/foo/index'))
|
assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content/index'))
|
||||||
assert_equal({:controller => "foo", :action => "list"}, set.recognize_path('/foo/list'))
|
assert_equal({:controller => "content", :action => "list"}, set.recognize_path('/content/list'))
|
||||||
assert_equal({:controller => "foo", :action => "show", :id => "1"}, set.recognize_path('/foo/show/1'))
|
assert_equal({:controller => "content", :action => "show", :id => "1"}, set.recognize_path('/content/show/1'))
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -123,9 +123,6 @@ XML
|
||||||
@controller = TestController.new
|
@controller = TestController.new
|
||||||
@request = ActionController::TestRequest.new
|
@request = ActionController::TestRequest.new
|
||||||
@response = ActionController::TestResponse.new
|
@response = ActionController::TestResponse.new
|
||||||
|
|
||||||
ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
|
|
||||||
ActionController::Routing::Routes.load_routes!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_raw_post_handling
|
def test_raw_post_handling
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
class << Object; alias_method :const_available?, :const_defined?; end
|
class << Object; alias_method :const_available?, :const_defined?; end
|
||||||
|
|
||||||
class ContentController < Class.new(ActionController::Base)
|
class ContentController < ActionController::Base
|
||||||
end
|
end
|
||||||
class NotAController
|
class NotAController
|
||||||
end
|
end
|
||||||
module Admin
|
module Admin
|
||||||
class << self; alias_method :const_available?, :const_defined?; end
|
class << self; alias_method :const_available?, :const_defined?; end
|
||||||
class UserController < Class.new(ActionController::Base); end
|
class UserController < ActionController::Base; end
|
||||||
class NewsFeedController < Class.new(ActionController::Base); end
|
class NewsFeedController < ActionController::Base; end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# For speed test
|
# For speed test
|
||||||
class SpeedController < ActionController::Base; end
|
class SpeedController < ActionController::Base; end
|
||||||
class SearchController < SpeedController; end
|
class SearchController < SpeedController; end
|
||||||
|
|
|
@ -35,12 +35,6 @@ class Rack::TestCase < ActionController::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
ActionController::Base.session_options[:key] = "abc"
|
ActionController::Base.session_options[:key] = "abc"
|
||||||
ActionController::Base.session_options[:secret] = ("*" * 30)
|
ActionController::Base.session_options[:secret] = ("*" * 30)
|
||||||
|
|
||||||
controllers = ActionController::Base.subclasses.map do |k|
|
|
||||||
k.underscore.sub(/_controller$/, '')
|
|
||||||
end
|
|
||||||
|
|
||||||
ActionController::Routing.use_controllers!(controllers)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def app
|
def app
|
||||||
|
@ -91,6 +85,22 @@ end
|
||||||
class ::ApplicationController < ActionController::Base
|
class ::ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ActionController
|
||||||
|
class << Routing
|
||||||
|
def possible_controllers
|
||||||
|
@@possible_controllers ||= []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Base
|
||||||
|
def self.inherited(klass)
|
||||||
|
name = klass.name.underscore.sub(/_controller$/, '')
|
||||||
|
ActionController::Routing.possible_controllers << name unless name.blank?
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class SimpleRouteCase < Rack::TestCase
|
class SimpleRouteCase < Rack::TestCase
|
||||||
setup do
|
setup do
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
|
|
Loading…
Reference in a new issue