diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/caching/sweeping.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 24 | ||||
-rw-r--r-- | actionpack/test/controller/filters_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 25 |
4 files changed, 57 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/caching/sweeping.rb b/actionpack/lib/action_controller/caching/sweeping.rb index 39da15e26a..73291ce083 100644 --- a/actionpack/lib/action_controller/caching/sweeping.rb +++ b/actionpack/lib/action_controller/caching/sweeping.rb @@ -68,14 +68,14 @@ module ActionController #:nodoc: def after(controller) self.controller = controller callback(:after) if controller.perform_caching - # Clean up, so that the controller can be collected after this request - self.controller = nil end def around(controller) before(controller) yield after(controller) + ensure + clean_up end protected @@ -90,6 +90,11 @@ module ActionController #:nodoc: end private + def clean_up + # Clean up, so that the controller can be collected after this request + self.controller = nil + end + def callback(timing) controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}" action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}" diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index ee90bfe63f..0a65b4dbcc 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -917,7 +917,7 @@ module ActionDispatch @path = (options[:path] || @name).to_s @controller = (options[:controller] || @name).to_s @as = options[:as] - @param = options[:param] || :id + @param = (options[:param] || :id).to_sym @options = options end @@ -965,12 +965,18 @@ module ActionDispatch "#{path}/:#{param}" end + alias :shallow_scope :member_scope + def new_scope(new_path) "#{path}/#{new_path}" end + def nested_param + :"#{singular}_#{param}" + end + def nested_scope - "#{path}/:#{singular}_#{param}" + "#{path}/:#{nested_param}" end end @@ -1481,18 +1487,18 @@ module ActionDispatch def nested_options #:nodoc: options = { :as => parent_resource.member_name } options[:constraints] = { - :"#{parent_resource.singular}_id" => id_constraint - } if id_constraint? + parent_resource.nested_param => param_constraint + } if param_constraint? options end - def id_constraint? #:nodoc: - @scope[:constraints] && @scope[:constraints][:id].is_a?(Regexp) + def param_constraint? #:nodoc: + @scope[:constraints] && @scope[:constraints][parent_resource.param].is_a?(Regexp) end - def id_constraint #:nodoc: - @scope[:constraints][:id] + def param_constraint #:nodoc: + @scope[:constraints][parent_resource.param] end def canonical_action?(action, flag) #:nodoc: @@ -1505,7 +1511,7 @@ module ActionDispatch def path_for_action(action, path) #:nodoc: prefix = shallow_scoping? ? - "#{@scope[:shallow_path]}/#{parent_resource.path}/:id" : @scope[:path] + "#{@scope[:shallow_path]}/#{parent_resource.shallow_scope}" : @scope[:path] if canonical_action?(action, path.blank?) prefix.to_s diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index b9cb93f0f4..afc00a3c9d 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -505,6 +505,10 @@ class FilterTest < ActionController::TestCase def show render :text => 'hello world' end + + def error + raise StandardError.new + end end class ImplicitActionsController < ActionController::Base @@ -534,6 +538,13 @@ class FilterTest < ActionController::TestCase assert_equal 'hello world', response.body end + def test_sweeper_should_clean_up_if_exception_is_raised + assert_raise StandardError do + test_process(SweeperTestController, 'error') + end + assert_nil AppSweeper.instance.controller + end + def test_before_method_of_sweeper_should_always_return_true sweeper = ActionController::Caching::Sweeper.send(:new) assert sweeper.before(TestController.new) diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index a42ac60917..205238990e 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -482,11 +482,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest get :preview, :on => :member end - resources :profiles, :param => :username do + resources :profiles, :param => :username, :username => /[a-z]+/ do get :details, :on => :member resources :messages end + resources :orders do + constraints :download => /[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}/ do + resources :downloads, :param => :download, :shallow => true + end + end + scope :as => "routes" do get "/c/:id", :as => :collision, :to => "collision#show" get "/collision", :to => "collision#show" @@ -2243,6 +2249,23 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal '34', @request.params[:id] end + def test_custom_param_constraint + get '/profiles/bob1' + assert_equal 404, @response.status + + get '/profiles/bob1/details' + assert_equal 404, @response.status + + get '/profiles/bob1/messages/34' + assert_equal 404, @response.status + end + + def test_shallow_custom_param + get '/downloads/0c0c0b68-d24b-11e1-a861-001ff3fffe6f.zip' + assert_equal 'downloads#show', @response.body + assert_equal '0c0c0b68-d24b-11e1-a861-001ff3fffe6f', @request.params[:download] + end + private def with_https old_https = https? |