diff options
author | Daniel Colson <danieljamescolson@gmail.com> | 2017-01-31 17:12:19 -0500 |
---|---|---|
committer | Daniel Colson <danieljamescolson@gmail.com> | 2017-02-02 22:26:49 -0500 |
commit | 796d8599f384c7da41318695028d60e62738beb0 (patch) | |
tree | ceb29c5fbe9b19828a6a36664011f99ea9c9e460 /activerecord/test | |
parent | 91c6eb602ad72c5b830cd5242f39768f90cf72dc (diff) | |
download | rails-796d8599f384c7da41318695028d60e62738beb0.tar.gz rails-796d8599f384c7da41318695028d60e62738beb0.tar.bz2 rails-796d8599f384c7da41318695028d60e62738beb0.zip |
Fix collection_singular_ids= bug
When the association's primary key is manually set as a symbol and called with an array of strings, CollectionAssociation#ids_writer
fails to cast the ids to integers. This is because
AssociationReflection#association_primary_key_type and
ThroughReflection#association_primary_key_type return the incorrect
type, since ModelSchema.type_for_attribute only accepts a string. The
result is an ActiveRecord::RecordNotFound error.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/reflection_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 04ee67c177..c1c2efb9c8 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -335,6 +335,15 @@ class ReflectionTest < ActiveRecord::TestCase assert_equal "custom_primary_key", Author.reflect_on_association(:tags_with_primary_key).association_primary_key.to_s # nested end + def test_association_primary_key_type + # Normal Association + assert_equal :integer, Author.reflect_on_association(:posts).association_primary_key_type.type + assert_equal :string, Author.reflect_on_association(:essay).association_primary_key_type.type + + # Through Association + assert_equal :string, Author.reflect_on_association(:essay_category).association_primary_key_type.type + end + def test_association_primary_key_raises_when_missing_primary_key reflection = ActiveRecord::Reflection.create(:has_many, :edge, nil, {}, Author) assert_raises(ActiveRecord::UnknownPrimaryKey) { reflection.association_primary_key } |