From 72c1e19c33ca06008d5d64619a533bdf34e3fc2b Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sat, 25 Sep 2010 18:30:56 -0400 Subject: after_create in ActiveModel should in the order specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#5650 state:resolved] Signed-off-by: José Valim --- activemodel/test/cases/callbacks_test.rb | 30 +++++++++++++++++++++++++++ activesupport/lib/active_support/callbacks.rb | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/activemodel/test/cases/callbacks_test.rb b/activemodel/test/cases/callbacks_test.rb index 64dc7b5026..069d907fb2 100644 --- a/activemodel/test/cases/callbacks_test.rb +++ b/activemodel/test/cases/callbacks_test.rb @@ -81,4 +81,34 @@ class CallbacksTest < ActiveModel::TestCase assert !ModelCallbacks.respond_to?(:around_empty) assert !ModelCallbacks.respond_to?(:after_empty) end + + class Violin + attr_reader :history + def initialize + @history = [] + end + extend ActiveModel::Callbacks + define_model_callbacks :create + def callback1; self.history << 'callback1'; end + def callback2; self.history << 'callback2'; end + def create + _run_create_callbacks {} + self + end + end + class Violin1 < Violin + after_create :callback1, :callback2 + end + class Violin2 < Violin + after_create :callback1 + after_create :callback2 + end + + test "after_create callbacks with both callbacks declared in one line" do + assert_equal ["callback1", "callback2"], Violin1.new.create.history + end + test "after_create callbacks with both callbacks declared in differnt lines" do + assert_equal ["callback1", "callback2"], Violin2.new.create.history + end + end diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index d811c3b2f0..0c1d46c7ec 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 -- cgit v1.2.3