diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2018-09-26 11:40:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 11:40:55 -0400 |
commit | 36440720689c07eb2c45d9d39005814e71e387a4 (patch) | |
tree | b162f17d2a20972e188fb005abd62ca0bd7afe16 /activerecord/test/cases | |
parent | a592e87a278cec10569d854dd5ece22179471bc0 (diff) | |
parent | 92e024c6abac16cc5a96ec948c381bfa3f0a22df (diff) | |
download | rails-36440720689c07eb2c45d9d39005814e71e387a4.tar.gz rails-36440720689c07eb2c45d9d39005814e71e387a4.tar.bz2 rails-36440720689c07eb2c45d9d39005814e71e387a4.zip |
Merge pull request #31819 from bpohoriletz/master
If association is a hash-like object preloading fails
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/eager_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb index ca902131f4..79b3b4a6ad 100644 --- a/activerecord/test/cases/associations/eager_test.rb +++ b/activerecord/test/cases/associations/eager_test.rb @@ -1618,6 +1618,32 @@ class EagerAssociationTest < ActiveRecord::TestCase end end + # Associations::Preloader#preloaders_on works with hash-like objects + test "preloading works with an object that responds to :to_hash" do + CustomHash = Class.new(Hash) + + assert_nothing_raised do + Post.preload(CustomHash.new(comments: [{ author: :essays }])).first + end + end + + # Associations::Preloader#preloaders_on works with string-like objects + test "preloading works with an object that responds to :to_str" do + CustomString = Class.new(String) + + assert_nothing_raised do + Post.preload(CustomString.new("comments")).first + end + end + + # Associations::Preloader#preloaders_on does not work with ranges + test "preloading fails when Range is passed" do + exception = assert_raises(ArgumentError) do + Post.preload(1..10).first + end + assert_equal("1..10 was not recognized for preload", exception.message) + end + private def find_all_ordered(klass, include = nil) klass.order("#{klass.table_name}.#{klass.primary_key}").includes(include).to_a |