1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/engine/test_test.rb
yuuji.yaginuma 87598c8c80 Make automatically synchronize test schema work inside engine
In Rails engine, migration files are in under `db/migrate` of engine.
Therefore, when rake task is executed in engine, `db/migrate` is
automatically added to `DatabaseTasks.migrations_paths`.
a18cf23a9c/activerecord/lib/active_record/railtie.rb (L39..L43)

However, if execute the rake task under dummy app, migration files will not
be loaded because engine's migration path setting process is not called.

Therefore, in order to load migration files correctly, it is necessary to
execute rake task under engine.

Fixes #30765
2017-10-02 15:50:58 +09:00

31 lines
898 B
Ruby

# 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