提交 b8e83ce1 编写于 作者: R Rafael Mendonça França

Merge pull request #18404 from claudiob/rebase-14549

Add test case and documentation for skip_before_filter.
......@@ -28,6 +28,16 @@ module ClassMethods
# The basic idea is that <tt>:only => :index</tt> gets converted to
# <tt>:if => proc {|c| c.action_name == "index" }</tt>.
#
# Note that <tt>:only</tt> has priority over <tt>:if</tt> in case they
# are used together.
#
# only: :index, if: -> { true } # the :if option will be ignored.
#
# Note that <tt>:if</tt> has priority over <tt>:except</tt> in case they
# are used together.
#
# except: :index, if: -> { true } # the :except option will be ignored.
#
# ==== Options
# * <tt>only</tt> - The callback should be run only for this action
# * <tt>except</tt> - The callback should be run for all actions except this action
......
......@@ -225,6 +225,30 @@ class ConditionalOptionsSkipFilter < ConditionalFilterController
skip_before_action :clean_up_tmp, if: -> { true }
end
class SkipFilterUsingOnlyAndIf < ConditionalFilterController
before_action :clean_up_tmp
before_action :ensure_login
skip_before_action :ensure_login, only: :login, if: -> { false }
skip_before_action :clean_up_tmp, only: :login, if: -> { true }
def login
render text: 'ok'
end
end
class SkipFilterUsingIfAndExcept < ConditionalFilterController
before_action :clean_up_tmp
before_action :ensure_login
skip_before_action :ensure_login, if: -> { false }, except: :login
skip_before_action :clean_up_tmp, if: -> { true }, except: :login
def login
render text: 'ok'
end
end
class ClassController < ConditionalFilterController
before_action ConditionalClassFilter
end
......@@ -596,6 +620,16 @@ def test_running_conditional_skip_options
assert_equal %w( ensure_login ), assigns["ran_filter"]
end
def test_if_is_ignored_when_used_with_only
test_process(SkipFilterUsingOnlyAndIf, 'login')
assert_nil assigns['ran_filter']
end
def test_except_is_ignored_when_used_with_if
test_process(SkipFilterUsingIfAndExcept, 'login')
assert_equal %w(ensure_login), assigns["ran_filter"]
end
def test_skipping_class_actions
test_process(ClassController)
assert_equal true, assigns["ran_class_action"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册