Improve clarity of error message for missing includes and eager_load
relations
This commit is contained in:
parent
1ac3fb9f06
commit
867a9cbbb8
@ -228,7 +228,7 @@ def walk(left, right)
|
||||
|
||||
def find_reflection(klass, name)
|
||||
klass._reflect_on_association(name) or
|
||||
raise ConfigurationError, "Association named '#{ name }' was not found on #{ klass.name }; perhaps you misspelled it?"
|
||||
raise ConfigurationError, "Can't join '#{ klass.name }' to association named '#{ name }'; perhaps you misspelled it?"
|
||||
end
|
||||
|
||||
def build(associations, base_klass)
|
||||
|
@ -740,6 +740,23 @@ def test_has_many_with_pluralize_table_names_false
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user