aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-07 08:23:23 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-07 08:23:23 -0800
commit9bd5c86c3bdc70bf29be7f756d1dec2fdd4eaaf0 (patch)
tree3fd98a9ad3e1de47a2180dda228cabbb3a7ae582 /activerecord/test
parentbb0007f70420445f140004587aa1228895ab6653 (diff)
parent939b896a06c0cff661076d0ca3fbe8c1d5552e83 (diff)
downloadrails-9bd5c86c3bdc70bf29be7f756d1dec2fdd4eaaf0.tar.gz
rails-9bd5c86c3bdc70bf29be7f756d1dec2fdd4eaaf0.tar.bz2
rails-9bd5c86c3bdc70bf29be7f756d1dec2fdd4eaaf0.zip
Merge pull request #9549 from larrylv/reload-stable-target-before-saving
Fix issue #7526. Reload the association target if it's stale.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index f392366c19..c9b26895ae 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -14,6 +14,8 @@ require 'models/sponsor'
require 'models/member'
require 'models/essay'
require 'models/toy'
+require 'models/person'
+require 'models/reader'
class BelongsToAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :topics,
@@ -716,4 +718,16 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal toy, sponsor.reload.sponsorable
end
+
+ def test_saving_nested_association
+ post1, post2 = Post.limit(2)
+ person = Person.new(:first_name => 'foo')
+ reader = Reader.new(:post => post1)
+
+ reader.post_id = post2.id
+ person.readers = [reader]
+
+ assert person.save
+ assert_equal reader.post_id, post2.id
+ end
end