mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Finder gives a little bit more info on the lookup column (primary key)
This commit is contained in:
parent
b15d816166
commit
983976ec54
2 changed files with 11 additions and 1 deletions
|
@ -300,7 +300,7 @@ module ActiveRecord
|
|||
unless record
|
||||
conditions = arel.where_sql
|
||||
conditions = " [#{conditions}]" if conditions
|
||||
raise RecordNotFound, "Couldn't find #{@klass.name} with ID=#{id}#{conditions}"
|
||||
raise RecordNotFound, "Couldn't find #{@klass.name} with #{@klass.primary_key}=#{id}#{conditions}"
|
||||
end
|
||||
|
||||
record
|
||||
|
|
|
@ -10,6 +10,7 @@ require 'models/entrant'
|
|||
require 'models/project'
|
||||
require 'models/developer'
|
||||
require 'models/customer'
|
||||
require 'models/toy'
|
||||
|
||||
class FinderTest < ActiveRecord::TestCase
|
||||
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers, :categories, :categorizations
|
||||
|
@ -1010,6 +1011,15 @@ class FinderTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_find_one_message_with_custom_primary_key
|
||||
Toy.set_primary_key :name
|
||||
begin
|
||||
Toy.find 'Hello World!'
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
assert_equal 'Couldn\'t find Toy with name=Hello World!', e.message
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def bind(statement, *vars)
|
||||
if vars.first.is_a?(Hash)
|
||||
|
|
Loading…
Reference in a new issue