mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixing tests and re-locating error checking.
This commit is contained in:
parent
f6628adc11
commit
d70c68d76a
5 changed files with 17 additions and 16 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue