diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/deprecated.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/helpers.rb | 12 | ||||
-rw-r--r-- | actionpack/lib/action_controller/railtie.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/stack.rb | 14 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/helper_test.rb | 15 | ||||
-rw-r--r-- | actionpack/test/dispatch/middleware_stack_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 21 |
8 files changed, 66 insertions, 17 deletions
diff --git a/actionpack/lib/action_controller/deprecated.rb b/actionpack/lib/action_controller/deprecated.rb index 589061e77c..edc0e5b3fe 100644 --- a/actionpack/lib/action_controller/deprecated.rb +++ b/actionpack/lib/action_controller/deprecated.rb @@ -2,3 +2,4 @@ ActionController::AbstractRequest = ActionController::Request = ActionDispatch:: ActionController::AbstractResponse = ActionController::Response = ActionDispatch::Response ActionController::Routing = ActionDispatch::Routing ActionController::Routing::Routes = ActionDispatch::Routing::RouteSet.new +ActionController::UrlWriter = AbstractController::UrlFor diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index 0e3db86861..ef3b89db14 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -56,6 +56,18 @@ module ActionController end module ClassMethods + def helpers_dir + ActiveSupport::Deprecation.warn "ActionController::Base.helpers_dir is deprecated. " << + "Please use ActionController::Base.helpers_path (which returns an array)" + self.helpers_path + end + + def helpers_dir=(value) + ActiveSupport::Deprecation.warn "ActionController::Base.helpers_dir= is deprecated. " << + "Please use ActionController::Base.helpers_path= (which is an array)" + self.helpers_path = Array(value) + end + def inherited(klass) klass.class_eval { default_helper_module! unless name.blank? } super diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb index f15c012471..29a0a346ec 100644 --- a/actionpack/lib/action_controller/railtie.rb +++ b/actionpack/lib/action_controller/railtie.rb @@ -8,17 +8,16 @@ module ActionController require "action_controller/railties/subscriber" subscriber ActionController::Railties::Subscriber.new + initializer "action_controller.logger" do + ActionController::Base.logger ||= Rails.logger + end + initializer "action_controller.set_configs" do |app| app.config.action_controller.each do |k,v| ActionController::Base.send "#{k}=", v end end - # TODO: ActionController::Base.logger should delegate to its own config.logger - initializer "action_controller.logger" do - ActionController::Base.logger ||= Rails.logger - end - initializer "action_controller.initialize_framework_caches" do ActionController::Base.cache_store ||= RAILS_CACHE end diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 0dc1d70e37..18a2922fa7 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -55,7 +55,11 @@ module ActionDispatch when Class klass == middleware else - klass == ActiveSupport::Inflector.constantize(middleware.to_s) + if lazy_compare?(@klass) && lazy_compare?(middleware) + normalize(@klass) == normalize(middleware) + else + klass == ActiveSupport::Inflector.constantize(middleware.to_s) + end end end @@ -72,6 +76,14 @@ module ActionDispatch end private + def lazy_compare?(object) + object.is_a?(String) || object.is_a?(Symbol) + end + + def normalize(object) + object.to_s.strip.sub(/^::/, '') + end + def build_args Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg } end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index fcbb70749f..5199984814 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -157,10 +157,11 @@ module ActionDispatch end # Invokes Rack::Mount::Utils.normalize path and ensure that - # (:locale) becomes (/:locale) instead of /(:locale). + # (:locale) becomes (/:locale) instead of /(:locale). Except + # for root cases, where the latter is the correct one. def self.normalize_path(path) path = Rack::Mount::Utils.normalize_path(path) - path.sub!(%r{/\(+/?:}, '(/:') + path.sub!(%r{/(\(+)/?:}, '\1/:') unless path =~ %r{^/\(+:.*\)$} path end diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index fe0961e575..75a96d6497 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -31,7 +31,7 @@ module LocalAbcHelper def c() end end -class HelperTest < Test::Unit::TestCase +class HelperTest < ActiveSupport::TestCase class TestController < ActionController::Base attr_accessor :delegate_attr def delegate_method() end @@ -135,6 +135,17 @@ class HelperTest < Test::Unit::TestCase assert methods.include?('foobar') end + def test_deprecation + assert_deprecated do + ActionController::Base.helpers_dir = "some/foo/bar" + end + assert_deprecated do + assert_equal ["some/foo/bar"], ActionController::Base.helpers_dir + end + ensure + ActionController::Base.helpers_path = [File.dirname(__FILE__) + '/../fixtures/helpers'] + end + private def expected_helper_methods TestHelper.instance_methods.map {|m| m.to_s } @@ -154,7 +165,7 @@ class HelperTest < Test::Unit::TestCase end -class IsolatedHelpersTest < Test::Unit::TestCase +class IsolatedHelpersTest < ActiveSupport::TestCase class A < ActionController::Base def index render :inline => '<%= shout %>' diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index f4e18308ae..7cf6365af3 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -87,4 +87,10 @@ class MiddlewareStackTest < ActiveSupport::TestCase end assert_equal [:foo], @stack.last.send(:build_args) end + + test "lazy compares so unloaded constants can be loaded" do + @stack.use "UnknownMiddleware" + @stack.use :"MiddlewareStackTest::BazMiddleware" + assert @stack.include?("::MiddlewareStackTest::BazMiddleware") + end end diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6dccabdb3f..dfe824fd70 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -141,19 +141,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :rooms end - scope '(:locale)', :locale => /en|pl/ do - resources :descriptions - end + match '/info' => 'projects#info', :as => 'info' namespace :admin do - scope '(/:locale)', :locale => /en|pl/ do + scope '(:locale)', :locale => /en|pl/ do resources :descriptions end end - match '/info' => 'projects#info', :as => 'info' - - root :to => 'projects#index' + scope '(:locale)', :locale => /en|pl/ do + resources :descriptions + root :to => 'projects#index' + end end end @@ -660,6 +659,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_optional_scoped_root + with_test_routes do + assert_equal '/en', root_path("en") + get '/en' + assert_equal 'projects#index', @response.body + end + end + def test_optional_scoped_path with_test_routes do assert_equal '/en/descriptions', descriptions_path("en") |