Permalink
Browse files

Added protection against duplicate migration names (Aslak Hellesøy) [#…

…112 state:resolved]
  • Loading branch information...
1 parent 4cc594b commit 10fdf44236ea9abfd327fc59d83670d4bcb3e0ca @aslakhellesoy aslakhellesoy committed with dhh May 7, 2008
View
2 activerecord/CHANGELOG
@@ -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
10 activerecord/lib/active_record/migration.rb
@@ -8,6 +8,12 @@ def initialize(version)
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}")
@@ -440,6 +446,10 @@ def migrations
if klasses.detect { |m| m.version == version }
raise DuplicateMigrationVersionError.new(version)
end
+
+ if klasses.detect { |m| m.name == name.camelize }
+ raise DuplicateMigrationNameError.new(name.camelize)
+ end
load(file)
View
6 activerecord/test/cases/migration_test.rb
@@ -984,6 +984,12 @@ def test_migrator_with_duplicates
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
7 activerecord/test/migrations/duplicate_names/20080507052938_chunky.rb
@@ -0,0 +1,7 @@
+class Chunky < ActiveRecord::Migration
+ def self.up
+ end
+
+ def self.down
+ end
+end
View
7 activerecord/test/migrations/duplicate_names/20080507053028_chunky.rb
@@ -0,0 +1,7 @@
+class Chunky < ActiveRecord::Migration
+ def self.up
+ end
+
+ def self.down
+ end
+end

0 comments on commit 10fdf44

Please sign in to comment.