Merge pull request #30773 from y-yagi/fix_30765

Make automatically synchronize test schema work inside engine
This commit is contained in:
Eileen M. Uchitelle 2017-11-12 19:18:49 -05:00 committed by GitHub
commit a45f234b02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

@ -581,7 +581,8 @@ def check_pending!(connection = Base.connection)
def load_schema_if_pending!
if ActiveRecord::Migrator.needs_migration? || !ActiveRecord::Migrator.any_migrations?
# Roundtrip to Rake to allow plugins to hook into database initialization.
FileUtils.cd Rails.root do
root = defined?(ENGINE_ROOT) ? ENGINE_ROOT : Rails.root
FileUtils.cd(root) do
current_config = Base.connection_config
Base.clear_all_connections!
system("bin/rails db:test:prepare")

@ -70,6 +70,9 @@ namespace :db do
desc "Retrieves the current schema version number"
app_task "version"
# desc 'Load the test schema'
app_task "test:prepare"
end
def find_engine_path(path)

@ -0,0 +1,31 @@
# frozen_string_literal: true
require "abstract_unit"
class Rails::Engine::TestTest < ActiveSupport::TestCase
setup do
@destination_root = Dir.mktmpdir("bukkits")
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --mountable` }
end
teardown do
FileUtils.rm_rf(@destination_root)
end
test "automatically synchronize test schema" do
Dir.chdir(plugin_path) do
# In order to confirm that migration files are loaded, generate multiple migration files.
`bin/rails generate model user name:string;
bin/rails generate model todo name:string;
RAILS_ENV=development bin/rails db:migrate`
output = `bin/rails test test/models/bukkits/user_test.rb`
assert_includes(output, "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips")
end
end
private
def plugin_path
"#{@destination_root}/bukkits"
end
end