aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorDominic Cleal <dominic@cleal.org>2016-10-06 13:47:26 +0100
committerDominic Cleal <dominic@cleal.org>2016-11-24 09:27:33 +0000
commit15e2da656f41af0124f7577858536f3b65462ad5 (patch)
tree1bbd1f076f37d73d79a1930e8b79d037e74364ef /activerecord/test/cases/associations
parent8556ab505a0a91efb529039b653984ab2b466a7e (diff)
downloadrails-15e2da656f41af0124f7577858536f3b65462ad5.tar.gz
rails-15e2da656f41af0124f7577858536f3b65462ad5.tar.bz2
rails-15e2da656f41af0124f7577858536f3b65462ad5.zip
Restore RecordNotFound when *_ids= can't find records by ID
9c9fb19 changed the behaviour of the _ids= setters for associations to raise an AssociationTypeMismatch when unknown IDs are given: Class: <ActiveRecord::AssociationTypeMismatch> Message: <"Developer(#43811860) expected, got NilClass(#16732720)"> This restores the original ActiveRecord::RecordNotFound exception with a much clearer error message: Class: <ActiveRecord::RecordNotFound> Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)"> Fixes #25719
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb3
1 files changed, 2 insertions, 1 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 c2239ac03a..08a22a58b1 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -886,7 +886,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
def test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set
company = companies(:rails_core)
ids = [Developer.first.id, -9999]
- assert_raises(ActiveRecord::AssociationTypeMismatch) { company.developer_ids = ids }
+ e = assert_raises(ActiveRecord::RecordNotFound) { company.developer_ids = ids }
+ assert_match(/Couldn't find all Developers with 'id'/, e.message)
end
def test_build_a_model_from_hm_through_association_with_where_clause