Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Updated the error message for find to stay consistent across Rails #10036

Merged
merged 1 commit into from

2 participants

@wangjohn

The RecordNotFound error message that is raised when using find on an association which has inverse_of defined does not match the error message that is thrown for non-inverse-of associations.

I've changed the error message to stay consistent with the error thrown for find without an
inverse_of association.

I also removed some variables that were not needed in the test cases related to the RecordNotFound error messages.

@wangjohn wangjohn closed this
@wangjohn wangjohn Updated the error message for +find+ on an inverse_of association
so that it is consistent with the error thrown for +find+ without an
inverse_of association.
a605c44
@wangjohn wangjohn reopened this
@rafaelfranca rafaelfranca merged commit abad4f7 into from
@wangjohn wangjohn deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 1, 2013
  1. @wangjohn

    Updated the error message for +find+ on an inverse_of association

    wangjohn authored
    so that it is consistent with the error thrown for +find+ without an
    inverse_of association.
This page is out of date. Refresh to see the latest.
View
2  activerecord/lib/active_record/associations/collection_association.rb
@@ -83,7 +83,7 @@ def find(*args)
find_by_scan(*args)
elsif options[:inverse_of]
args = args.flatten
- raise RecordNotFound, "Must specify an id to find" if args.blank?
+ raise RecordNotFound, "Couldn't find #{scope.klass.name} without an ID" if args.blank?
result = find_by_scan(*args)
View
2  activerecord/test/cases/associations/inverse_associations_test.rb
@@ -305,7 +305,6 @@ def test_parent_instance_should_find_child_instance_using_child_instance_id_when
def test_raise_record_not_found_error_when_invalid_ids_are_passed
man = Man.create!
- interest = Interest.create!(man: man)
invalid_id = 2394823094892348920348523452345
assert_raise(ActiveRecord::RecordNotFound) { man.interests.find(invalid_id) }
@@ -316,7 +315,6 @@ def test_raise_record_not_found_error_when_invalid_ids_are_passed
def test_raise_record_not_found_error_when_no_ids_are_passed
man = Man.create!
- interest = Interest.create!(man: man)
assert_raise(ActiveRecord::RecordNotFound) { man.interests.find() }
end
Something went wrong with that request. Please try again.