Permalink
Browse files

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

Execute conditional procs on controller filters only for current action
Conflicts:
	actionpack/CHANGELOG.md
  • Loading branch information...
1 parent a6b7818 commit ab8a833e0ba0aa5198fbe3472791e7b58ccbd199 @rafaelfranca rafaelfranca committed Aug 10, 2013
View
@@ -1,5 +1,12 @@
## unreleased ##
+* 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.
@@ -36,7 +36,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
@@ -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 }
@@ -636,6 +640,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"]

0 comments on commit ab8a833

Please sign in to comment.