diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2016-03-18 10:41:57 -0400 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2016-03-18 10:41:57 -0400 |
commit | a4ef62279d69d901b99fe0e71338b5aaebab01c0 (patch) | |
tree | 81afa1e06e1daff9638ea85abeef51c425236992 /activerecord/test/cases | |
parent | 5bd5ee1e805d8cb084822388798d120d887bfc52 (diff) | |
parent | 867a9cbbb818bb4f0d3990403c554a632f367944 (diff) | |
download | rails-a4ef62279d69d901b99fe0e71338b5aaebab01c0.tar.gz rails-a4ef62279d69d901b99fe0e71338b5aaebab01c0.tar.bz2 rails-a4ef62279d69d901b99fe0e71338b5aaebab01c0.zip |
Merge pull request #22518 from RochesterinNYC/better-error-message-for-includes-relations-missing
Improve error message for missing relations for includes and eager_load
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/join_model_test.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 1d892a0956..c7bd9d2119 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -747,6 +747,23 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase assert_equal aircraft.engines, [engine] end + def test_proper_error_message_for_eager_load_and_includes_association_errors + includes_error = assert_raises(ActiveRecord::ConfigurationError) { + Post.includes(:nonexistent_relation).where(nonexistent_relation: {name: 'Rochester'}).find(1) + } + assert_equal("Can't join 'Post' to association named 'nonexistent_relation'; perhaps you misspelled it?", includes_error.message) + + eager_load_error = assert_raises(ActiveRecord::ConfigurationError) { + Post.eager_load(:nonexistent_relation).where(nonexistent_relation: {name: 'Rochester'}).find(1) + } + assert_equal("Can't join 'Post' to association named 'nonexistent_relation'; perhaps you misspelled it?", eager_load_error.message) + + includes_and_eager_load_error = assert_raises(ActiveRecord::ConfigurationError) { + Post.eager_load(:nonexistent_relation).includes(:nonexistent_relation).where(nonexistent_relation: {name: 'Rochester'}).find(1) + } + assert_equal("Can't join 'Post' to association named 'nonexistent_relation'; perhaps you misspelled it?", includes_and_eager_load_error.message) + end + private # create dynamic Post models to allow different dependency options def find_post_with_dependency(post_id, association, association_name, dependency) |