@@ -653,6 +653,20 @@ def test_ci_files_are_skipped_if_required
653
653
assert_no_file ".github/dependabot.yml"
654
654
end
655
655
656
+ def test_inclusion_of_kamal_files
657
+ run_generator_instance
658
+
659
+ assert_file "config/deploy.yml"
660
+ assert_file ".env.erb"
661
+ end
662
+
663
+ def test_kamal_files_are_skipped_if_required
664
+ run_generator [ destination_root , "--skip-kamal" ]
665
+
666
+ assert_no_file "config/deploy.yml"
667
+ assert_no_file ".env.erb"
668
+ end
669
+
656
670
def test_usage_read_from_file
657
671
assert_called ( File , :read , returns : "USAGE FROM FILE" ) do
658
672
assert_equal "USAGE FROM FILE" , Rails ::Generators ::AppGenerator . desc
@@ -766,15 +780,10 @@ def test_skip_active_job_option
766
780
def test_skip_javascript_option
767
781
generator ( [ destination_root ] , skip_javascript : true )
768
782
769
- command_check = -> command , *_ do
770
- if command == "importmap:install"
771
- flunk "`importmap:install` expected to not be called."
772
- end
773
- end
783
+ run_generator_instance
774
784
775
- generator . stub ( :rails_command , command_check ) do
776
- run_generator_instance
777
- end
785
+ assert_not_includes @rails_commands , "importmap:install" , "`importmap:install` expected to not be called."
786
+ assert_not_includes @rails_commands , "turbo:install stimulus:install" , "`turbo:install stimulus:install` expected to not be called."
778
787
779
788
assert_no_gem "importmap-rails"
780
789
assert_no_gem "jsbundling-rails"
@@ -792,39 +801,19 @@ def test_skip_javascript_option
792
801
def test_webpack_option
793
802
generator ( [ destination_root ] , javascript : "webpack" )
794
803
795
- webpack_called = 0
796
- command_check = -> command , *_ do
797
- case command
798
- when "javascript:install:webpack"
799
- webpack_called += 1
800
- end
801
- end
802
-
803
- generator . stub ( :rails_command , command_check ) do
804
- run_generator_instance
805
- end
804
+ run_generator_instance
806
805
807
- assert_equal 1 , webpack_called , "`javascript:install:webpack` expected to be called once , but was called #{ webpack_called } times ."
806
+ assert_includes @rails_commands , "javascript:install:webpack" , "`javascript:install:webpack` expected to be called, but wasn't ."
808
807
assert_gem "jsbundling-rails"
809
808
assert_node_files
810
809
end
811
810
812
811
def test_esbuild_option
813
812
generator ( [ destination_root ] , javascript : "esbuild" )
814
813
815
- esbuild_called = 0
816
- command_check = -> command , *_ do
817
- case command
818
- when "javascript:install:esbuild"
819
- esbuild_called += 1
820
- end
821
- end
822
-
823
- generator . stub ( :rails_command , command_check ) do
824
- run_generator_instance
825
- end
814
+ run_generator_instance
826
815
827
- assert_equal 1 , esbuild_called , "`javascript:install:esbuild` expected to be called once , but was called #{ esbuild_called } times ."
816
+ assert_includes @rails_commands , "javascript:install:esbuild" , "`javascript:install:esbuild` expected to be called, but wasn't ."
828
817
assert_gem "jsbundling-rails"
829
818
assert_node_files
830
819
end
@@ -847,19 +836,9 @@ def test_esbuild_option_with_js_argument
847
836
def test_bun_option
848
837
generator ( [ destination_root ] , javascript : "bun" )
849
838
850
- bun_called = 0
851
- command_check = -> command , *_ do
852
- case command
853
- when "javascript:install:bun"
854
- bun_called += 1
855
- end
856
- end
857
-
858
- generator . stub ( :rails_command , command_check ) do
859
- run_generator_instance
860
- end
839
+ run_generator_instance
861
840
862
- assert_equal 1 , bun_called , "`javascript:install:bun` expected to be called once , but was called #{ bun_called } times ."
841
+ assert_includes @rails_commands , "javascript:install:bun" , "`javascript:install:bun` expected to be called, but wasn't ."
863
842
assert_gem "jsbundling-rails"
864
843
end
865
844
@@ -900,20 +879,20 @@ def test_skip_javascript_option_with_skip_js_argument
900
879
end
901
880
902
881
def test_hotwire
903
- run_generator_and_bundler [ destination_root ]
882
+ generator [ destination_root ]
883
+ run_generator_instance
884
+
885
+ assert_includes @rails_commands , "turbo:install stimulus:install" , "`turbo:install stimulus:install` expected to be called, but wasn't."
904
886
assert_gem "turbo-rails"
905
887
assert_gem "stimulus-rails"
906
888
assert_file "app/views/layouts/application.html.erb" do |content |
907
889
assert_match ( /data-turbo-track/ , content )
908
890
end
909
- assert_file "app/javascript/application.js" do |content |
910
- assert_match ( /turbo/ , content )
911
- assert_match ( /controllers/ , content )
912
- end
913
891
end
914
892
915
893
def test_skip_hotwire
916
- run_generator [ destination_root , "--skip-hotwire" ]
894
+ generator [ destination_root ] , [ "--skip-hotwire" ]
895
+ run_generator_instance
917
896
918
897
assert_no_gem "turbo-rails"
919
898
assert_file "app/views/layouts/application.html.erb" do |content |
@@ -923,11 +902,11 @@ def test_skip_hotwire
923
902
end
924
903
925
904
def test_css_option_with_asset_pipeline_tailwind
926
- run_generator_and_bundler [ destination_root , "--css=tailwind" ]
905
+ generator [ destination_root ] , [ "--css=tailwind" ]
906
+ run_generator_instance
907
+
908
+ assert_includes @rails_commands , "tailwindcss:install" , "`tailwindcss:install` expected to be called, but wasn't."
927
909
assert_gem "tailwindcss-rails"
928
- assert_file "app/views/layouts/application.html.erb" do |content |
929
- assert_match ( /tailwind/ , content )
930
- end
931
910
assert_no_node_files
932
911
end
933
912
@@ -938,9 +917,11 @@ def test_css_option_with_tailwind_uses_cssbundling_gem_when_using_node
938
917
end
939
918
940
919
def test_css_option_with_asset_pipeline_sass
941
- run_generator_and_bundler [ destination_root , "--css=sass" ]
920
+ generator [ destination_root ] , [ "--css=sass" ]
921
+ run_generator_instance
922
+
923
+ assert_includes @rails_commands , "dartsass:install" , "`dartsass:install` expected to be called, but wasn't."
942
924
assert_gem "dartsass-rails"
943
- assert_file "app/assets/stylesheets/application.scss"
944
925
assert_no_node_files
945
926
end
946
927
@@ -951,9 +932,11 @@ def test_css_option_with_sass_uses_cssbundling_gem_when_using_node
951
932
end
952
933
953
934
def test_css_option_with_cssbundling_gem
954
- run_generator_and_bundler [ destination_root , "--css=postcss" ]
935
+ generator [ destination_root ] , [ "--css=postcss" ]
936
+ run_generator_instance
937
+
938
+ assert_includes @rails_commands , "css:install:postcss" , "`css:install:postcss` expected to be called, but wasn't."
955
939
assert_gem "cssbundling-rails"
956
- assert_file "app/assets/stylesheets/application.postcss.css"
957
940
assert_node_files
958
941
end
959
942
@@ -963,6 +946,16 @@ def test_css_option_with_cssbundling_gem_does_not_force_jsbundling_gem
963
946
assert_gem "importmap-rails"
964
947
end
965
948
949
+ def test_default_generator_executes_all_rails_commands
950
+ generator [ destination_root ]
951
+ run_generator_instance
952
+
953
+ expected_commands = [
954
+ "credentials:diff --enroll" , "importmap:install" , "turbo:install stimulus:install"
955
+ ]
956
+ assert_equal expected_commands , @rails_commands
957
+ end
958
+
966
959
def test_skip_dev_gems
967
960
run_generator [ destination_root , "--skip-dev-gems" ]
968
961
assert_no_gem "web-console"
@@ -1250,21 +1243,7 @@ def assert_no_node_files
1250
1243
end
1251
1244
end
1252
1245
1253
- def run_generator_and_bundler ( args )
1254
- option_args , positional_args = args . partition { |arg | arg . start_with? ( "--" ) }
1255
- option_args << "--no-skip-bundle"
1256
- generator ( positional_args , option_args )
1257
-
1258
- # Stub `rails_gemfile_entry` so that Bundler resolves `gem "rails"` to the
1259
- # current repository instead of searching for an invalid version number
1260
- # (for a version that hasn't been released yet).
1261
- rails_gemfile_entry = Rails ::Generators ::AppBase ::GemfileEntry . path ( "rails" , Rails ::Generators ::RAILS_DEV_PATH )
1262
- generator . stub ( :rails_gemfile_entry , -> { rails_gemfile_entry } ) do
1263
- quietly { run_generator_instance }
1264
- end
1265
- end
1266
-
1267
- def run_app_update ( app_root = destination_root )
1246
+ def run_app_update ( app_root = destination_root , flags : "--force" )
1268
1247
Dir . chdir ( app_root ) do
1269
1248
gemfile_contents = File . read ( "Gemfile" )
1270
1249
gemfile_contents . sub! ( /^(gem "rails").*/ , "\\ 1, path: #{ File . expand_path ( "../../.." , __dir__ ) . inspect } " )
0 commit comments