aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_through_associations_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-02-26 12:40:22 -0700
committerSean Griffin <sean@thoughtbot.com>2015-02-26 12:42:55 -0700
commit38218929e9b3205a2a731660b3c5527937e1c015 (patch)
treed5fe509a1750905969eb7f4bfb47a180ac048fd4 /activerecord/test/cases/associations/has_many_through_associations_test.rb
parentf069b413216f207056b4e46ba302afc646201c1e (diff)
downloadrails-38218929e9b3205a2a731660b3c5527937e1c015.tar.gz
rails-38218929e9b3205a2a731660b3c5527937e1c015.tar.bz2
rails-38218929e9b3205a2a731660b3c5527937e1c015.zip
Properly create through records when called with `where`
Various behaviors needed by associations (such as creating the through record) are lost when `where` is called, since we stop having a `CollectionProxy` and start having an `AssociationRelation` which does not contain this behavior. I *think* we should be able to rm `AssociationRelation`, but we have tests saying the changes required to do that would be bad (Without saying why. Of course. >_>) Fixes #19073.
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.rb6
1 files changed, 6 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 6729a5a9fc..5f52c65412 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -595,6 +595,12 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb")
end
+ def test_through_record_is_built_when_created_with_where
+ assert_difference("posts(:thinking).readers.count", 1) do
+ posts(:thinking).people.where(first_name: "Jeb").create
+ end
+ end
+
def test_associate_with_create_and_no_options
peeps = posts(:thinking).people.count
posts(:thinking).people.create(:first_name => 'foo')