Skip to content

Commit

Permalink
Fix filter :only and :except with implicit actions
Browse files Browse the repository at this point in the history
The method_name argument is "default_render" for implicit actions
so use the action_name attribute to determine which callbacks to run.

[#5673 state:resolved]
  • Loading branch information
pixeltrix committed Mar 23, 2011
1 parent 0823bbd commit 35de70f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller/callbacks.rb
Expand Up @@ -14,7 +14,7 @@ module Callbacks
# Override AbstractController::Base's process_action to run the # Override AbstractController::Base's process_action to run the
# process_action callbacks around the normal behavior. # process_action callbacks around the normal behavior.
def process_action(method_name, *args) def process_action(method_name, *args)
run_callbacks(:process_action, method_name) do run_callbacks(:process_action, action_name) do

This comment has been minimized.

Copy link
@josevalim

josevalim Mar 29, 2011

Contributor

This change is not good. If there is an error here, is that the method_name is the wrong value. It should be equal to the action_name here.

This comment has been minimized.

Copy link
@josevalim

josevalim Mar 29, 2011

Contributor

Fixed on: 4e2bacd

super super
end end
end end
Expand Down
29 changes: 29 additions & 0 deletions actionpack/test/controller/filters_test.rb
Expand Up @@ -503,6 +503,22 @@ def show
render :text => 'hello world' render :text => 'hello world'
end end
end end

class ImplicitActionsController < ActionController::Base
before_filter :find_only, :only => :edit
before_filter :find_except, :except => :edit

private

def find_only
@only = 'Only'
end

def find_except
@except = 'Except'
end
end

def test_sweeper_should_not_block_rendering def test_sweeper_should_not_block_rendering
response = test_process(SweeperTestController) response = test_process(SweeperTestController)
assert_equal 'hello world', response.body assert_equal 'hello world', response.body
Expand Down Expand Up @@ -781,6 +797,19 @@ def test_a_rescuing_around_filter
assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body) assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body)
end end


def test_filters_obey_only_and_except_for_implicit_actions
test_process(ImplicitActionsController, 'show')
assert_nil assigns(:user)
assert_equal 'Except', assigns(:except)
assert_nil assigns(:only)
assert_equal 'show', response.body

test_process(ImplicitActionsController, 'edit')
assert_equal 'Only', assigns(:only)
assert_nil assigns(:except)
assert_equal 'edit', response.body
end

private private
def test_process(controller, action = "show") def test_process(controller, action = "show")
@controller = controller.is_a?(Class) ? controller.new : controller @controller = controller.is_a?(Class) ? controller.new : controller
Expand Down
@@ -0,0 +1 @@
edit
@@ -0,0 +1 @@
show

0 comments on commit 35de70f

Please sign in to comment.