mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #15762 from arthurnn/better_error_on_bad_alias_method
Dont swallow errors when bad alias_method
This commit is contained in:
commit
843b8c0b8c
3 changed files with 27 additions and 10 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
* Dont swallow errors on compute_type when having a bad alias_method on
|
||||||
|
a class.
|
||||||
|
|
||||||
|
*arthurnn*
|
||||||
|
|
||||||
* PostgreSQL invalid `uuid` are convert to nil.
|
* PostgreSQL invalid `uuid` are convert to nil.
|
||||||
|
|
||||||
*Abdelkader Boudih*
|
*Abdelkader Boudih*
|
||||||
|
|
|
@ -151,14 +151,8 @@ module ActiveRecord
|
||||||
candidates << type_name
|
candidates << type_name
|
||||||
|
|
||||||
candidates.each do |candidate|
|
candidates.each do |candidate|
|
||||||
begin
|
constant = ActiveSupport::Dependencies.safe_constantize(candidate)
|
||||||
constant = ActiveSupport::Dependencies.constantize(candidate)
|
return constant if candidate == constant.to_s
|
||||||
return constant if candidate == constant.to_s
|
|
||||||
# We don't want to swallow NoMethodError < NameError errors
|
|
||||||
rescue NoMethodError
|
|
||||||
raise
|
|
||||||
rescue NameError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)
|
||||||
|
|
|
@ -1347,14 +1347,32 @@ class BasicsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_compute_type_no_method_error
|
def test_compute_type_no_method_error
|
||||||
ActiveSupport::Dependencies.stubs(:constantize).raises(NoMethodError)
|
ActiveSupport::Dependencies.stubs(:safe_constantize).raises(NoMethodError)
|
||||||
assert_raises NoMethodError do
|
assert_raises NoMethodError do
|
||||||
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_compute_type_on_undefined_method
|
||||||
|
error = nil
|
||||||
|
begin
|
||||||
|
Class.new(Author) do
|
||||||
|
alias_method :foo, :bar
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
error = e
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveSupport::Dependencies.stubs(:safe_constantize).raises(e)
|
||||||
|
|
||||||
|
exception = assert_raises NameError do
|
||||||
|
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
||||||
|
end
|
||||||
|
assert_equal error.message, exception.message
|
||||||
|
end
|
||||||
|
|
||||||
def test_compute_type_argument_error
|
def test_compute_type_argument_error
|
||||||
ActiveSupport::Dependencies.stubs(:constantize).raises(ArgumentError)
|
ActiveSupport::Dependencies.stubs(:safe_constantize).raises(ArgumentError)
|
||||||
assert_raises ArgumentError do
|
assert_raises ArgumentError do
|
||||||
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
ActiveRecord::Base.send :compute_type, 'InvalidModel'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue