File tree Expand file tree Collapse file tree 10 files changed +100
-11
lines changed Expand file tree Collapse file tree 10 files changed +100
-11
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ class WebGenerator < Rails::Generators::Base
5
5
include Suspenders ::Generators ::APIAppUnsupported
6
6
include Suspenders ::Generators ::DatabaseUnsupported
7
7
include Suspenders ::Generators ::NodeNotInstalled
8
+ include Suspenders ::Generators ::NodeVersionUnsupported
8
9
9
10
source_root File . expand_path ( "../../../templates/install/web" , __FILE__ )
10
11
desc <<~MARKDOWN
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ module Generators
3
3
class PrerequisitesGenerator < Rails ::Generators ::Base
4
4
include Suspenders ::Generators ::Helpers
5
5
include Suspenders ::Generators ::NodeNotInstalled
6
+ include Suspenders ::Generators ::NodeVersionUnsupported
6
7
7
8
source_root File . expand_path ( "../../templates/prerequisites" , __FILE__ )
8
9
Original file line number Diff line number Diff line change
1
+ def node_version
2
+ ENV [ "NODE_VERSION" ] || `node --version` [ /\d +\. \d +\. \d +/ ]
3
+ end
4
+
5
+ def node_not_installed?
6
+ !node_version . present?
7
+ end
8
+
9
+ def node_version_unsupported?
10
+ node_version < "20.0.0"
11
+ end
12
+
1
13
def apply_template!
14
+ if node_not_installed? || node_version_unsupported?
15
+ message = <<~ERROR
16
+
17
+
18
+ === Node version unsupported ===
19
+
20
+ Suspenders requires Node >= 20.0.0
21
+ ERROR
22
+
23
+ fail Rails ::Generators ::Error , message
24
+ end
2
25
if options [ :database ] == "postgresql" && options [ :skip_test ]
3
26
after_bundle do
4
27
gem_group :development , :test do
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ def rspec_test_helper_present?
22
22
def node_version
23
23
ENV [ "NODE_VERSION" ] || `node --version` [ /\d +\. \d +\. \d +/ ]
24
24
end
25
+
26
+ def node_not_installed?
27
+ !node_version . present?
28
+ end
29
+
30
+ def node_version_unsupported?
31
+ node_version < Suspenders ::MINIMUM_NODE_VERSION
32
+ end
25
33
end
26
34
27
35
module APIAppUnsupported
@@ -81,6 +89,9 @@ def database_unsupported?
81
89
82
90
module NodeNotInstalled
83
91
class Error < StandardError
92
+ def message
93
+ "This generator requires Node"
94
+ end
84
95
end
85
96
86
97
extend ActiveSupport ::Concern
@@ -92,11 +103,23 @@ def raise_if_node_not_installed
92
103
end
93
104
end
94
105
end
106
+ end
95
107
96
- private
108
+ module NodeVersionUnsupported
109
+ class Error < StandardError
110
+ def message
111
+ "This generator requires Node >= #{ Suspenders ::MINIMUM_NODE_VERSION } "
112
+ end
113
+ end
97
114
98
- def node_not_installed?
99
- !node_version . present?
115
+ extend ActiveSupport ::Concern
116
+
117
+ included do
118
+ def raise_if_node_version_unsupported
119
+ if node_version_unsupported?
120
+ raise Suspenders ::Generators ::NodeVersionUnsupported ::Error
121
+ end
122
+ end
100
123
end
101
124
end
102
125
end
Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ module Suspenders
2
2
VERSION = "3.0.0" . freeze
3
3
RAILS_VERSION = "~> 7.0" . freeze
4
4
MINIMUM_RUBY_VERSION = ">= 3.1" . freeze
5
+ MINIMUM_NODE_VERSION = "20.0.0" . freeze
5
6
end
Original file line number Diff line number Diff line change @@ -38,6 +38,16 @@ class WebGeneratorTest < Rails::Generators::TestCase
38
38
end
39
39
end
40
40
41
+ test "raises if Node is unsupported" do
42
+ Object . any_instance . stubs ( :` ) . returns ( "v19.9.9\n " )
43
+
44
+ with_database "postgresql" do
45
+ assert_raises Suspenders ::Generators ::NodeVersionUnsupported ::Error do
46
+ run_generator
47
+ end
48
+ end
49
+ end
50
+
41
51
private
42
52
43
53
def prepare_destination
Original file line number Diff line number Diff line change @@ -12,22 +12,22 @@ class PrerequisitesGeneratorTest < Rails::Generators::TestCase
12
12
teardown :restore_destination
13
13
14
14
test "generates .node-version file (from ENV)" do
15
- ClimateControl . modify NODE_VERSION : "1.2.3 " do
15
+ ClimateControl . modify NODE_VERSION : "20.0.0 " do
16
16
run_generator
17
17
18
18
assert_file app_root ( ".node-version" ) do |file |
19
- assert_match ( /1 \. 2 \. 3 / , file )
19
+ assert_match ( /20 \. 0 \. 0 / , file )
20
20
end
21
21
end
22
22
end
23
23
24
24
test "generates .node-version file (from system)" do
25
- Object . any_instance . stubs ( :` ) . returns ( "v1.2.3 \n " )
25
+ Object . any_instance . stubs ( :` ) . returns ( "v20.0.0 \n " )
26
26
27
27
run_generator
28
28
29
29
assert_file app_root ( ".node-version" ) do |file |
30
- assert_match ( /1 \. 2 \. 3 / , file )
30
+ assert_match ( /20 \. 0 \. 0 / , file )
31
31
end
32
32
end
33
33
@@ -41,6 +41,16 @@ class PrerequisitesGeneratorTest < Rails::Generators::TestCase
41
41
assert_no_file app_root ( ".node-version" )
42
42
end
43
43
44
+ test "raises if Node is unsupported" do
45
+ Object . any_instance . stubs ( :` ) . returns ( "v19.9.9\n " )
46
+
47
+ assert_raises Suspenders ::Generators ::NodeVersionUnsupported ::Error do
48
+ run_generator
49
+ end
50
+
51
+ assert_no_file app_root ( ".node-version" )
52
+ end
53
+
44
54
private
45
55
46
56
def restore_destination
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ module Suspenders
6
6
module Cleanup
7
7
class GenerateReadmeTest < ActiveSupport ::TestCase
8
8
test "generates README using generator descriptions" do
9
- Object . any_instance . stubs ( :` ) . returns ( "v1.2.3 \n " )
9
+ Object . any_instance . stubs ( :` ) . returns ( "v20.0.0 \n " )
10
10
11
11
Tempfile . create "README.md" do |readme |
12
12
path = readme . path
@@ -20,7 +20,7 @@ class GenerateReadmeTest < ActiveSupport::TestCase
20
20
21
21
assert_match "## Prerequisites" , readme
22
22
assert_match Suspenders ::MINIMUM_RUBY_VERSION , readme
23
- assert_match "Node: `1.2.3 `" , readme
23
+ assert_match "Node: `20.0.0 `" , readme
24
24
25
25
assert_match "## Configuration" , readme
26
26
assert_match "### Test" , readme
Original file line number Diff line number Diff line change 1
1
require "test_helper"
2
2
3
3
class Suspenders ::GeneratorsTest < ActiveSupport ::TestCase
4
- class APIAppUnsupportedTest < Suspenders :: GeneratorsTest
4
+ class APIAppUnsupportedTest < ActiveSupport :: TestCase
5
5
test "message returns a custom message" do
6
6
expected = "This generator cannot be used on API only applications."
7
7
8
8
assert_equal expected , Suspenders ::Generators ::APIAppUnsupported ::Error . new . message
9
9
end
10
10
end
11
11
12
- class DatabaseUnsupportedTest < Suspenders :: GeneratorsTest
12
+ class DatabaseUnsupportedTest < ActiveSupport :: TestCase
13
13
test "message returns a custom message" do
14
14
expected = "This generator requires PostgreSQL"
15
15
16
16
assert_equal expected , Suspenders ::Generators ::DatabaseUnsupported ::Error . new . message
17
17
end
18
18
end
19
+
20
+ class NodeNotInstalledTest < ActiveSupport ::TestCase
21
+ test "message returns a custom message" do
22
+ expected = "This generator requires Node"
23
+
24
+ assert_equal expected , Suspenders ::Generators ::NodeNotInstalled ::Error . new . message
25
+ end
26
+ end
27
+
28
+ class NodeVersionUnsupportedTest < ActiveSupport ::TestCase
29
+ test "message returns a custom message" do
30
+ expected = "This generator requires Node >= #{ Suspenders ::MINIMUM_NODE_VERSION } "
31
+
32
+ assert_equal expected , Suspenders ::Generators ::NodeVersionUnsupported ::Error . new . message
33
+ end
34
+ end
19
35
end
Original file line number Diff line number Diff line change @@ -12,4 +12,8 @@ class SuspendersTest < ActiveSupport::TestCase
12
12
test "it has a Minimum Ruby version number" do
13
13
assert Suspenders ::MINIMUM_RUBY_VERSION
14
14
end
15
+
16
+ test "it has a Minimum Node version number" do
17
+ assert Suspenders ::MINIMUM_NODE_VERSION
18
+ end
15
19
end
You can’t perform that action at this time.
0 commit comments