aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-08-16 05:36:18 -0300
committerGitHub <noreply@github.com>2016-08-16 05:36:18 -0300
commitcaef3b92149c2f73536110ec0ef582b43e48329c (patch)
tree07b00a2a3e5916067861e63a4e324e50aab6a6da /activerecord/test/cases
parent1a52ed178423dd727653c31398045993cd8c8cb8 (diff)
parentcafdbeba9043c25280fb816ec5e554ae2d020f86 (diff)
downloadrails-caef3b92149c2f73536110ec0ef582b43e48329c.tar.gz
rails-caef3b92149c2f73536110ec0ef582b43e48329c.tar.bz2
rails-caef3b92149c2f73536110ec0ef582b43e48329c.zip
Merge pull request #26097 from Dagnan/fix_recordnotfound_args_rebased
When calling association.find RecordNotFound is now raised with the s…
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
-rw-r--r--activerecord/test/cases/finder_test.rb10
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 dd3b7240b8..d53c2b0c51 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -622,6 +622,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 c32fa3b1e2..f8f9f2d383 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