aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorwangjohn <wangjohn@mit.edu>2013-03-31 21:23:53 -0400
committerwangjohn <wangjohn@mit.edu>2013-04-01 15:56:23 -0400
commit6c5032f53de9f4ba1669ff9c9eea25c70bf3af33 (patch)
tree83956550aaf33af713bcfa1fee8c2c45f0558408 /activerecord/test/cases
parent93302dc442231199fdb871e58055798e7c41b79c (diff)
downloadrails-6c5032f53de9f4ba1669ff9c9eea25c70bf3af33.tar.gz
rails-6c5032f53de9f4ba1669ff9c9eea25c70bf3af33.tar.bz2
rails-6c5032f53de9f4ba1669ff9c9eea25c70bf3af33.zip
Throwing a RecordNotFound exception when a record is scanned using the
inverse_of option. I've also refactored the code for raising a RecordNotFound exception when searching for records with ids.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index c8cad84013..89d2876c6c 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -303,6 +303,24 @@ class InverseHasManyTests < ActiveRecord::TestCase
assert_equal man.name, man.interests.find(interest.id).man.name, "The name of the man should match after the child name is changed"
end
+ 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) }
+
+ invalid_ids = [8432342, 2390102913, 2453245234523452]
+ assert_raise(ActiveRecord::RecordNotFound) { man.interests.find(invalid_ids) }
+ end
+
+ 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
+
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.first.secret_interests }
end