Changeset 3668
- Timestamp:
- 02/26/06 17:49:09 (3 years ago)
- Files:
-
- trunk/actionpack/lib/action_controller/base.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/helpers.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/base_test.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/benchmark_test.rb (modified) (2 diffs)
- trunk/activesupport/lib/active_support/core_ext/class/removal.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/dependencies.rb (modified) (1 diff)
- trunk/railties/builtin/controllers/rails_info_controller.rb (modified) (1 diff)
- trunk/railties/lib/commands/servers/lighttpd.rb (modified) (1 diff)
- trunk/railties/test/dispatcher_test.rb (modified) (2 diffs)
- trunk/railties/test/rails_info_controller_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/base.rb
r3606 r3668 325 325 components = self.name.to_s.split('::') 326 326 components[-1] = $1 if /^(.*)Controller$/ =~ components.last 327 # Accomodate the root Controllers module.328 components.shift if components.first == 'Controllers'329 327 @controller_path = components.map { |name| name.underscore }.join('/') 330 328 end trunk/actionpack/lib/action_controller/helpers.rb
r2938 r3668 110 110 private 111 111 def default_helper_module! 112 module_name = name.sub(/ ^Controllers::/, '').sub(/Controller$|$/, 'Helper')112 module_name = name.sub(/Controller$|$/, 'Helper') 113 113 module_path = module_name.split('::').map { |m| m.underscore }.join('/') 114 114 require_dependency module_path … … 129 129 raise unless e.is_missing?("helpers/#{child.controller_path}_helper") 130 130 end 131 end 131 end 132 132 end 133 133 end trunk/actionpack/test/controller/base_test.rb
r2696 r3668 3 3 require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late 4 4 5 # This file currently contains a few controller UTs 6 # I couldn't find where the current base tests are, so I created this file. 7 # If there aren't any base-specific UTs, then this file should grow as they 8 # are written. If there are, or there is a better place for these, then I will 9 # move them to the correct location. 10 # 11 # Nicholas Seckar aka. Ulysses 12 13 # Provide a static version of the Controllers module instead of the auto-loading version. 14 # We don't want these tests to fail when dependencies are to blame. 15 module Controllers 16 module Submodule 17 class ContainedEmptyController < ActionController::Base 18 end 19 class ContainedNonEmptyController < ActionController::Base 20 def public_action 21 end 22 23 hide_action :hidden_action 24 def hidden_action 25 end 26 27 def another_hidden_action 28 end 29 hide_action :another_hidden_action 30 end 31 class SubclassedController < ContainedNonEmptyController 32 hide_action :public_action # Hiding it here should not affect the superclass. 33 end 5 # Provide some controller to run the tests on. 6 module Submodule 7 class ContainedEmptyController < ActionController::Base 34 8 end 35 class EmptyController < ActionController::Base 36 include ActionController::Caching 37 end 38 class NonEmptyController < ActionController::Base 9 class ContainedNonEmptyController < ActionController::Base 39 10 def public_action 40 11 end … … 43 14 def hidden_action 44 15 end 16 17 def another_hidden_action 18 end 19 hide_action :another_hidden_action 20 end 21 class SubclassedController < ContainedNonEmptyController 22 hide_action :public_action # Hiding it here should not affect the superclass. 23 end 24 end 25 class EmptyController < ActionController::Base 26 include ActionController::Caching 27 end 28 class NonEmptyController < ActionController::Base 29 def public_action 30 end 31 32 hide_action :hidden_action 33 def hidden_action 45 34 end 46 35 end … … 48 37 class ControllerClassTests < Test::Unit::TestCase 49 38 def test_controller_path 50 assert_equal 'empty', Controllers::EmptyController.controller_path51 assert_equal 'submodule/contained_empty', Controllers::Submodule::ContainedEmptyController.controller_path39 assert_equal 'empty', EmptyController.controller_path 40 assert_equal 'submodule/contained_empty', Submodule::ContainedEmptyController.controller_path 52 41 end 53 42 def test_controller_name 54 assert_equal 'empty', Controllers::EmptyController.controller_name55 assert_equal 'contained_empty', Controllers::Submodule::ContainedEmptyController.controller_name43 assert_equal 'empty', EmptyController.controller_name 44 assert_equal 'contained_empty', Submodule::ContainedEmptyController.controller_name 56 45 end 57 46 end … … 59 48 class ControllerInstanceTests < Test::Unit::TestCase 60 49 def setup 61 @empty = Controllers::EmptyController.new62 @contained = Controllers::Submodule::ContainedEmptyController.new63 @empty_controllers = [@empty, @contained, Controllers::Submodule::SubclassedController.new]50 @empty = EmptyController.new 51 @contained = Submodule::ContainedEmptyController.new 52 @empty_controllers = [@empty, @contained, Submodule::SubclassedController.new] 64 53 65 @non_empty_controllers = [ Controllers::NonEmptyController.new,66 Controllers::Submodule::ContainedNonEmptyController.new]54 @non_empty_controllers = [NonEmptyController.new, 55 Submodule::ContainedNonEmptyController.new] 67 56 end 68 57 trunk/actionpack/test/controller/benchmark_test.rb
r2039 r3668 2 2 require 'test/unit' 3 3 4 # Provide a static version of the Controllers module instead of the auto-loading version. 5 # We don't want these tests to fail when dependencies are to blame. 6 module Controllers 7 class BenchmarkedController < ActionController::Base 8 def public_action 9 render :nothing => true 10 end 4 # Provide some static controllers. 5 class BenchmarkedController < ActionController::Base 6 def public_action 7 render :nothing => true 8 end 11 9 12 def rescue_action(e) 13 raise e 14 end 10 def rescue_action(e) 11 raise e 15 12 end 16 13 end … … 23 20 24 21 def setup 25 @controller = Controllers::BenchmarkedController.new22 @controller = BenchmarkedController.new 26 23 # benchmark doesn't do anything unless a logger is set 27 24 @controller.logger = MockLogger.new trunk/activesupport/lib/active_support/core_ext/class/removal.rb
r3532 r3668 9 9 10 10 def remove_class(*klasses) 11 klasses. each do |klass|11 klasses.flatten.each do |klass| 12 12 # Skip this class if there is nothing bound to this name 13 13 next unless defined?(klass.name) 14 14 15 15 basename = klass.to_s.split("::").last 16 16 parent = klass.parent 17 17 18 18 # Skip this class if it does not match the current one bound to this name 19 19 next unless parent.const_defined?(basename) && klass = parent.const_get(basename) 20 20 21 21 parent.send :remove_const, basename unless parent == klass 22 22 end trunk/activesupport/lib/active_support/dependencies.rb
r3526 r3668 99 99 # require_association when using single-table inheritance. 100 100 def const_missing(class_id) 101 if Object.const_defined?(:Controllers) && Object::Controllers.const_available?(class_id)102 return Object::Controllers.const_get(class_id)103 end104 105 101 file_name = class_id.to_s.demodulize.underscore 106 102 file_path = as_load_path.empty? ? file_name : "#{as_load_path}/#{file_name}" trunk/railties/builtin/controllers/rails_info_controller.rb
r2933 r3668 1 module Controllers #:nodoc: 2 class RailsInfoController < ApplicationController 3 def properties 4 if local_request? 5 render :inline => Rails::Info.to_html 6 else 7 render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => 500 8 end 1 class RailsInfoController < ApplicationController 2 def properties 3 if local_request? 4 render :inline => Rails::Info.to_html 5 else 6 render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => 500 9 7 end 10 8 end trunk/railties/lib/commands/servers/lighttpd.rb
r3641 r3668 31 31 "..", "..", "..", "configs", "lighttpd.conf")) 32 32 puts "=> #{config_file} not found, copying from #{source}" 33 FileUtils.cp source, config_file 33 config = File.read source 34 config = config.gsub "CWD", File.expand_path(RAILS_ROOT).inspect 35 File.open(config_file, 'w') { |f| f.write config } 34 36 end 35 37 trunk/railties/test/dispatcher_test.rb
r2841 r3668 25 25 @output = StringIO.new 26 26 ENV['REQUEST_METHOD'] = "GET" 27 setup_minimal_environment28 27 end 29 28 30 29 def teardown 31 30 ENV['REQUEST_METHOD'] = nil 32 teardown_minimal_environment33 31 end 34 32 … … 92 90 Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, @output) 93 91 end 94 95 def setup_minimal_environment96 value = Dependencies::LoadingModule.root97 Object.const_set("Controllers", value)98 end99 100 def teardown_minimal_environment101 Object.send(:remove_const, "Controllers")102 end103 92 end trunk/railties/test/rails_info_controller_test.rb
r2933 r3668 8 8 require 'action_controller/test_process' 9 9 require 'rails_info' 10 11 module Controllers; def self.const_available?(constant); false end end12 10 13 11 class ApplicationController < ActionController::Base … … 30 28 31 29 # Re-raise errors caught by the controller. 32 class Controllers::RailsInfoController; def rescue_action(e) raise e end; end30 class RailsInfoController; def rescue_action(e) raise e end; end 33 31 34 32 class RailsInfoControllerTest < Test::Unit::TestCase 35 33 def setup 36 @controller = Controllers::RailsInfoController.new34 @controller = RailsInfoController.new 37 35 @request = ActionController::TestRequest.new 38 36 @response = ActionController::TestResponse.new … … 40 38 41 39 def test_rails_info_properties_table_rendered_for_local_request 42 Controllers::RailsInfoController.local_request = true40 RailsInfoController.local_request = true 43 41 get :properties 44 42 assert_tag :tag => 'table' … … 47 45 48 46 def test_rails_info_properties_error_rendered_for_non_local_request 49 Controllers::RailsInfoController.local_request = false47 RailsInfoController.local_request = false 50 48 get :properties 51 49 assert_tag :tag => 'p'