diff options
author | Pavel Pravosud <pavel@pravosud.com> | 2015-09-05 17:48:15 -0700 |
---|---|---|
committer | Pavel Pravosud <pavel@pravosud.com> | 2015-09-07 00:04:31 -0700 |
commit | 4ff626cac901b41f86646dab1939d2a95b2d26bd (patch) | |
tree | d9c19561cf94aa088a41ec45381ada3adf6f30c2 /activerecord/lib/active_record/migration.rb | |
parent | f443ae670de9ce9bcb8c00adde08405d2cfd70db (diff) | |
download | rails-4ff626cac901b41f86646dab1939d2a95b2d26bd.tar.gz rails-4ff626cac901b41f86646dab1939d2a95b2d26bd.tar.bz2 rails-4ff626cac901b41f86646dab1939d2a95b2d26bd.zip |
Make ActiveRecordException descendants args optional
This change allows to instantiate all ActiveRecordError descendant
execption classes without arguments, which might be useful in testing
and is far less surprising than mandatory arguments.
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 112d52024f..3b90ab1e31 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -84,35 +84,53 @@ module ActiveRecord end class DuplicateMigrationVersionError < MigrationError#:nodoc: - def initialize(version) - super("Multiple migrations have the version number #{version}") + def initialize(version = nil) + if version + super("Multiple migrations have the version number #{version}.") + else + super("Duplicate migration version error.") + end end end class DuplicateMigrationNameError < MigrationError#:nodoc: - def initialize(name) - super("Multiple migrations have the name #{name}") + def initialize(name = nil) + if name + super("Multiple migrations have the name #{name}.") + else + super("Duplicate migration name.") + end end end class UnknownMigrationVersionError < MigrationError #:nodoc: - def initialize(version) - super("No migration with version number #{version}") + def initialize(version = nil) + if version + super("No migration with version number #{version}.") + else + super("Unknown migration version.") + end end end class IllegalMigrationNameError < MigrationError#:nodoc: - def initialize(name) - super("Illegal name for migration file: #{name}\n\t(only lower case letters, numbers, and '_' allowed)") + def initialize(name = nil) + if name + super("Illegal name for migration file: #{name}\n\t(only lower case letters, numbers, and '_' allowed).") + else + super("Illegal name for migration.") + end end end class PendingMigrationError < MigrationError#:nodoc: - def initialize - if defined?(Rails.env) - super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate RAILS_ENV=#{::Rails.env}") + def initialize(message = nil) + if !message && defined?(Rails.env) + super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate RAILS_ENV=#{::Rails.env}.") + elsif !message + super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate.") else - super("Migrations are pending. To resolve this issue, run:\n\n\tbin/rake db:migrate") + super end end end |