1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove ::Controllers related cruft; fix AP tests

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3668 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Nicholas Seckar 2006-02-26 17:49:09 +00:00
parent d11f8d5516
commit 26eaf073c4
10 changed files with 60 additions and 93 deletions

View file

@ -324,8 +324,6 @@ module ActionController #:nodoc:
unless @controller_path
components = self.name.to_s.split('::')
components[-1] = $1 if /^(.*)Controller$/ =~ components.last
# Accomodate the root Controllers module.
components.shift if components.first == 'Controllers'
@controller_path = components.map { |name| name.underscore }.join('/')
end

View file

@ -109,7 +109,7 @@ module ActionController #:nodoc:
private
def default_helper_module!
module_name = name.sub(/^Controllers::/, '').sub(/Controller$|$/, 'Helper')
module_name = name.sub(/Controller$|$/, 'Helper')
module_path = module_name.split('::').map { |m| m.underscore }.join('/')
require_dependency module_path
helper module_name.constantize
@ -128,7 +128,7 @@ module ActionController #:nodoc:
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.controller_path}_helper")
end
end
end
end
end
end

View file

@ -2,68 +2,57 @@ require File.dirname(__FILE__) + '/../abstract_unit'
require 'test/unit'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
# This file currently contains a few controller UTs
# I couldn't find where the current base tests are, so I created this file.
# If there aren't any base-specific UTs, then this file should grow as they
# are written. If there are, or there is a better place for these, then I will
# move them to the correct location.
#
# Nicholas Seckar aka. Ulysses
# Provide a static version of the Controllers module instead of the auto-loading version.
# We don't want these tests to fail when dependencies are to blame.
module Controllers
module Submodule
class ContainedEmptyController < ActionController::Base
end
class ContainedNonEmptyController < ActionController::Base
def public_action
end
hide_action :hidden_action
def hidden_action
end
def another_hidden_action
end
hide_action :another_hidden_action
end
class SubclassedController < ContainedNonEmptyController
hide_action :public_action # Hiding it here should not affect the superclass.
end
# Provide some controller to run the tests on.
module Submodule
class ContainedEmptyController < ActionController::Base
end
class EmptyController < ActionController::Base
include ActionController::Caching
end
class NonEmptyController < ActionController::Base
class ContainedNonEmptyController < ActionController::Base
def public_action
end
hide_action :hidden_action
def hidden_action
end
def another_hidden_action
end
hide_action :another_hidden_action
end
class SubclassedController < ContainedNonEmptyController
hide_action :public_action # Hiding it here should not affect the superclass.
end
end
class EmptyController < ActionController::Base
include ActionController::Caching
end
class NonEmptyController < ActionController::Base
def public_action
end
hide_action :hidden_action
def hidden_action
end
end
class ControllerClassTests < Test::Unit::TestCase
def test_controller_path
assert_equal 'empty', Controllers::EmptyController.controller_path
assert_equal 'submodule/contained_empty', Controllers::Submodule::ContainedEmptyController.controller_path
assert_equal 'empty', EmptyController.controller_path
assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path
end
def test_controller_name
assert_equal 'empty', Controllers::EmptyController.controller_name
assert_equal 'contained_empty', Controllers::Submodule::ContainedEmptyController.controller_name
assert_equal 'empty', EmptyController.controller_name
assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name
end
end
class ControllerInstanceTests < Test::Unit::TestCase
def setup
@empty = Controllers::EmptyController.new
@contained = Controllers::Submodule::ContainedEmptyController.new
@empty_controllers = [@empty, @contained, Controllers::Submodule::SubclassedController.new]
@empty = EmptyController.new
@contained = Submodule::ContainedEmptyController.new
@empty_controllers = [@empty, @contained, Submodule::SubclassedController.new]
@non_empty_controllers = [Controllers::NonEmptyController.new,
Controllers::Submodule::ContainedNonEmptyController.new]
@non_empty_controllers = [NonEmptyController.new,
Submodule::ContainedNonEmptyController.new]
end
def test_action_methods

View file

@ -1,17 +1,14 @@
require File.dirname(__FILE__) + '/../abstract_unit'
require 'test/unit'
# Provide a static version of the Controllers module instead of the auto-loading version.
# We don't want these tests to fail when dependencies are to blame.
module Controllers
class BenchmarkedController < ActionController::Base
def public_action
render :nothing => true
end
# Provide some static controllers.
class BenchmarkedController < ActionController::Base
def public_action
render :nothing => true
end
def rescue_action(e)
raise e
end
def rescue_action(e)
raise e
end
end
@ -22,7 +19,7 @@ class BenchmarkTest < Test::Unit::TestCase
end
def setup
@controller = Controllers::BenchmarkedController.new
@controller = BenchmarkedController.new
# benchmark doesn't do anything unless a logger is set
@controller.logger = MockLogger.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new

View file

@ -8,17 +8,17 @@ class Class #:nodoc:
end
def remove_class(*klasses)
klasses.each do |klass|
klasses.flatten.each do |klass|
# Skip this class if there is nothing bound to this name
next unless defined?(klass.name)
basename = klass.to_s.split("::").last
parent = klass.parent
# Skip this class if it does not match the current one bound to this name
next unless parent.const_defined?(basename) && klass = parent.const_get(basename)
parent.send :remove_const, basename unless parent == klass
end
end
end
end

View file

@ -98,10 +98,6 @@ class Module #:nodoc:
# Use const_missing to autoload associations so we don't have to
# require_association when using single-table inheritance.
def const_missing(class_id)
if Object.const_defined?(:Controllers) && Object::Controllers.const_available?(class_id)
return Object::Controllers.const_get(class_id)
end
file_name = class_id.to_s.demodulize.underscore
file_path = as_load_path.empty? ? file_name : "#{as_load_path}/#{file_name}"
begin

View file

@ -1,11 +1,9 @@
module Controllers #:nodoc:
class RailsInfoController < ApplicationController
def properties
if local_request?
render :inline => Rails::Info.to_html
else
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => 500
end
class RailsInfoController < ApplicationController
def properties
if local_request?
render :inline => Rails::Info.to_html
else
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => 500
end
end
end
end

View file

@ -30,7 +30,9 @@ unless File.exist?(config_file)
source = File.expand_path(File.join(File.dirname(__FILE__),
"..", "..", "..", "configs", "lighttpd.conf"))
puts "=> #{config_file} not found, copying from #{source}"
FileUtils.cp source, config_file
config = File.read source
config = config.gsub "CWD", File.expand_path(RAILS_ROOT).inspect
File.open(config_file, 'w') { |f| f.write config }
end
config = IO.read(config_file)

View file

@ -24,12 +24,10 @@ class DispatcherTest < Test::Unit::TestCase
def setup
@output = StringIO.new
ENV['REQUEST_METHOD'] = "GET"
setup_minimal_environment
end
def teardown
ENV['REQUEST_METHOD'] = nil
teardown_minimal_environment
end
def test_ac_subclasses_cleared_on_reset
@ -91,13 +89,4 @@ class DispatcherTest < Test::Unit::TestCase
def dispatch
Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, @output)
end
def setup_minimal_environment
value = Dependencies::LoadingModule.root
Object.const_set("Controllers", value)
end
def teardown_minimal_environment
Object.send(:remove_const, "Controllers")
end
end

View file

@ -8,8 +8,6 @@ require 'action_controller'
require 'action_controller/test_process'
require 'rails_info'
module Controllers; def self.const_available?(constant); false end end
class ApplicationController < ActionController::Base
@local_request = false
class << self
@ -29,24 +27,24 @@ end
require 'rails_info_controller'
# Re-raise errors caught by the controller.
class Controllers::RailsInfoController; def rescue_action(e) raise e end; end
class RailsInfoController; def rescue_action(e) raise e end; end
class RailsInfoControllerTest < Test::Unit::TestCase
def setup
@controller = Controllers::RailsInfoController.new
@controller = RailsInfoController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_rails_info_properties_table_rendered_for_local_request
Controllers::RailsInfoController.local_request = true
RailsInfoController.local_request = true
get :properties
assert_tag :tag => 'table'
assert_response :success
end
def test_rails_info_properties_error_rendered_for_non_local_request
Controllers::RailsInfoController.local_request = false
RailsInfoController.local_request = false
get :properties
assert_tag :tag => 'p'
assert_response 500