From 8d04d7c6b9e551257866858b7f29e9f3cb444896 Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Tue, 29 Oct 2024 19:07:18 -0400 Subject: [PATCH 1/4] Prevent warnings if a generator tries to run [DEPRECATED] This Gemfile does not include an explicit global source. Not using an explicit global source may result in a different lockfile being generated depending on the gems you have installed locally before bundler is run. Instead, define a global source in your Gemfile like this: source "https://rubygems.org". --- test/generators/suspenders/install/web_generator_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/generators/suspenders/install/web_generator_test.rb b/test/generators/suspenders/install/web_generator_test.rb index b2740732..8e9ff1b0 100644 --- a/test/generators/suspenders/install/web_generator_test.rb +++ b/test/generators/suspenders/install/web_generator_test.rb @@ -52,6 +52,10 @@ class WebGeneratorTest < Rails::Generators::TestCase def prepare_destination touch "Gemfile" + + File.open("test/dummy/Gemfile", "w") do |f| + f.write('source "https://rubygems.org"') + end end def restore_destination From a424bd70c2f45ae8a93daa213c59c24bda52559a Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Tue, 29 Oct 2024 19:33:40 -0400 Subject: [PATCH 2/4] Simplify node_not_installed logic --- lib/install/web.rb | 2 +- lib/suspenders/generators.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/install/web.rb b/lib/install/web.rb index b071c4d7..8f89ccd6 100644 --- a/lib/install/web.rb +++ b/lib/install/web.rb @@ -3,7 +3,7 @@ def node_version end def node_not_installed? - !node_version.present? + node_version.blank? end def node_version_unsupported? diff --git a/lib/suspenders/generators.rb b/lib/suspenders/generators.rb index 9d342604..78cf37c2 100644 --- a/lib/suspenders/generators.rb +++ b/lib/suspenders/generators.rb @@ -24,7 +24,7 @@ def node_version end def node_not_installed? - !node_version.present? + node_version.blank? end def node_version_unsupported? From a9d68788c4cd07e3bcefaef89b69a69a08df1410 Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Tue, 29 Oct 2024 19:34:34 -0400 Subject: [PATCH 3/4] User Gem:::Version for Node version comparisons Simplify writing of source to Gemfile --- lib/install/web.rb | 10 ++++++-- lib/suspenders/generators.rb | 10 ++++++-- .../suspenders/install/web_generator_test.rb | 24 ++++++++++++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/install/web.rb b/lib/install/web.rb index 8f89ccd6..b68567a1 100644 --- a/lib/install/web.rb +++ b/lib/install/web.rb @@ -1,5 +1,9 @@ def node_version - ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] + version = ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] + + return if version.blank? + + Gem::Version.new(version) end def node_not_installed? @@ -7,7 +11,9 @@ def node_not_installed? end def node_version_unsupported? - node_version < "20.0.0" + minimum_node_version = Gem::Version.new("20.0.0") + + node_version < minimum_node_version end def apply_template! diff --git a/lib/suspenders/generators.rb b/lib/suspenders/generators.rb index 78cf37c2..d0c085d4 100644 --- a/lib/suspenders/generators.rb +++ b/lib/suspenders/generators.rb @@ -20,7 +20,11 @@ def rspec_test_helper_present? end def node_version - ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] + version = ENV["NODE_VERSION"] || `node --version`[/\d+\.\d+\.\d+/] + + return if version.blank? + + Gem::Version.new(version) end def node_not_installed? @@ -28,7 +32,9 @@ def node_not_installed? end def node_version_unsupported? - node_version < Suspenders::MINIMUM_NODE_VERSION + minimum_node_version = Gem::Version.new(Suspenders::MINIMUM_NODE_VERSION) + + node_version < minimum_node_version end end diff --git a/test/generators/suspenders/install/web_generator_test.rb b/test/generators/suspenders/install/web_generator_test.rb index 8e9ff1b0..fcf719aa 100644 --- a/test/generators/suspenders/install/web_generator_test.rb +++ b/test/generators/suspenders/install/web_generator_test.rb @@ -48,14 +48,32 @@ class WebGeneratorTest < Rails::Generators::TestCase end end + test "evaluates support for Node versions correctly" do + web_generator = Generators::Install::WebGenerator.new + + unsupported_versions = %w[1.0.0 1.100.200 10.0.0 19.0.0 19.9.9 19.9999.99999] + + unsupported_versions.each do |unsupported_version| + Generators::Install::WebGenerator.any_instance.stubs(:node_version).returns(unsupported_version) + + assert_predicate web_generator, :node_version_unsupported?, "Node version #{unsupported_version} should not be supported" + end + + supported_versions = %w[20.0.0 20.1.0 20.100.200 50.0.0 100.0.0] + + supported_versions.each do |supported_version| + Generators::Install::WebGenerator.any_instance.stubs(:node_version).returns(supported_version) + + assert_not_predicate web_generator, :node_version_unsupported?, "Node version #{supported_version} should be supported" + end + end + private def prepare_destination touch "Gemfile" - File.open("test/dummy/Gemfile", "w") do |f| - f.write('source "https://rubygems.org"') - end + File.write("test/dummy/Gemfile", 'source "https://rubygems.org"') end def restore_destination From 579a24d369d81857075d1343233e3de2d1707670 Mon Sep 17 00:00:00 2001 From: Louis Antonopoulos Date: Tue, 29 Oct 2024 19:39:55 -0400 Subject: [PATCH 4/4] Update test description --- test/generators/suspenders/install/web_generator_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/generators/suspenders/install/web_generator_test.rb b/test/generators/suspenders/install/web_generator_test.rb index fcf719aa..fac8f2cb 100644 --- a/test/generators/suspenders/install/web_generator_test.rb +++ b/test/generators/suspenders/install/web_generator_test.rb @@ -48,7 +48,7 @@ class WebGeneratorTest < Rails::Generators::TestCase end end - test "evaluates support for Node versions correctly" do + test "evaluates supported Node versions correctly" do web_generator = Generators::Install::WebGenerator.new unsupported_versions = %w[1.0.0 1.100.200 10.0.0 19.0.0 19.9.9 19.9999.99999]