Use major + minor AR versions in 'Directly inheriting' error message

This commit is contained in:
Ryan Bigg 2021-01-16 08:07:31 +11:00 committed by Rafael Mendonça França
parent f250208dd4
commit 80f204b78c
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 5 additions and 3 deletions

View File

@ -556,10 +556,12 @@ module ActiveRecord
def self.inherited(subclass) #:nodoc:
super
if subclass.superclass == Migration
major = ActiveRecord::VERSION::MAJOR
minor = ActiveRecord::VERSION::MINOR
raise StandardError, "Directly inheriting from ActiveRecord::Migration is not supported. " \
"Please specify the Rails release the migration was written for:\n" \
"Please specify the Active Record release the migration was written for:\n" \
"\n" \
" class #{subclass} < ActiveRecord::Migration[4.2]"
" class #{subclass} < ActiveRecord::Migration[#{major}.#{minor}]"
end
end

View File

@ -204,7 +204,7 @@ module ActiveRecord
e = assert_raises(StandardError) do
class_eval("class LegacyMigration < ActiveRecord::Migration; end")
end
assert_match(/LegacyMigration < ActiveRecord::Migration\[4\.2\]/, e.message)
assert_match(/LegacyMigration < ActiveRecord::Migration\[\d\.\d\]/, e.message)
end
def test_legacy_migrations_not_raise_exception_on_reverting_transaction