From 5f6906796f6117b0218faf37ef6b784b4921bc0a Mon Sep 17 00:00:00 2001 From: aseroff Date: Tue, 23 Jul 2024 09:48:59 -0500 Subject: [PATCH] Fixes generator tests - cascading test failures caused when no application.js file found during install generator. Because javascript convention changes between major rails versions, generating new sample app no longer reliably places a file at app/assets/javascripts/application.js. Now the install generator will touch that location if detect_js_format falls through, though there may be a better way to do this. --- lib/generators/serviceworker/install_generator.rb | 2 ++ test/serviceworker/install_generator_test.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/generators/serviceworker/install_generator.rb b/lib/generators/serviceworker/install_generator.rb index 986983c..0d92f9a 100644 --- a/lib/generators/serviceworker/install_generator.rb +++ b/lib/generators/serviceworker/install_generator.rb @@ -60,6 +60,8 @@ def detect_js_format return [ext, "//="] end + FileUtils.touch javascripts_dir("application.js") + ['.js', "//="] end def detect_layout diff --git a/test/serviceworker/install_generator_test.rb b/test/serviceworker/install_generator_test.rb index d6ad018..3133a81 100644 --- a/test/serviceworker/install_generator_test.rb +++ b/test/serviceworker/install_generator_test.rb @@ -45,7 +45,7 @@ class ServiceWorker::InstallGeneratorTest < ::Rails::Generators::TestCase end assert_file "app/assets/javascripts/application.js" do |content| - assert_match(%r{\n//= require serviceworker-companion}, content) + assert_match(%r{//= require serviceworker-companion}, content) end end