diff options
author | Scott Barron <scott@elitists.net> | 2005-09-28 00:09:50 +0000 |
---|---|---|
committer | Scott Barron <scott@elitists.net> | 2005-09-28 00:09:50 +0000 |
commit | 83b390bcfcded8bd5263883ddf741ef35bccc801 (patch) | |
tree | 99afdd1d134bd6cc7404c2d2f96e6466572158a7 /activerecord/test | |
parent | 8e78e9335b6b6e86d5a55f9d00ea0ab699268cc5 (diff) | |
download | rails-83b390bcfcded8bd5263883ddf741ef35bccc801.tar.gz rails-83b390bcfcded8bd5263883ddf741ef35bccc801.tar.bz2 rails-83b390bcfcded8bd5263883ddf741ef35bccc801.zip |
Returning false in before_destroy should cancel action. Closes #1829.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2381 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/callbacks_test.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/activerecord/test/callbacks_test.rb b/activerecord/test/callbacks_test.rb index d915b3a875..ea522ca7ac 100644 --- a/activerecord/test/callbacks_test.rb +++ b/activerecord/test/callbacks_test.rb @@ -70,6 +70,25 @@ class RecursiveCallbackDeveloper < ActiveRecord::Base end end +class ImmutableDeveloper < ActiveRecord::Base + set_table_name 'developers' + + before_destroy :cancel_destroy + + private + + def cancel_destroy + return false + end +end + +class ImmutableMethodDeveloper < ActiveRecord::Base + set_table_name 'developers' + + def before_destroy + return false + end +end class CallbacksTest < Test::Unit::TestCase fixtures :developers @@ -282,6 +301,24 @@ class CallbacksTest < Test::Unit::TestCase [ :after_initialize, :block ], ], david.history end + + def test_before_destroy_returning_false + david = ImmutableDeveloper.find(1) + devs = ImmutableDeveloper.find(:all).size + assert !david.destroy + # cancel_destroy returns false so the destruction should + # be cancelled + assert_equal ImmutableDeveloper.find(:all).size, devs + + david = ImmutableMethodDeveloper.find(1) + devs = ImmutableMethodDeveloper.find(:all).size + assert !david.destroy + # before_destroy returns false so the destruction should + # be cancelled + assert_equal ImmutableMethodDeveloper.find(:all).size, devs + end + + def test_zzz_callback_returning_false # must be run last since we modify CallbackDeveloper david = CallbackDeveloper.find(1) |