diff options
author | José Valim <jose.valim@gmail.com> | 2009-08-01 16:47:44 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-08-07 17:16:16 +0200 |
commit | 7034272354ad41dd4d1c90138a79e7f14ebc2bed (patch) | |
tree | 51c091d7ff973bbeb1aa2bd7417d0da3a9ed71ba /activerecord | |
parent | f59984cc81bd1a64a53a2480a9b4e05fe7357d7c (diff) | |
download | rails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.tar.gz rails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.tar.bz2 rails-7034272354ad41dd4d1c90138a79e7f14ebc2bed.zip |
Add destroyed? to ActiveRecord, include tests for polymorphic urls for destroyed objects and refactor mime responds tests and documentation.
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 7 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 17 |
2 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e358564ead..531a698f77 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2492,6 +2492,11 @@ module ActiveRecord #:nodoc: @new_record || false end + # Returns true if this object has been destroyed, otherwise returns false. + def destroyed? + @destroyed || false + end + # :call-seq: # save(perform_validation = true) # @@ -2542,6 +2547,7 @@ module ActiveRecord #:nodoc: # options, use <tt>#destroy</tt>. def delete self.class.delete(id) unless new_record? + @destroyed = true freeze end @@ -2556,6 +2562,7 @@ module ActiveRecord #:nodoc: ) end + @destroyed = true freeze end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 82eba81549..16364141df 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1271,6 +1271,23 @@ class BasicsTest < ActiveRecord::TestCase assert_equal Topic.find(1).new_record?, false end + def test_destroyed_returns_boolean + developer = Developer.new + assert_equal developer.destroyed?, false + developer.destroy + assert_equal developer.destroyed?, true + + developer = Developer.first + assert_equal developer.destroyed?, false + developer.destroy + assert_equal developer.destroyed?, true + + developer = Developer.last + assert_equal developer.destroyed?, false + developer.delete + assert_equal developer.destroyed?, true + end + def test_clone topic = Topic.find(1) cloned_topic = nil |