Test for after_create callback order in ActiveSupport [#5703 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
72c1e19c33
commit
bfc986811c
|
@ -149,6 +149,27 @@ module CallbacksTest
|
||||||
end
|
end
|
||||||
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_after_save_runs_in_the_reverse_order
|
||||||
|
person = AfterSaveConditionalPerson.new
|
||||||
|
person.save
|
||||||
|
assert_equal [
|
||||||
|
[:after_save, :string2],
|
||||||
|
[:after_save, :string1]
|
||||||
|
], person.history
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConditionalPerson < Record
|
class ConditionalPerson < Record
|
||||||
# proc
|
# proc
|
||||||
before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true }
|
before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true }
|
||||||
|
@ -352,6 +373,8 @@ module CallbacksTest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ResetCallbackTest < Test::Unit::TestCase
|
class ResetCallbackTest < Test::Unit::TestCase
|
||||||
def test_save_conditional_person
|
def test_save_conditional_person
|
||||||
person = CleanPerson.new
|
person = CleanPerson.new
|
||||||
|
|
Loading…
Reference in New Issue