Merge pull request #47242 from skipkayhil/hm-rm-extra-engine-require
Remove unneeded require in plugin application.rb
This commit is contained in:
commit
c88ca3b720
@ -124,10 +124,6 @@ def generate_test_dummy(force = false)
|
||||
def test_dummy_config
|
||||
template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
|
||||
|
||||
insert_into_file "#{dummy_path}/config/application.rb", <<~RUBY, after: /^Bundler\.require.+\n/
|
||||
require #{namespaced_name.inspect}
|
||||
RUBY
|
||||
|
||||
if mountable?
|
||||
template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
|
||||
end
|
||||
|
@ -2,13 +2,15 @@
|
||||
|
||||
require "abstract_unit"
|
||||
require "console_helpers"
|
||||
require "plugin_helpers"
|
||||
|
||||
class Rails::Engine::CommandsTest < ActiveSupport::TestCase
|
||||
include ConsoleHelpers
|
||||
include PluginHelpers
|
||||
|
||||
def setup
|
||||
@destination_root = Dir.mktmpdir("bukkits")
|
||||
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --mountable` }
|
||||
generate_plugin("#{@destination_root}/bukkits", "--mountable")
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ -17,14 +19,14 @@ def teardown
|
||||
|
||||
def test_help_command_work_inside_engine
|
||||
output = capture(:stderr) do
|
||||
Dir.chdir(plugin_path) { `bin/rails --help` }
|
||||
in_plugin_context(plugin_path) { `bin/rails --help` }
|
||||
end
|
||||
assert_no_match "NameError", output
|
||||
end
|
||||
|
||||
def test_runner_command_work_inside_engine
|
||||
output = capture(:stdout) do
|
||||
Dir.chdir(plugin_path) { system("bin/rails runner 'puts Rails.env'") }
|
||||
in_plugin_context(plugin_path) { system({ "RAILS_ENV" => "test" }, "bin/rails runner 'puts Rails.env'") }
|
||||
end
|
||||
|
||||
assert_equal "test", output.strip
|
||||
@ -63,10 +65,9 @@ def plugin_path
|
||||
end
|
||||
|
||||
def spawn_command(command, fd)
|
||||
Process.spawn(
|
||||
"#{plugin_path}/bin/rails #{command}",
|
||||
in: fd, out: fd, err: fd
|
||||
)
|
||||
in_plugin_context(plugin_path) do
|
||||
Process.spawn("bin/rails #{command}", in: fd, out: fd, err: fd)
|
||||
end
|
||||
end
|
||||
|
||||
def kill(pid)
|
||||
|
@ -1,11 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "abstract_unit"
|
||||
require "plugin_helpers"
|
||||
|
||||
class Rails::Engine::TestTest < ActiveSupport::TestCase
|
||||
include PluginHelpers
|
||||
|
||||
setup do
|
||||
@destination_root = Dir.mktmpdir("bukkits")
|
||||
Dir.chdir(@destination_root) { `bundle exec rails plugin new bukkits --mountable` }
|
||||
generate_plugin("#{@destination_root}/bukkits", "--mountable")
|
||||
end
|
||||
|
||||
teardown do
|
||||
@ -13,7 +16,7 @@ class Rails::Engine::TestTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "automatically synchronize test schema" do
|
||||
Dir.chdir(plugin_path) do
|
||||
in_plugin_context(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;
|
||||
|
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "plugin_helpers"
|
||||
require "generators/generators_test_helper"
|
||||
require "rails/generators/rails/plugin/plugin_generator"
|
||||
require "generators/shared_generator_tests"
|
||||
@ -22,6 +23,7 @@
|
||||
)
|
||||
|
||||
class PluginGeneratorTest < Rails::Generators::TestCase
|
||||
include PluginHelpers
|
||||
include GeneratorsTestHelper
|
||||
destination File.join(destination_root, "bukkits")
|
||||
arguments [destination_root]
|
||||
@ -282,10 +284,13 @@ def test_template_from_dir_pwd
|
||||
|
||||
def test_ensure_that_migration_tasks_work_with_mountable_option
|
||||
run_generator [destination_root, "--mountable"]
|
||||
FileUtils.cd destination_root
|
||||
quietly { system "bundle install" }
|
||||
output = `bin/rails db:migrate 2>&1`
|
||||
assert $?.success?, "Command failed: #{output}"
|
||||
prepare_plugin(destination_root)
|
||||
|
||||
in_plugin_context(destination_root) do
|
||||
quietly { system "bundle install" }
|
||||
output = `bin/rails db:migrate 2>&1`
|
||||
assert $?.success?, "Command failed: #{output}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_creating_engine_in_full_mode
|
||||
@ -554,10 +559,14 @@ def test_creating_dummy_without_tests_but_with_dummy_path
|
||||
end
|
||||
end
|
||||
|
||||
def test_dummy_application_loads_plugin
|
||||
def test_plugin_passes_generated_test
|
||||
run_generator
|
||||
prepare_plugin(destination_root)
|
||||
|
||||
assert_file "test/dummy/config/application.rb", /^require "bukkits"/
|
||||
in_plugin_context(destination_root) do
|
||||
output = `bin/test 2>&1`
|
||||
assert $?.success?, "Command failed: #{output}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_dummy_application_sets_include_all_helpers_to_false_for_mountable
|
||||
|
@ -1,5 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "plugin_helpers"
|
||||
require "generators/generators_test_helper"
|
||||
require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
|
||||
|
||||
@ -9,6 +10,7 @@ module Generators
|
||||
end
|
||||
|
||||
class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
|
||||
include PluginHelpers
|
||||
include GeneratorsTestHelper
|
||||
arguments %w(User name:string age:integer)
|
||||
|
||||
@ -270,11 +272,9 @@ def test_model_name_option
|
||||
end
|
||||
|
||||
def test_controller_tests_pass_by_default_inside_mountable_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--mountable") do
|
||||
quietly { `bin/rails g controller dashboard foo` }
|
||||
quietly { `bin/rails db:migrate RAILS_ENV=test` }
|
||||
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
|
||||
@ -282,11 +282,9 @@ def test_controller_tests_pass_by_default_inside_mountable_engine
|
||||
end
|
||||
|
||||
def test_controller_tests_pass_by_default_inside_full_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--full") do
|
||||
quietly { `bin/rails g controller dashboard foo` }
|
||||
quietly { `bin/rails db:migrate RAILS_ENV=test` }
|
||||
assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bin/rails test 2>&1`)
|
||||
|
@ -1,9 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "plugin_helpers"
|
||||
require "generators/generators_test_helper"
|
||||
require "rails/generators/rails/scaffold/scaffold_generator"
|
||||
|
||||
class ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||
include PluginHelpers
|
||||
include GeneratorsTestHelper
|
||||
arguments %w(product_line title:string approved:boolean product:belongs_to user:references)
|
||||
|
||||
@ -565,11 +567,9 @@ def test_scaffold_generator_password_digest
|
||||
end
|
||||
|
||||
def test_scaffold_tests_pass_by_default_inside_mountable_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--mountable") do
|
||||
quietly do
|
||||
`bin/rails g scaffold User name:string age:integer;
|
||||
bin/rails db:migrate`
|
||||
@ -579,11 +579,9 @@ def test_scaffold_tests_pass_by_default_inside_mountable_engine
|
||||
end
|
||||
|
||||
def test_scaffold_tests_pass_by_default_inside_namespaced_mountable_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits-admin --mountable` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits-admin")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--mountable") do
|
||||
quietly do
|
||||
`bin/rails g scaffold User name:string age:integer;
|
||||
bin/rails db:migrate`
|
||||
@ -599,11 +597,9 @@ def test_scaffold_tests_pass_by_default_inside_namespaced_mountable_engine
|
||||
end
|
||||
|
||||
def test_scaffold_tests_pass_by_default_inside_full_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--full") do
|
||||
quietly do
|
||||
`bin/rails g scaffold User name:string age:integer;
|
||||
bin/rails db:migrate`
|
||||
@ -613,11 +609,9 @@ def test_scaffold_tests_pass_by_default_inside_full_engine
|
||||
end
|
||||
|
||||
def test_scaffold_tests_pass_by_default_inside_api_mountable_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --mountable --api` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--mountable", "--api") do
|
||||
quietly do
|
||||
`bin/rails g scaffold User name:string age:integer;
|
||||
bin/rails db:migrate`
|
||||
@ -627,11 +621,9 @@ def test_scaffold_tests_pass_by_default_inside_api_mountable_engine
|
||||
end
|
||||
|
||||
def test_scaffold_tests_pass_by_default_inside_api_full_engine
|
||||
Dir.chdir(destination_root) { `bundle exec rails plugin new bukkits --full --api` }
|
||||
|
||||
engine_path = File.join(destination_root, "bukkits")
|
||||
|
||||
Dir.chdir(engine_path) do
|
||||
with_new_plugin(engine_path, "--full", "--api") do
|
||||
quietly do
|
||||
`bin/rails g scaffold User name:string age:integer;
|
||||
bin/rails db:migrate`
|
||||
|
36
railties/test/plugin_helpers.rb
Normal file
36
railties/test/plugin_helpers.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PluginHelpers
|
||||
def generate_plugin(plugin_path, *args)
|
||||
system(*%w[bundle exec rails plugin new], plugin_path, *args, out: File::NULL, exception: true)
|
||||
prepare_plugin(plugin_path)
|
||||
end
|
||||
|
||||
def prepare_plugin(plugin_path)
|
||||
# Fill placeholders in gemspec to prevent Gem::InvalidSpecificationException
|
||||
# from being raised. (Some fields require a valid URL, so use one for all.)
|
||||
gemspec_path = "#{plugin_path}/#{File.basename(plugin_path)}.gemspec"
|
||||
gemspec = File.read(gemspec_path).gsub(/"TODO.*"/, "http://example.com".inspect)
|
||||
File.write(gemspec_path, gemspec)
|
||||
|
||||
# Resolve `rails` gem to this repo so that Bundler doesn't search for a
|
||||
# version of Rails that hasn't been released yet.
|
||||
gemfile_path = "#{plugin_path}/Gemfile"
|
||||
gemfile = <<~RUBY
|
||||
#{File.read(gemfile_path).sub(/gem "rails".*/, "")}
|
||||
gem "rails", path: #{File.expand_path("../..", __dir__).inspect}
|
||||
RUBY
|
||||
File.write(gemfile_path, gemfile)
|
||||
end
|
||||
|
||||
def in_plugin_context(plugin_path, &block)
|
||||
# Run with `Bundler.with_unbundled_env` so that Bundler uses the plugin's
|
||||
# Gemfile instead of this repo's Gemfile.
|
||||
Dir.chdir(plugin_path) { Bundler.with_unbundled_env(&block) }
|
||||
end
|
||||
|
||||
def with_new_plugin(plugin_path, *args, &block)
|
||||
generate_plugin(plugin_path, *args)
|
||||
in_plugin_context(plugin_path, &block)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user