Skip to content

Commit

Permalink
fix: support proc symbol on callbacks conditionals, fixes: #54056 issue
Browse files Browse the repository at this point in the history
Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
  • Loading branch information
Roriz and byroot committed Dec 30, 2024
1 parent d8a3011 commit 2043d15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions activesupport/lib/active_support/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,10 @@ def self.build(filter, callback)
when Conditionals::Value
ProcCall.new(filter)
when ::Proc
if filter.arity > 1
case filter.arity
when 2
InstanceExec2.new(filter)
elsif filter.arity > 0
when 1, -2
InstanceExec1.new(filter)
else
InstanceExec0.new(filter)
Expand Down
2 changes: 2 additions & 0 deletions activesupport/test/callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ class ConditionalPerson < Record
before_save Proc.new { |r| r.history << "b00m" }, if: Proc.new { |r| false }
before_save Proc.new { |r| r.history << [:before_save, :proc] }, unless: Proc.new { |r| false }
before_save Proc.new { |r| r.history << "b00m" }, unless: Proc.new { |r| true }
before_save Proc.new { |r| r.history << "b00m" }, unless: proc(&:history)
before_save Proc.new { |r| r.history << "b00m" }, unless: lambda(&:history)
# symbol
before_save Proc.new { |r| r.history << [:before_save, :symbol] }, if: :yes
before_save Proc.new { |r| r.history << "b00m" }, if: :no
Expand Down

0 comments on commit 2043d15

Please sign in to comment.