Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11799 from njakobsen/fix-controller-filter-callbacks

Execute conditional procs on controller filters only for current action
  • Loading branch information...
commit 4f940820f29f8fc9c9113baca709aae11683b596 2 parents a3f390b + 55cbb85
@rafaelfranca rafaelfranca authored
View
7 actionpack/CHANGELOG.md
@@ -1,3 +1,10 @@
+* Fix an issue where :if and :unless controller action procs were being run
+ before checking for the correct action in the :only and :unless options.
+
+ Fixes #11799
+
+ *Nicholas Jakobsen*
+
* Fix an issue where `assert_dom_equal` and `assert_dom_not_equal` were
ignoring the passed failure message argument.
View
2  actionpack/lib/abstract_controller/callbacks.rb
@@ -38,7 +38,7 @@ def _normalize_callback_options(options)
def _normalize_callback_option(options, from, to) # :nodoc:
if from = options[from]
from = Array(from).map {|o| "action_name == '#{o}'"}.join(" || ")
- options[to] = Array(options[to]) << from
+ options[to] = Array(options[to]).unshift(from)
end
end
View
9 actionpack/test/controller/filters_test.rb
@@ -208,6 +208,10 @@ class AnomolousYetValidConditionController < ConditionalFilterController
before_filter(ConditionalClassFilter, :ensure_login, Proc.new {|c| c.instance_variable_set(:"@ran_proc_filter1", true)}, :except => :show_without_filter) { |c| c.instance_variable_set(:"@ran_proc_filter2", true)}
end
+ class OnlyConditionalOptionsFilter < ConditionalFilterController
+ before_filter :ensure_login, :only => :index, :if => Proc.new {|c| c.instance_variable_set(:"@ran_conditional_index_proc", true) }
+ end
+
class ConditionalOptionsFilter < ConditionalFilterController
before_filter :ensure_login, :if => Proc.new { |c| true }
before_filter :clean_up_tmp, :if => Proc.new { |c| false }
@@ -649,6 +653,11 @@ def test_running_except_condition_filters
assert !assigns["ran_class_filter"]
end
+ def test_running_only_condition_and_conditional_options
+ test_process(OnlyConditionalOptionsFilter, "show")
+ assert_not assigns["ran_conditional_index_proc"]
+ end
+
def test_running_before_and_after_condition_filters
test_process(BeforeAndAfterConditionController)
assert_equal %w( ensure_login clean_up_tmp), assigns["ran_filter"]
Please sign in to comment.
Something went wrong with that request. Please try again.