diff options
author | Michel Pigassou <mpigassou@zendesk.com> | 2016-07-30 15:19:30 +0200 |
---|---|---|
committer | Michel Pigassou <mpigassou@zendesk.com> | 2016-08-13 12:41:45 -0700 |
commit | cafdbeba9043c25280fb816ec5e554ae2d020f86 (patch) | |
tree | c9904aa5466cabbf8114d012af51b80b1ba13228 /activerecord/test/cases | |
parent | 6107a40c0e4d05614493bddf33d5ae8d9ce8a8d2 (diff) | |
download | rails-cafdbeba9043c25280fb816ec5e554ae2d020f86.tar.gz rails-cafdbeba9043c25280fb816ec5e554ae2d020f86.tar.bz2 rails-cafdbeba9043c25280fb816ec5e554ae2d020f86.zip |
When calling association.find RecordNotFound is now raised with the same argument as when we do it in Record.find (primary_key, id and model).
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_associations_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 09692fc3a0..db71e0d13c 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -618,6 +618,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_raise(ActiveRecord::RecordNotFound) { firm.clients.find(2, 99) } end + def test_find_one_message_on_primary_key + firm = Firm.all.merge!(order: "id").first + + e = assert_raises(ActiveRecord::RecordNotFound) do + firm.clients.find(0) + end + assert_equal 0, e.id + assert_equal "id", e.primary_key + assert_equal "Client", e.model + assert_match (/\ACouldn't find Client with 'id'=0/), e.message + end + def test_find_ids_and_inverse_of force_signal37_to_load_all_clients_of_firm diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index bf0ce18bb8..390156ef37 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -1119,6 +1119,16 @@ class FinderTest < ActiveRecord::TestCase assert_equal [0, 1, 1], posts.map(&:author_id).sort end + def test_find_one_message_on_primary_key + e = assert_raises(ActiveRecord::RecordNotFound) do + Car.find(0) + end + assert_equal 0, e.id + assert_equal "id", e.primary_key + assert_equal "Car", e.model + assert_equal "Couldn't find Car with 'id'=0", e.message + end + def test_find_one_message_with_custom_primary_key table_with_custom_primary_key do |model| model.primary_key = :name |