From bea44cbaa48433d427a9418ff6b5c617b10e0585 Mon Sep 17 00:00:00 2001 From: Chulki Lee Date: Fri, 10 Jan 2014 16:27:18 -0800 Subject: Set NameError#name --- activerecord/CHANGELOG.md | 4 ++++ activerecord/lib/active_record/inheritance.rb | 2 +- activerecord/test/cases/base_test.rb | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index f57158f38e..7db700a27a 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Set NameError#name with class name when failed to load the class for association. + + *Chulki Lee* + * Fix bug in `becomes!` when changing from the base model to a STI sub-class. Fixes #13272. diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index 949e7678a5..69896f7219 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -126,7 +126,7 @@ module ActiveRecord end end - raise NameError, "uninitialized constant #{candidates.first}" + raise NameError.new("uninitialized constant #{candidates.first}", candidates.first) end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index cb8e564da1..4bc6002bfe 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1301,9 +1301,11 @@ class BasicsTest < ActiveRecord::TestCase end def test_compute_type_nonexistent_constant - assert_raises NameError do + e = assert_raises NameError do ActiveRecord::Base.send :compute_type, 'NonexistentModel' end + assert_equal 'uninitialized constant ActiveRecord::Base::NonexistentModel', e.message + assert_equal 'ActiveRecord::Base::NonexistentModel', e.name end def test_compute_type_no_method_error -- cgit v1.2.3