From a8f2900d4837a759ba1e1a0ecef71728be52d1f3 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 25 Sep 2010 12:11:04 -0400 Subject: [PATCH] wip --- activesupport/lib/active_support/callbacks.rb | 2 +- activesupport/test/callbacks_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index d811c3b..0c1d46c 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -482,7 +482,7 @@ module ActiveSupport chain.delete_if {|c| c.matches?(type, filter) } end - options[:prepend] ? chain.unshift(*mapped) : chain.push(*mapped) + options[:prepend] ? chain.unshift(*(mapped.reverse)) : chain.push(*mapped) end end diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 292383e..08063aa 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -149,6 +149,27 @@ module CallbacksTest end end + class AfterSaveConditionalPerson < Record + after_save Proc.new { |r| r.history << [:after_save, :string1] } + after_save Proc.new { |r| r.history << [:after_save, :string2] } + def save + run_callbacks :save + end + end + + class AfterSaveConditionalPersonCallbackTest < Test::Unit::TestCase + def test_save_conditional_person + person = AfterSaveConditionalPerson.new + person.save + assert_equal [ + [:before_save, :string1], + [:before_save, :string2] + ], person.history + end + end + + + class ConditionalPerson < Record # proc before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true } @@ -352,6 +373,8 @@ module CallbacksTest end end + + class ResetCallbackTest < Test::Unit::TestCase def test_save_conditional_person person = CleanPerson.new -- 1.7.2