Merge pull request #11799 from njakobsen/fix-controller-filter-callbacks
Execute conditional procs on controller filters only for current action
This commit is contained in:
commit
4f940820f2
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user