diff options
author | Matthew Draper <matthew@trebex.net> | 2016-11-25 00:48:00 +1030 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-25 00:48:00 +1030 |
commit | 33039fa7239afdde963fe651637226a7dca4b85b (patch) | |
tree | 8f27dc90159f788c19c01bdcea2b397753d57836 /activerecord/test | |
parent | 2f73982c215b6573bfa59e5a89471aedbd7c211a (diff) | |
parent | 935502062e647def60288944808240667f7893cc (diff) | |
download | rails-33039fa7239afdde963fe651637226a7dca4b85b.tar.gz rails-33039fa7239afdde963fe651637226a7dca4b85b.tar.bz2 rails-33039fa7239afdde963fe651637226a7dca4b85b.zip |
Merge pull request #26718 from domcleal/5-0-stable-ids-writer-exception
Restore RecordNotFound when *_ids= can't find records by ID
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 17 |
1 files changed, 16 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..8defb09db7 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -883,10 +883,25 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end + def test_collection_singular_ids_setter_with_changed_primary_key + company = companies(:first_firm) + client = companies(:first_client) + company.clients_using_primary_key_ids = [client.name] + assert_equal [client], company.clients_using_primary_key + end + 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_collection_singular_ids_setter_raises_exception_when_invalid_ids_set_with_changed_primary_key + company = companies(:first_firm) + ids = [Client.first.name, "unknown client"] + e = assert_raises(ActiveRecord::RecordNotFound) { company.clients_using_primary_key_ids = ids } + assert_match(/Couldn't find all Clients with 'name'/, e.message) end def test_build_a_model_from_hm_through_association_with_where_clause |