aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_test.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-09-20 16:12:13 +0000
committerJamis Buck <jamis@37signals.com>2005-09-20 16:12:13 +0000
commit5213a1f73332995ae98d2a163454dff2b288e650 (patch)
tree45b4d6979c5812e4ea2208971de15a1827bcc9d9 /activerecord/test/associations_test.rb
parent4fa9a2bfe22515f893368786982dd6e76241b552 (diff)
downloadrails-5213a1f73332995ae98d2a163454dff2b288e650.tar.gz
rails-5213a1f73332995ae98d2a163454dff2b288e650.tar.bz2
rails-5213a1f73332995ae98d2a163454dff2b288e650.zip
Fixed saving a record with two unsaved belongs_to associations pointing to the same object #2023 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2278 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-xactiverecord/test/associations_test.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 35e14a5e19..763b66da9b 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -794,6 +794,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
assert_equal num_orders +1, Order.count
assert_equal num_customers +2, Customer.count
end
+
def test_store_association_in_two_relations_with_one_save
num_orders = Order.count
@@ -814,6 +815,50 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
assert_equal num_customers +1, Customer.count
end
+ def test_store_association_in_two_relations_with_one_save_in_existing_object
+ num_orders = Order.count
+ num_customers = Customer.count
+ order = Order.create
+
+ customer = order.billing = order.shipping = Customer.new
+ assert order.save
+ assert_equal customer, order.billing
+ assert_equal customer, order.shipping
+
+ order.reload
+
+ assert_equal customer, order.billing
+ assert_equal customer, order.shipping
+
+ assert_equal num_orders +1, Order.count
+ assert_equal num_customers +1, Customer.count
+ end
+
+ def test_store_association_in_two_relations_with_one_save_in_existing_object_with_values
+ num_orders = Order.count
+ num_customers = Customer.count
+ order = Order.create
+
+ customer = order.billing = order.shipping = Customer.new
+ assert order.save
+ assert_equal customer, order.billing
+ assert_equal customer, order.shipping
+
+ order.reload
+
+ customer = order.billing = order.shipping = Customer.new
+
+ assert order.save
+ order.reload
+
+ assert_equal customer, order.billing
+ assert_equal customer, order.shipping
+
+ assert_equal num_orders +1, Order.count
+ assert_equal num_customers +2, Customer.count
+ end
+
+
def test_association_assignment_sticks
post = Post.find(:first)
author1, author2 = Author.find(:all, :limit => 2)