From 5d66ec0ffbfdd7ebe10818eeac17874740e28638 Mon Sep 17 00:00:00 2001 From: Frederik Fix Date: Sun, 14 Dec 2008 20:00:30 +0100 Subject: [PATCH] fix problem where callbacks can be defined multiple times --- activesupport/lib/active_support/callbacks.rb | 5 +++++ activesupport/test/callbacks_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 5cdcaf5..97226aa 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -114,6 +114,11 @@ module ActiveSupport super(callback.is_a?(Callback) ? callback : find(callback)) end + def concat(chain) + present = map(&:method) + super chain.reject { |c| present.include?(c.method) } + end + private def self.extract_options(*methods, &block) methods.flatten! diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 25b8eec..64588d3 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -145,4 +145,9 @@ class CallbackChainTest < Test::Unit::TestCase @chain.delete(:bacon) assert_equal [:lettuce, :tomato], @chain.map(&:method) end + + def test_multiple_concats + @chain.concat CallbackChain.build(:make, :bacon, :cucumber) + assert_equal [:bacon, :lettuce, :tomato, :cucumber], @chain.map(&:method) + end end -- 1.5.5.1