aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-01-08 11:53:25 -0600
committerschneems <richard.schneeman@gmail.com>2016-01-08 14:05:20 -0600
commitd70c68d76abcbc24ef0e56b7a7b580d0013255dd (patch)
tree4c3eef7f058ae7ea341814e8869f808b7a7ef67c
parentf6628adc11e2e57db75030fca9bae035be5cd95b (diff)
downloadrails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.tar.gz
rails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.tar.bz2
rails-d70c68d76abcbc24ef0e56b7a7b580d0013255dd.zip
Fixing tests and re-locating error checking.
-rw-r--r--activerecord/lib/active_record/migration.rb15
-rw-r--r--activerecord/lib/active_record/tasks/database_tasks.rb4
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb8
-rw-r--r--railties/test/application/bin_setup_test.rb2
-rw-r--r--railties/test/application/rake/dbs_test.rb4
5 files changed, 17 insertions, 16 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
diff --git a/railties/test/application/bin_setup_test.rb b/railties/test/application/bin_setup_test.rb
index c96bbe4c70..d279f198f2 100644
--- a/railties/test/application/bin_setup_test.rb
+++ b/railties/test/application/bin_setup_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
assert_not File.exist?("tmp/restart.txt")
`bin/setup 2>&1`
assert_equal 0, File.size("log/my.log")
- assert_equal '["articles", "schema_migrations", "internal_metadatas"]', list_tables.call
+ assert_equal '["articles", "schema_migrations", "active_record_internal_metadatas"]', list_tables.call
assert File.exist?("tmp/restart.txt")
end
end
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index 47ab65e57b..1304e73378 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -222,14 +222,14 @@ module ApplicationTests
assert_equal '["posts"]', list_tables[]
`bin/rake db:schema:load`
- assert_equal '["posts", "comments", "schema_migrations", "internal_metadatas"]', list_tables[]
+ assert_equal '["posts", "comments", "schema_migrations", "active_record_internal_metadatas"]', list_tables[]
app_file 'db/structure.sql', <<-SQL
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255));
SQL
`bin/rake db:structure:load`
- assert_equal '["posts", "comments", "schema_migrations", "internal_metadatas", "users"]', list_tables[]
+ assert_equal '["posts", "comments", "schema_migrations", "active_record_internal_metadatas", "users"]', list_tables[]
end
end