diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/assets_test.rb | 20 | ||||
-rw-r--r-- | railties/test/application/middleware_test.rb | 15 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 3 | ||||
-rw-r--r-- | railties/test/engine/commands_test.rb | 3 | ||||
-rw-r--r-- | railties/test/generators/api_app_generator_test.rb | 1 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 71 | ||||
-rw-r--r-- | railties/test/generators/assets_generator_test.rb | 4 | ||||
-rw-r--r-- | railties/test/generators/channel_generator_test.rb | 21 | ||||
-rw-r--r-- | railties/test/generators/controller_generator_test.rb | 3 | ||||
-rw-r--r-- | railties/test/generators/plugin_generator_test.rb | 47 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 19 | ||||
-rw-r--r-- | railties/test/generators/shared_generator_tests.rb | 23 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 19 |
13 files changed, 86 insertions, 163 deletions
diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 4ca6d02b85..46ee0d670e 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -68,20 +68,6 @@ module ApplicationTests assert_equal 'a = "/assets/rails.png";', last_response.body.strip end - test "assets do not require compressors until it is used" do - app_file "app/assets/javascripts/demo.js.erb", "<%= :alert %>();" - add_to_env_config "production", "config.assets.compile = true" - add_to_env_config "production", "config.assets.precompile = []" - - # Load app env - app "production" - - assert_not defined?(Uglifier) - get "/assets/demo.js" - assert_match "alert()", last_response.body - assert defined?(Uglifier) - end - test "precompile creates the file, gives it the original asset's content and run in production as default" do app_file "app/assets/config/manifest.js", "//= link_tree ../javascripts" app_file "app/assets/javascripts/application.js", "alert();" @@ -443,13 +429,13 @@ module ApplicationTests end test "digested assets are not mistakenly removed" do - app_file "app/assets/application.js", "alert();" + app_file "app/assets/application.css", "div { font-weight: bold }" add_to_config "config.assets.compile = true" precompile! - files = Dir["#{app_path}/public/assets/application-*.js"] - assert_equal 1, files.length, "Expected digested application.js asset to be generated, but none found" + files = Dir["#{app_path}/public/assets/application-*.css"] + assert_equal 1, files.length, "Expected digested application.css asset to be generated, but none found" end test "digested assets are removed from configured path" do diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 5efaf841d4..631f5bac7f 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -25,6 +25,7 @@ module ApplicationTests boot! assert_equal [ + "Webpacker::DevServerProxy", "Rack::Sendfile", "ActionDispatch::Static", "ActionDispatch::Executor", @@ -56,6 +57,7 @@ module ApplicationTests boot! assert_equal [ + "Webpacker::DevServerProxy", "Rack::Sendfile", "ActionDispatch::Static", "ActionDispatch::Executor", @@ -138,7 +140,7 @@ module ApplicationTests add_to_config "config.ssl_options = { redirect: { host: 'example.com' } }" boot! - assert_equal [{ redirect: { host: "example.com" } }], Rails.application.middleware.first.args + assert_equal [{ redirect: { host: "example.com" } }], Rails.application.middleware[1].args end test "removing Active Record omits its middleware" do @@ -222,30 +224,31 @@ module ApplicationTests test "insert middleware after" do add_to_config "config.middleware.insert_after Rack::Sendfile, Rack::Config" boot! - assert_equal "Rack::Config", middleware.second + assert_equal "Rack::Config", middleware.third end test "unshift middleware" do add_to_config "config.middleware.unshift Rack::Config" boot! - assert_equal "Rack::Config", middleware.first + assert_equal "Rack::Config", middleware.second end test "Rails.cache does not respond to middleware" do add_to_config "config.cache_store = :memory_store" boot! - assert_equal "Rack::Runtime", middleware.fourth + assert_equal "Rack::Runtime", middleware.fifth end test "Rails.cache does respond to middleware" do boot! - assert_equal "Rack::Runtime", middleware.fifth + assert_equal "ActiveSupport::Cache::Strategy::LocalCache", middleware.fifth + assert_equal "Rack::Runtime", middleware[5] end test "insert middleware before" do add_to_config "config.middleware.insert_before Rack::Sendfile, Rack::Config" boot! - assert_equal "Rack::Config", middleware.first + assert_equal "Rack::Config", middleware.second end test "can't change middleware after it's built" do diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 1522a2bbc5..a0cdae898b 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -118,7 +118,7 @@ module ApplicationTests end def test_code_statistics_sanity - assert_match "Code LOC: 25 Test LOC: 0 Code to Test Ratio: 1:0.0", + assert_match "Code LOC: 32 Test LOC: 0 Code to Test Ratio: 1:0.0", rails("stats") end @@ -190,6 +190,7 @@ module ApplicationTests rails "generate", "model", "Cart" rails "generate", "scaffold", "LineItems", "product:references", "cart:belongs_to" with_rails_env("test") { rails("db:migrate") } + rails("webpacker:compile") output = rails("test") assert_match(/7 runs, 9 assertions, 0 failures, 0 errors/, output) diff --git a/railties/test/engine/commands_test.rb b/railties/test/engine/commands_test.rb index 48c93af80c..0e5167578d 100644 --- a/railties/test/engine/commands_test.rb +++ b/railties/test/engine/commands_test.rb @@ -24,7 +24,7 @@ class Rails::Engine::CommandsTest < ActiveSupport::TestCase def test_runner_command_work_inside_engine output = capture(:stdout) do - Dir.chdir(plugin_path) { system("bin/rails runner 'puts Rails.env'") } + Dir.chdir(plugin_path) { system({ "SKIP_REQUIRE_WEBPACKER" => "true" }, "bin/rails runner 'puts Rails.env'") } end assert_equal "test", output.strip @@ -67,6 +67,7 @@ class Rails::Engine::CommandsTest < ActiveSupport::TestCase def spawn_command(command, fd) Process.spawn( + { "SKIP_REQUIRE_WEBPACKER" => "true" }, "#{plugin_path}/bin/rails #{command}", in: fd, out: fd, err: fd ) diff --git a/railties/test/generators/api_app_generator_test.rb b/railties/test/generators/api_app_generator_test.rb index c2540f4091..4f2894e71e 100644 --- a/railties/test/generators/api_app_generator_test.rb +++ b/railties/test/generators/api_app_generator_test.rb @@ -40,7 +40,6 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase end assert_file "Gemfile" do |content| - assert_no_match(/gem 'coffee-rails'/, content) assert_no_match(/gem 'sass-rails'/, content) assert_no_match(/gem 'web-console'/, content) assert_no_match(/gem 'capybara'/, content) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1169633244..48e8b7123f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -13,10 +13,9 @@ DEFAULT_APP_FILES = %w( config.ru app/assets/config/manifest.js app/assets/images - app/assets/javascripts - app/assets/javascripts/application.js - app/assets/javascripts/cable.js - app/assets/javascripts/channels + app/javascript + app/javascript/channels + app/javascript/packs/application.js app/assets/stylesheets app/assets/stylesheets/application.css app/channels/application_cable/channel.rb @@ -114,12 +113,12 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_assets - run_generator + run_generator [destination_root, "--no-skip-javascript"] assert_file("app/views/layouts/application.html.erb", /stylesheet_link_tag\s+'application', media: 'all', 'data-turbolinks-track': 'reload'/) - assert_file("app/views/layouts/application.html.erb", /javascript_include_tag\s+'application', 'data-turbolinks-track': 'reload'/) + assert_file("app/views/layouts/application.html.erb", /javascript_pack_tag\s+'application', 'data-turbolinks-track': 'reload'/) assert_file("app/assets/stylesheets/application.css") - assert_file("app/assets/javascripts/application.js") + assert_file("app/javascript/packs/application.js") end def test_application_job_file_present @@ -215,7 +214,8 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_new_application_load_defaults app_root = File.join(destination_root, "myfirstapp") - run_generator [app_root] + run_generator [app_root, "--no-skip-javascript"] + output = nil assert_file "#{app_root}/config/application.rb", /\s+config\.load_defaults #{Rails::VERSION::STRING.to_f}/ @@ -559,7 +559,6 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator assert_gem "sass-rails" - assert_gem "uglifier" end def test_action_cable_redis_gems @@ -601,24 +600,6 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_inclusion_of_javascript_runtime - run_generator - if defined?(JRUBY_VERSION) - assert_gem "therubyrhino" - elsif RUBY_PLATFORM =~ /mingw|mswin/ - assert_gem "duktape" - else - assert_file "Gemfile", /# gem 'mini_racer', platforms: :ruby/ - end - end - - def test_rails_ujs_is_the_default_ujs_library - run_generator - assert_file "app/assets/javascripts/application.js" do |contents| - assert_match %r{^//= require rails-ujs}, contents - end - end - def test_javascript_is_skipped_if_required run_generator [destination_root, "--skip-javascript"] @@ -628,22 +609,6 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/stylesheet_link_tag\s+'application', media: 'all' %>/, contents) assert_no_match(/javascript_include_tag\s+'application' \%>/, contents) end - - assert_no_gem "coffee-rails" - assert_no_gem "uglifier" - - assert_file "config/environments/production.rb" do |content| - assert_no_match(/config\.assets\.js_compressor = :uglifier/, content) - end - end - - def test_coffeescript_is_skipped_if_required - run_generator [destination_root, "--skip-coffee"] - - assert_file "Gemfile" do |content| - assert_no_match(/coffee-rails/, content) - assert_match(/uglifier/, content) - end end def test_inclusion_of_jbuilder @@ -819,22 +784,22 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_gem "spring" end - def test_webpack_option + def test_skip_javascript_option command_check = -> command, *_ do @called ||= 0 if command == "webpacker:install" @called += 1 - assert_equal 1, @called, "webpacker:install expected to be called once, but was called #{@called} times." + assert_equal 0, @called, "webpacker:install expected not to be called once, but was called #{@called} times." end end - generator([destination_root], webpack: "webpack").stub(:rails_command, command_check) do + generator([destination_root], skip_javascript: true).stub(:rails_command, command_check) do generator.stub :bundle_command, nil do quietly { generator.invoke_all } end end - assert_gem "webpacker" + assert_no_gem "webpacker" end def test_webpack_option_with_js_framework @@ -856,22 +821,24 @@ class AppGeneratorTest < Rails::Generators::TestCase quietly { generator.invoke_all } end end + + assert_gem "webpacker" end def test_generator_if_skip_turbolinks_is_given - run_generator [destination_root, "--skip-turbolinks"] + run_generator [destination_root, "--skip-turbolinks", "--no-skip-javascript"] assert_no_gem "turbolinks" assert_file "app/views/layouts/application.html.erb" do |content| assert_no_match(/data-turbolinks-track/, content) end - assert_file "app/assets/javascripts/application.js" do |content| + assert_file "app/javascript/packs/application.js" do |content| assert_no_match(/turbolinks/, content) end end def test_bootsnap - run_generator + run_generator [destination_root, "--no-skip-bootsnap"] unless defined?(JRUBY_VERSION) assert_gem "bootsnap" @@ -972,7 +939,7 @@ class AppGeneratorTest < Rails::Generators::TestCase template end - sequence = ["git init", "install", "binstubs bundler", "exec spring binstub --all", "echo ran after_bundle"] + sequence = ["git init", "install", "binstubs bundler", "exec spring binstub --all", "webpacker:install", "echo ran after_bundle"] @sequence_step ||= 0 ensure_bundler_first = -> command, options = nil do assert_equal sequence[@sequence_step], command, "commands should be called in sequence #{sequence}" @@ -989,7 +956,7 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - assert_equal 5, @sequence_step + assert_equal 6, @sequence_step end def test_gitignore diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb index 3cec41dbf8..83d2429acf 100644 --- a/railties/test/generators/assets_generator_test.rb +++ b/railties/test/generators/assets_generator_test.rb @@ -9,13 +9,11 @@ class AssetsGeneratorTest < Rails::Generators::TestCase def test_assets run_generator - assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" end def test_skipping_assets - run_generator ["posts", "--no-stylesheets", "--no-javascripts"] - assert_no_file "app/assets/javascripts/posts.js" + run_generator ["posts", "--no-stylesheets"] assert_no_file "app/assets/stylesheets/posts.css" end end diff --git a/railties/test/generators/channel_generator_test.rb b/railties/test/generators/channel_generator_test.rb index e543cc11b8..265d7c9618 100644 --- a/railties/test/generators/channel_generator_test.rb +++ b/railties/test/generators/channel_generator_test.rb @@ -26,8 +26,8 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) end - assert_file "app/assets/javascripts/channels/chat.js" do |channel| - assert_match(/App\.chat = App\.cable\.subscriptions\.create\("ChatChannel/, channel) + assert_file "app/javascript/channels/chat_channel.js" do |channel| + assert_match(/import consumer from "\.\/consumer"\s+consumer\.subscriptions\.create\("ChatChannel/, channel) end end @@ -40,8 +40,8 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_match(/def mute/, channel) end - assert_file "app/assets/javascripts/channels/chat.js" do |channel| - assert_match(/App\.chat = App\.cable\.subscriptions\.create\("ChatChannel/, channel) + assert_file "app/javascript/channels/chat_channel.js" do |channel| + assert_match(/import consumer from "\.\/consumer"\s+consumer\.subscriptions\.create\("ChatChannel/, channel) assert_match(/,\n\n speak/, channel) assert_match(/,\n\n mute: function\(\) \{\n return this\.perform\('mute'\);\n \}\n\}\);/, channel) end @@ -54,15 +54,17 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_match(/class ChatChannel < ApplicationCable::Channel/, channel) end - assert_no_file "app/assets/javascripts/channels/chat.js" + assert_no_file "app/javascript/channels/chat_channel.js" end def test_cable_js_is_created_if_not_present_already run_generator ["chat"] - FileUtils.rm("#{destination_root}/app/assets/javascripts/cable.js") + FileUtils.rm("#{destination_root}/app/javascript/channels/index.js") + FileUtils.rm("#{destination_root}/app/javascript/channels/consumer.js") run_generator ["camp"] - assert_file "app/assets/javascripts/cable.js" + assert_file "app/javascript/channels/index.js" + assert_file "app/javascript/channels/consumer.js" end def test_channel_on_revoke @@ -74,7 +76,8 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_file "app/channels/application_cable/channel.rb" assert_file "app/channels/application_cable/connection.rb" - assert_file "app/assets/javascripts/cable.js" + assert_file "app/javascript/channels/index.js" + assert_file "app/javascript/channels/consumer.js" end def test_channel_suffix_is_not_duplicated @@ -84,6 +87,6 @@ class ChannelGeneratorTest < Rails::Generators::TestCase assert_file "app/channels/chat_channel.rb" assert_no_file "app/assets/javascripts/channels/chat_channel.js" - assert_file "app/assets/javascripts/channels/chat.js" + assert_file "app/javascript/channels/chat_channel.js" end end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 021004c9b8..adef56255a 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -39,13 +39,11 @@ class ControllerGeneratorTest < Rails::Generators::TestCase def test_invokes_assets run_generator - assert_file "app/assets/javascripts/account.js" assert_file "app/assets/stylesheets/account.css" end def test_does_not_invoke_assets_if_required run_generator ["account", "--skip-assets"] - assert_no_file "app/assets/javascripts/account.js" assert_no_file "app/assets/stylesheets/account.css" end @@ -133,7 +131,6 @@ class ControllerGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/account_helper.rb" assert_no_file "app/assets/javascripts/account_controller.js" - assert_file "app/assets/javascripts/account.js" assert_no_file "app/assets/stylesheets/account_controller.css" assert_file "app/assets/stylesheets/account.css" diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 468a9c9e89..66286fc554 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -140,10 +140,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase run_generator assert_file "test/dummy/app/assets/stylesheets/application.css" - - assert_file "test/dummy/app/assets/javascripts/application.js" do |contents| - assert_no_match(/jquery/, contents) - end end def test_ensure_that_plugin_options_are_not_passed_to_app_generator @@ -210,28 +206,10 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_no_file "#{destination_root}/Gemfile.lock" end - def test_skipping_javascripts_without_mountable_option - run_generator - assert_no_file "app/assets/javascripts/bukkits/application.js" - end - - def test_javascripts_generation - run_generator [destination_root, "--mountable"] - assert_file "app/assets/javascripts/bukkits/application.js" do |content| - assert_match "//= require rails-ujs", content - assert_match "//= require activestorage", content - assert_match "//= require_tree .", content - end - assert_file "app/views/layouts/bukkits/application.html.erb" do |content| - assert_match "javascript_include_tag", content - end - end - - def test_skip_javascripts + def test_skip_javascript run_generator [destination_root, "--skip-javascript", "--mountable"] - assert_no_file "app/assets/javascripts/bukkits/application.js" assert_file "app/views/layouts/bukkits/application.html.erb" do |content| - assert_no_match "javascript_include_tag", content + assert_no_match "javascript_pack_tag", content end end @@ -264,7 +242,6 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_creating_engine_in_full_mode run_generator [destination_root, "--full"] - assert_file "app/assets/javascripts/bukkits" assert_file "app/assets/stylesheets/bukkits" assert_file "app/assets/images/bukkits" assert_file "app/models" @@ -280,7 +257,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_creating_engine_with_hyphenated_name_in_full_mode run_generator [File.join(destination_root, "hyphenated-name"), "--full"] - assert_file "hyphenated-name/app/assets/javascripts/hyphenated/name" + assert_no_file "hyphenated-name/app/assets/javascripts/hyphenated/name" assert_file "hyphenated-name/app/assets/stylesheets/hyphenated/name" assert_file "hyphenated-name/app/assets/images/hyphenated/name" assert_file "hyphenated-name/app/models" @@ -297,7 +274,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_creating_engine_with_hyphenated_and_underscored_name_in_full_mode run_generator [File.join(destination_root, "my_hyphenated-name"), "--full"] - assert_file "my_hyphenated-name/app/assets/javascripts/my_hyphenated/name" + assert_no_file "my_hyphenated-name/app/assets/javascripts/my_hyphenated/name" assert_file "my_hyphenated-name/app/assets/stylesheets/my_hyphenated/name" assert_file "my_hyphenated-name/app/assets/images/my_hyphenated/name" assert_file "my_hyphenated-name/app/models" @@ -318,7 +295,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_create_mountable_application_with_mountable_option run_generator [destination_root, "--mountable"] - assert_file "app/assets/javascripts/bukkits" + assert_no_file "app/assets/javascripts/bukkits" assert_file "app/assets/stylesheets/bukkits" assert_file "app/assets/images/bukkits" assert_file "config/routes.rb", /Bukkits::Engine\.routes\.draw do/ @@ -334,7 +311,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_match "<%= csrf_meta_tags %>", contents assert_match "<%= csp_meta_tag %>", contents assert_match(/stylesheet_link_tag\s+['"]bukkits\/application['"]/, contents) - assert_match(/javascript_include_tag\s+['"]bukkits\/application['"]/, contents) + assert_no_match(/javascript_include_tag\s+['"]bukkits\/application['"]/, contents) assert_match "<%= yield %>", contents end assert_file "test/test_helper.rb" do |content| @@ -348,7 +325,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase def test_create_mountable_application_with_mountable_option_and_hypenated_name run_generator [File.join(destination_root, "hyphenated-name"), "--mountable"] - assert_file "hyphenated-name/app/assets/javascripts/hyphenated/name" + assert_no_file "hyphenated-name/app/assets/javascripts/hyphenated/name" assert_file "hyphenated-name/app/assets/stylesheets/hyphenated/name" assert_file "hyphenated-name/app/assets/images/hyphenated/name" assert_file "hyphenated-name/config/routes.rb", /Hyphenated::Name::Engine\.routes\.draw do/ @@ -364,13 +341,13 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "hyphenated-name/app/views/layouts/hyphenated/name/application.html.erb" do |contents| assert_match "<title>Hyphenated name</title>", contents assert_match(/stylesheet_link_tag\s+['"]hyphenated\/name\/application['"]/, contents) - assert_match(/javascript_include_tag\s+['"]hyphenated\/name\/application['"]/, contents) + assert_no_match(/javascript_include_tag\s+['"]hyphenated\/name\/application['"]/, contents) end end def test_create_mountable_application_with_mountable_option_and_hypenated_and_underscored_name run_generator [File.join(destination_root, "my_hyphenated-name"), "--mountable"] - assert_file "my_hyphenated-name/app/assets/javascripts/my_hyphenated/name" + assert_no_file "my_hyphenated-name/app/assets/javascripts/my_hyphenated/name" assert_file "my_hyphenated-name/app/assets/stylesheets/my_hyphenated/name" assert_file "my_hyphenated-name/app/assets/images/my_hyphenated/name" assert_file "my_hyphenated-name/config/routes.rb", /MyHyphenated::Name::Engine\.routes\.draw do/ @@ -386,13 +363,13 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "my_hyphenated-name/app/views/layouts/my_hyphenated/name/application.html.erb" do |contents| assert_match "<title>My hyphenated name</title>", contents assert_match(/stylesheet_link_tag\s+['"]my_hyphenated\/name\/application['"]/, contents) - assert_match(/javascript_include_tag\s+['"]my_hyphenated\/name\/application['"]/, contents) + assert_no_match(/javascript_include_tag\s+['"]my_hyphenated\/name\/application['"]/, contents) end end def test_create_mountable_application_with_mountable_option_and_multiple_hypenates_in_name run_generator [File.join(destination_root, "deep-hyphenated-name"), "--mountable"] - assert_file "deep-hyphenated-name/app/assets/javascripts/deep/hyphenated/name" + assert_no_file "deep-hyphenated-name/app/assets/javascripts/deep/hyphenated/name" assert_file "deep-hyphenated-name/app/assets/stylesheets/deep/hyphenated/name" assert_file "deep-hyphenated-name/app/assets/images/deep/hyphenated/name" assert_file "deep-hyphenated-name/config/routes.rb", /Deep::Hyphenated::Name::Engine\.routes\.draw do/ @@ -408,7 +385,7 @@ class PluginGeneratorTest < Rails::Generators::TestCase assert_file "deep-hyphenated-name/app/views/layouts/deep/hyphenated/name/application.html.erb" do |contents| assert_match "<title>Deep hyphenated name</title>", contents assert_match(/stylesheet_link_tag\s+['"]deep\/hyphenated\/name\/application['"]/, contents) - assert_match(/javascript_include_tag\s+['"]deep\/hyphenated\/name\/application['"]/, contents) + assert_no_match(/javascript_include_tag\s+['"]deep\/hyphenated\/name\/application['"]/, contents) end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 94aab15aa9..21b5013484 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -93,7 +93,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Assets assert_file "app/assets/stylesheets/scaffold.css" - assert_file "app/assets/javascripts/product_lines.js" assert_file "app/assets/stylesheets/product_lines.css" end @@ -166,7 +165,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Assets assert_no_file "app/assets/stylesheets/scaffold.css" - assert_no_file "app/assets/javascripts/product_lines.js" assert_no_file "app/assets/stylesheets/product_lines.css" end @@ -222,7 +220,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Assets assert_file "app/assets/stylesheets/scaffold.css", /:visited/ - assert_no_file "app/assets/javascripts/product_lines.js" assert_no_file "app/assets/stylesheets/product_lines.css" end @@ -299,7 +296,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Assets assert_file "app/assets/stylesheets/scaffold.css", /:visited/ - assert_file "app/assets/javascripts/admin/roles.js" assert_file "app/assets/stylesheets/admin/roles.css" end @@ -335,7 +331,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase # Assets assert_file "app/assets/stylesheets/scaffold.css" - assert_no_file "app/assets/javascripts/admin/roles.js" assert_no_file "app/assets/stylesheets/admin/roles.css" end @@ -380,28 +375,24 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_assets_with_switch_no_assets run_generator [ "posts", "--no-assets" ] assert_no_file "app/assets/stylesheets/scaffold.css" - assert_no_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_assets_with_switch_assets_false run_generator [ "posts", "--assets=false" ] assert_no_file "app/assets/stylesheets/scaffold.css" - assert_no_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_scaffold_stylesheet_with_switch_no_scaffold_stylesheet run_generator [ "posts", "--no-scaffold-stylesheet" ] assert_no_file "app/assets/stylesheets/scaffold.css" - assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" end def test_scaffold_generator_no_scaffold_stylesheet_with_switch_scaffold_stylesheet_false run_generator [ "posts", "--scaffold-stylesheet=false" ] assert_no_file "app/assets/stylesheets/scaffold.css" - assert_file "app/assets/javascripts/posts.js" assert_file "app/assets/stylesheets/posts.css" end @@ -429,17 +420,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase def test_scaffold_generator_no_stylesheets run_generator [ "posts", "--no-stylesheets" ] assert_no_file "app/assets/stylesheets/scaffold.css" - assert_file "app/assets/javascripts/posts.js" assert_no_file "app/assets/stylesheets/posts.css" end - def test_scaffold_generator_no_javascripts - run_generator [ "posts", "--no-javascripts" ] - assert_file "app/assets/stylesheets/scaffold.css" - assert_no_file "app/assets/javascripts/posts.js" - assert_file "app/assets/stylesheets/posts.css" - end - def test_scaffold_generator_outputs_error_message_on_missing_attribute_type run_generator ["post", "title", "body:text", "author"] @@ -630,7 +613,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert File.exist?("app/helpers/bukkits/users_helper.rb") - assert File.exist?("app/assets/javascripts/bukkits/users.js") assert File.exist?("app/assets/stylesheets/bukkits/users.css") end end @@ -660,7 +642,6 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_not File.exist?("app/helpers/bukkits/users_helper.rb") - assert_not File.exist?("app/assets/javascripts/bukkits/users.js") assert_not File.exist?("app/assets/stylesheets/bukkits/users.css") end end diff --git a/railties/test/generators/shared_generator_tests.rb b/railties/test/generators/shared_generator_tests.rb index 5a1257e5c1..521f775553 100644 --- a/railties/test/generators/shared_generator_tests.rb +++ b/railties/test/generators/shared_generator_tests.rb @@ -27,7 +27,7 @@ module SharedGeneratorTests end def test_skeleton_is_created - run_generator + run_generator [destination_root, "--no-skip-javascript"] default_files.each { |path| assert_file path } end @@ -196,10 +196,12 @@ module SharedGeneratorTests end def test_generator_for_active_storage - run_generator + run_generator [destination_root, "--no-skip-javascript"] - assert_file "#{application_path}/app/assets/javascripts/application.js" do |content| - assert_match(/^\/\/= require activestorage/, content) + unless generator_class.name == "Rails::Generators::PluginGenerator" + assert_file "#{application_path}/app/javascript/packs/application.js" do |content| + assert_match(/^import \* as ActiveStorage from "activestorage"\nActiveStorage.start\(\)/, content) + end end assert_file "#{application_path}/config/environments/development.rb" do |content| @@ -224,11 +226,11 @@ module SharedGeneratorTests end def test_generator_if_skip_active_storage_is_given - run_generator [destination_root, "--skip-active-storage"] + run_generator [destination_root, "--skip-active-storage", "--no-skip-javascript"] assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/ - assert_file "#{application_path}/app/assets/javascripts/application.js" do |content| + assert_file "#{application_path}/app/javascript/packs/application.js" do |content| assert_no_match(/^\/\/= require activestorage/, content) end @@ -254,12 +256,12 @@ module SharedGeneratorTests end def test_generator_does_not_generate_active_storage_contents_if_skip_active_record_is_given - run_generator [destination_root, "--skip-active-record"] + run_generator [destination_root, "--skip-active-record", "--no-skip-javascript"] assert_file "#{application_path}/config/application.rb", /#\s+require\s+["']active_storage\/engine["']/ - assert_file "#{application_path}/app/assets/javascripts/application.js" do |content| - assert_no_match(/^\/\/= require activestorage/, content) + assert_file "#{application_path}/app/javascript/packs/application.js" do |content| + assert_no_match(/^import * as ActiveStorage from "activestorage"\nActiveStorage.start()/, content) end assert_file "#{application_path}/config/environments/development.rb" do |content| @@ -320,8 +322,6 @@ module SharedGeneratorTests assert_file "Gemfile" do |content| assert_no_match(/sass-rails/, content) - assert_no_match(/uglifier/, content) - assert_no_match(/coffee-rails/, content) end assert_file "#{application_path}/config/environments/development.rb" do |content| @@ -330,7 +330,6 @@ module SharedGeneratorTests assert_file "#{application_path}/config/environments/production.rb" do |content| assert_no_match(/config\.assets\.digest/, content) - assert_no_match(/config\.assets\.js_compressor/, content) assert_no_match(/config\.assets\.css_compressor/, content) assert_no_match(/config\.assets\.compile/, content) end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 2a8c6d8f97..e44f21380e 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -30,11 +30,11 @@ require "rails/secrets" module TestHelpers module Paths def app_template_path - File.join Dir.tmpdir, "app_template" + File.join RAILS_FRAMEWORK_ROOT, "tmp/templates/app_template" end def tmp_path(*args) - @tmp_path ||= File.realpath(Dir.mktmpdir) + @tmp_path ||= File.realpath(Dir.mktmpdir(nil, File.join(RAILS_FRAMEWORK_ROOT, "tmp"))) File.join(@tmp_path, *args) end @@ -469,17 +469,28 @@ Module.new do # Build a rails app FileUtils.rm_rf(app_template_path) - FileUtils.mkdir(app_template_path) + FileUtils.mkdir_p(app_template_path) + + Dir.chdir "#{RAILS_FRAMEWORK_ROOT}/actionview" do + `yarn build` + end `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-gemfile --skip-listen --no-rc` File.open("#{app_template_path}/config/boot.rb", "w") do |f| f.puts "require 'rails/all'" end + Dir.chdir(app_template_path) { `yarn add https://github.com/rails/webpacker.git` } # Use the latest version. + + # Manually install `webpack` as bin symlinks are not created for subdependencies + # in workspaces. See https://github.com/yarnpkg/yarn/issues/4964 + Dir.chdir(app_template_path) { `yarn add webpack@4.17.1 --tilde` } + Dir.chdir(app_template_path) { `yarn add webpack-cli` } + # Fake 'Bundler.require' -- we run using the repo's Gemfile, not an # app-specific one: we don't want to require every gem that lists. contents = File.read("#{app_template_path}/config/application.rb") - contents.sub!(/^Bundler\.require.*/, "%w(turbolinks).each { |r| require r }") + contents.sub!(/^Bundler\.require.*/, "%w(turbolinks webpacker).each { |r| require r }") File.write("#{app_template_path}/config/application.rb", contents) require "rails" |