1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #41598 from rails/remove-proc-special-case

Remove special case filtering for Procs.
This commit is contained in:
Aaron Patterson 2021-03-02 17:46:37 -08:00 committed by GitHub
commit 41970d254a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 28 deletions

View file

@ -12,7 +12,7 @@ class ActionController::Base
def before_actions
filters = _process_action_callbacks.select { |c| c.kind == :before }
filters.map!(&:raw_filter)
filters.map!(&:filter)
end
end
end

View file

@ -289,21 +289,17 @@ module ActiveSupport
end
attr_accessor :kind, :name
attr_reader :chain_config
attr_reader :chain_config, :filter
def initialize(name, filter, kind, options, chain_config)
@chain_config = chain_config
@name = name
@kind = kind
@filter = filter
@key = compute_identifier filter
@if = check_conditionals(options[:if])
@unless = check_conditionals(options[:unless])
end
def filter; @key; end
def raw_filter; @filter; end
def merge_conditional_options(chain, if_option:, unless_option:)
options = {
if: @if.dup,
@ -367,15 +363,6 @@ module ActiveSupport
conditionals.freeze
end
def compute_identifier(filter)
case filter
when ::Proc
filter.object_id
else
filter
end
end
def conditions_lambdas
@if.map { |c| CallTemplate.build(c, self).make_lambda } +
@unless.map { |c| CallTemplate.build(c, self).inverted_lambda }

View file

@ -1129,15 +1129,6 @@ module CallbacksTest
}
end
def test_skip_lambda # raises error
calls = []
callback = ->(o) { calls << o }
klass = build_class(callback)
assert_raises(ArgumentError) { klass.skip callback }
klass.new.run
assert_equal 10, calls.length
end
def test_skip_symbol # removes all
calls = []
klass = build_class(:bar)

View file

@ -325,9 +325,9 @@ class SetupAndTeardownTest < ActiveSupport::TestCase
teardown :foo, :sentinel
def test_inherited_setup_callbacks
assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter)
assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:filter)
assert_equal [:foo], @called_back
assert_equal [:foo, :sentinel], self.class._teardown_callbacks.map(&:raw_filter)
assert_equal [:foo, :sentinel], self.class._teardown_callbacks.map(&:filter)
end
def setup
@ -355,9 +355,9 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest
teardown :bar
def test_inherited_setup_callbacks
assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter)
assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:filter)
assert_equal [:foo, :bar], @called_back
assert_equal [:foo, :sentinel, :bar], self.class._teardown_callbacks.map(&:raw_filter)
assert_equal [:foo, :sentinel, :bar], self.class._teardown_callbacks.map(&:filter)
end
private