diff options
author | Dominic Cleal <dominic@cleal.org> | 2016-10-07 08:56:05 +0100 |
---|---|---|
committer | Dominic Cleal <dominic@cleal.org> | 2016-11-24 09:29:40 +0000 |
commit | 935502062e647def60288944808240667f7893cc (patch) | |
tree | 0d00de76bc70f2808a0d78185eca3db1790674f5 /activerecord/test/cases/associations/has_many_through_associations_test.rb | |
parent | 15e2da656f41af0124f7577858536f3b65462ad5 (diff) | |
download | rails-935502062e647def60288944808240667f7893cc.tar.gz rails-935502062e647def60288944808240667f7893cc.tar.bz2 rails-935502062e647def60288944808240667f7893cc.zip |
Add test for collection *_ids= setter when association primary key set
Fixes casting of IDs to the data type of the association primary key,
rather than then the data type of the model's primary key. (Tests use a
string primary key on the association, rather than an int.)
Tests issue #20995
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.rb | 14 |
1 files changed, 14 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 08a22a58b1..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,6 +883,13 @@ 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] @@ -890,6 +897,13 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase 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 assert_nothing_raised { books(:awdr).subscribers.where(nick: "marklazz").build } end |