1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Change for ActiveRecord::Migration.[] to raise ArgumentError instead of RuntimeError

The error is raised because user passed invalid version number to a public api of
`ActiveRecord`, so `ArgumentError` is more suitable.
And add a test case checking if an error is raised when unknown migration version
is passed, because these test cases are not implemented.
This commit is contained in:
yui-knk 2016-03-24 20:03:43 +09:00
parent 878c2bbaaf
commit cf570d7d01
2 changed files with 4 additions and 1 deletions

View file

@ -528,7 +528,7 @@ module ActiveRecord
name = "V#{version.tr('.', '_')}"
unless Compatibility.const_defined?(name)
versions = Compatibility.constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect }
raise "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
end
Compatibility.const_get(name)
end

View file

@ -1107,4 +1107,7 @@ class CopyMigrationsTest < ActiveRecord::TestCase
ActiveRecord::Base.logger = old
end
def test_unknown_migration_version_should_raise_an_argument_error
assert_raise(ArgumentError) { ActiveRecord::Migration[1.0] }
end
end