aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-08 16:04:03 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-13 14:38:34 -0600
commit0a4e3f4a7f6d93c713389140bc6e6613b721b0ff (patch)
tree393f55354f3eb63dde582612a7b26dd5e929ffbf /activerecord/test/cases/associations/has_many_through_associations_test.rb
parent49fee3d271e52a44a7bc7fcbbcb00792b613b7df (diff)
downloadrails-0a4e3f4a7f6d93c713389140bc6e6613b721b0ff.tar.gz
rails-0a4e3f4a7f6d93c713389140bc6e6613b721b0ff.tar.bz2
rails-0a4e3f4a7f6d93c713389140bc6e6613b721b0ff.zip
Through associations should set both parent ids on join models
member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
Diffstat (limited to 'activerecord/test/cases/associations/has_many_through_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 2e62189e7a..8641584c0c 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -330,6 +330,19 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert post.single_people.include?(person)
end
+ def test_both_parent_ids_set_when_saving_new
+ post = Post.new(title: 'Hello', body: 'world')
+ person = Person.new(first_name: 'Sean')
+
+ post.people = [person]
+ post.save
+
+ assert post.id
+ assert person.id
+ assert_equal post.id, post.readers.first.post_id
+ assert_equal person.id, post.readers.first.person_id
+ end
+
def test_delete_association
assert_queries(2){posts(:welcome);people(:michael); }