aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-19 05:30:42 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-19 05:30:42 +0000
commit16b129a68ca1770815107a3edb54090282349ba7 (patch)
treefedc506d08a766066a829ae8efa3d691cc719aff /activerecord/test/cases
parentf95ff8d4dc37ced3b4493ad628e3ff7e5d950efd (diff)
downloadrails-16b129a68ca1770815107a3edb54090282349ba7.tar.gz
rails-16b129a68ca1770815107a3edb54090282349ba7.tar.bz2
rails-16b129a68ca1770815107a3edb54090282349ba7.zip
belongs_to supports :dependent => :destroy and :delete. Closes #10592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8675 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-xactiverecord/test/cases/associations_test.rb19
-rw-r--r--activerecord/test/cases/json_serialization_test.rb2
2 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index b21f0cc9e2..301f8a6e2c 100755
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -470,7 +470,7 @@ end
class HasManyAssociationsTest < ActiveSupport::TestCase
fixtures :accounts, :companies, :developers, :projects,
- :developers_projects, :topics, :authors, :comments
+ :developers_projects, :topics, :authors, :comments, :author_addresses
def setup
Client.destroyed_client_ids.clear
@@ -995,6 +995,23 @@ class HasManyAssociationsTest < ActiveSupport::TestCase
assert_equal 1, Client.find_all_by_client_of(firm.id).size
end
+ def test_dependent_delete_and_destroy_with_belongs_to
+ author_address = author_addresses(:david_address)
+ assert_equal [], AuthorAddress.destroyed_author_address_ids[authors(:david).id]
+
+ assert_difference "AuthorAddress.count", -2 do
+ authors(:david).destroy
+ end
+
+ assert_equal [author_address.id], AuthorAddress.destroyed_author_address_ids[authors(:david).id]
+ end
+
+ def test_invalid_belongs_to_dependent_option_raises_exception
+ assert_raises ArgumentError do
+ Author.belongs_to :special_author_address, :dependent => :nullify
+ end
+ end
+
def test_clearing_without_initial_access
firm = companies(:first_firm)
diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb
index 465c2454fc..779b8e02ad 100644
--- a/activerecord/test/cases/json_serialization_test.rb
+++ b/activerecord/test/cases/json_serialization_test.rb
@@ -151,7 +151,7 @@ class DatabaseConnectedJsonEncodingTest < ActiveSupport::TestCase
def test_should_allow_except_option_for_list_of_authors
authors = [@david, @mary]
- assert_equal %([{"id": 1}, {"id": 2}]), authors.to_json(:except => [:name, :author_address_id])
+ assert_equal %([{"id": 1}, {"id": 2}]), authors.to_json(:except => [:name, :author_address_id, :author_address_extra_id])
end
def test_should_allow_includes_for_list_of_authors