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

Added protection against duplicate migration names (Aslak Hellesøy) [#112 state:resolved]

This commit is contained in:
Aslak Hellesøy 2008-05-07 07:59:34 +02:00 committed by David Heinemeier Hansson
parent 4cc594bd70
commit 10fdf44236
5 changed files with 32 additions and 0 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Added protection against duplicate migration names (Aslak Hellesøy) [#112]
* Base#instantiate_time_object: eliminate check for Time.zone, since we can assume this is set if time_zone_aware_attributes is set to true [Geoff Buesing]
* Time zone aware attribute methods use Time.zone.parse instead of #to_time for String arguments, so that offset information in String is respected. Resolves #105. [Scott Fleckenstein, Geoff Buesing]

View file

@ -8,6 +8,12 @@ module ActiveRecord
end
end
class DuplicateMigrationNameError < ActiveRecordError#:nodoc:
def initialize(name)
super("Multiple migrations have the name #{name}")
end
end
class UnknownMigrationVersionError < ActiveRecordError #:nodoc:
def initialize(version)
super("No migration with version number #{version}")
@ -441,6 +447,10 @@ module ActiveRecord
raise DuplicateMigrationVersionError.new(version)
end
if klasses.detect { |m| m.name == name.camelize }
raise DuplicateMigrationNameError.new(name.camelize)
end
load(file)
klasses << returning(name.camelize.constantize) do |klass|

View file

@ -984,6 +984,12 @@ if ActiveRecord::Base.connection.supports_migrations?
end
end
def test_migrator_with_duplicate_names
assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil)
end
end
def test_migrator_with_missing_version_numbers
assert_raise(ActiveRecord::UnknownMigrationVersionError) do
ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/missing", 500)

View file

@ -0,0 +1,7 @@
class Chunky < ActiveRecord::Migration
def self.up
end
def self.down
end
end

View file

@ -0,0 +1,7 @@
class Chunky < ActiveRecord::Migration
def self.up
end
def self.down
end
end