aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-05-30 08:25:05 -0400
committereileencodes <eileencodes@gmail.com>2019-06-14 11:15:08 -0400
commit7cc27d749c3563e6b278ad01d233cb92ea3b7935 (patch)
tree5975a2c14a3b0f9d2dfc234a2a5b27f3e50354e0 /railties/test
parentc0af72bf86701e03ac97a50754beddf2b5d7943f (diff)
downloadrails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.tar.gz
rails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.tar.bz2
rails-7cc27d749c3563e6b278ad01d233cb92ea3b7935.zip
Move SchemaMigration to migration_context
This PR moves the `schema_migration` to `migration_context` so that we can access the `schema_migration` per connection. This does not change behavior of the SchemaMigration if you are using one database. This also does not change behavior of any public APIs. `Migrator` is private as is `MigrationContext` so we can change these as needed. We now need to pass a `schema_migration` to `Migrator` so that we can run migrations on the right connection outside the context of a rake task. The bugs this fixes were discovered while debugging the issues around the SchemaCache on initialization with multiple database. It was clear that `get_all_versions` wouldn't work without these changes outside the context of a rake task (because in the rake task we establish a connection and change AR::Base.connection to the db we're running on). Because the `SchemaCache` relies on the `SchemaMigration` information we need to make sure we store it per-connection rather than on ActiveRecord::Base. [Eileen M. Uchitelle & Aaron Patterson]
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/loading_test.rb7
-rw-r--r--railties/test/railties/engine_test.rb2
2 files changed, 5 insertions, 4 deletions
diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb
index c262a6435e..9ab400acfc 100644
--- a/railties/test/application/loading_test.rb
+++ b/railties/test/application/loading_test.rb
@@ -133,11 +133,12 @@ class LoadingTest < ActiveSupport::TestCase
require "#{rails_root}/config/environment"
setup_ar!
- assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort
+ initial = [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord, "primary::SchemaMigration"].collect(&:to_s).sort
+ assert_equal initial, ActiveRecord::Base.descendants.collect(&:to_s).sort
get "/load"
- assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata, ApplicationRecord, Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort
+ assert_equal [Post].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort - initial
get "/unload"
- assert_equal [ActiveStorage::Blob, ActiveStorage::Attachment, ActiveRecord::SchemaMigration, ActiveRecord::InternalMetadata].collect(&:to_s).sort, ActiveRecord::Base.descendants.collect(&:to_s).sort
+ assert_equal ["ActiveRecord::InternalMetadata", "ActiveRecord::SchemaMigration", "primary::SchemaMigration"], ActiveRecord::Base.descendants.collect(&:to_s).sort.uniq
end
test "initialize cant be called twice" do
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 8ce68dbcfa..7f05b9d9cf 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -34,7 +34,7 @@ module RailtiesTest
def migrations
migration_root = File.expand_path(ActiveRecord::Migrator.migrations_paths.first, app_path)
- ActiveRecord::MigrationContext.new(migration_root).migrations
+ ActiveRecord::MigrationContext.new(migration_root, ActiveRecord::SchemaMigration).migrations
end
test "serving sprocket's assets" do