diff options
author | Hongli Lai (Phusion <hongli@phusion.nl> | 2008-09-21 23:01:32 +0200 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-09-21 22:53:44 +0100 |
commit | 46939a9b5a0098fddeac99a8a4331f66bdd0710e (patch) | |
tree | 8e233668c2bac790bd54b50d664f813903f199f6 /activerecord/test | |
parent | 5f83e1844c83c19cf97c6415b943c6ec3cb4bb06 (diff) | |
download | rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.tar.gz rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.tar.bz2 rails-46939a9b5a0098fddeac99a8a4331f66bdd0710e.zip |
Add Model#delete instance method, similar to Model.delete class method. [#1086 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index aebcca634c..d3f00be894 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -472,6 +472,18 @@ class BasicsTest < ActiveRecord::TestCase assert topic.instance_variable_get("@custom_approved") end + def test_delete + topic = Topic.find(1) + assert_equal topic, topic.delete, 'topic.delete did not return self' + assert topic.frozen?, 'topic not frozen after delete' + assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) } + end + + def test_delete_doesnt_run_callbacks + Topic.find(1).delete + assert_not_nil Topic.find(2) + end + def test_destroy topic = Topic.find(1) assert_equal topic, topic.destroy, 'topic.destroy did not return self' @@ -820,6 +832,20 @@ class BasicsTest < ActiveRecord::TestCase assert_equal [ Topic.find(1) ], [ Topic.find(2).topic ] & [ Topic.find(1) ] end + def test_delete_new_record + client = Client.new + client.delete + assert client.frozen? + end + + def test_delete_record_with_associations + client = Client.find(3) + client.delete + assert client.frozen? + assert_kind_of Firm, client.firm + assert_raises(ActiveSupport::FrozenObjectError) { client.name = "something else" } + end + def test_destroy_new_record client = Client.new client.destroy |