diff options
author | schneems <richard.schneeman@gmail.com> | 2016-01-08 11:53:25 -0600 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2016-01-08 14:05:20 -0600 |
commit | d70c68d76abcbc24ef0e56b7a7b580d0013255dd (patch) | |
tree | 4c3eef7f058ae7ea341814e8869f808b7a7ef67c /activerecord | |
parent | f6628adc11e2e57db75030fca9bae035be5cd95b (diff) | |
download | rails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.tar.gz rails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.tar.bz2 rails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.zip |
Fixing tests and re-locating error checking.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 15 | ||||
-rw-r--r-- | activerecord/lib/active_record/tasks/database_tasks.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/schema_dumper_test.rb | 8 |
3 files changed, 14 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index e06a581094..f5753fe426 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -164,7 +164,7 @@ module ActiveRecord end class EnvironmentMismatchError < ActiveRecordError - def initialize(current: , stored: ) + def initialize(current: nil, stored: nil) msg = "You are attempting to modify a database that was last run in #{ stored } environment.\n" msg << "You are running in #{ current } environment." msg << "if you are sure you want to continue, run the same command with the environment variable\n" @@ -1238,7 +1238,12 @@ module ActiveRecord end def self.last_stored_environment - ActiveRecord::InternalMetadata[:environment] + return nil if current_version == 0 + raise NoEnvironmentInSchemaError unless ActiveRecord::InternalMetadata.table_exists? + + environment = ActiveRecord::InternalMetadata[:environment] + raise NoEnvironmentInSchemaError unless environment + environment end def self.current_environment @@ -1246,11 +1251,7 @@ module ActiveRecord end def self.protected_environment? - return false if current_version == 0 - raise NoEnvironmentInSchemaError unless ActiveRecord::InternalMetadata.table_exists? - - raise NoEnvironmentInSchemaError unless last_stored_environment - ActiveRecord::Base.protected_environments.include?(last_stored_environment) + ActiveRecord::Base.protected_environments.include?(last_stored_environment) if last_stored_environment end def up? diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index d51f38c93f..7b8f27699a 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -51,8 +51,8 @@ module ActiveRecord raise ActiveRecord::ProtectedEnvironmentError.new(stored) end - if current != stored - raise EnvironmentMismatchError.new(current: current, stored: stored) + if stored && stored != current + raise ActiveRecord::EnvironmentMismatchError.new(current: current, stored: stored) end end rescue ActiveRecord::NoDatabaseError diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 97c3d664ba..2006f40b25 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -38,7 +38,7 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_match %r{create_table "accounts"}, output assert_match %r{create_table "authors"}, output assert_no_match %r{create_table "schema_migrations"}, output - assert_no_match %r{create_table "internal_metadatas"}, output + assert_no_match %r{create_table "active_record_internal_metadatas"}, output end def test_schema_dump_uses_force_cascade_on_create_table @@ -159,7 +159,7 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "accounts"}, output assert_match %r{create_table "authors"}, output assert_no_match %r{create_table "schema_migrations"}, output - assert_no_match %r{create_table "internal_metadatas"}, output + assert_no_match %r{create_table "active_record_internal_metadatas"}, output end def test_schema_dump_with_regexp_ignored_table @@ -167,7 +167,7 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "accounts"}, output assert_match %r{create_table "authors"}, output assert_no_match %r{create_table "schema_migrations"}, output - assert_no_match %r{create_table "internal_metadatas"}, output + assert_no_match %r{create_table "active_record_internal_metadatas"}, output end def test_schema_dumps_index_columns_in_right_order @@ -345,7 +345,7 @@ class SchemaDumperTest < ActiveRecord::TestCase assert_no_match %r{create_table "foo_.+_bar"}, output assert_no_match %r{add_index "foo_.+_bar"}, output assert_no_match %r{create_table "schema_migrations"}, output - assert_no_match %r{create_table "internal_metadatas"}, output + assert_no_match %r{create_table "active_record_internal_metadatas"}, output if ActiveRecord::Base.connection.supports_foreign_keys? assert_no_match %r{add_foreign_key "foo_.+_bar"}, output |