From 84a0d6bf869ade33e450c4b070e5fa7b5d3d7e8a Mon Sep 17 00:00:00 2001 From: Patricio Mac Adden Date: Wed, 19 Mar 2025 11:09:43 -0300 Subject: [PATCH 1/3] add accept_confirm if turbo is available so system tests don't fail. fixes #519 --- .../scaffold/scaffold_generator.rb | 1 + .../test_unit/scaffold/scaffold_generator.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 lib/generators/test_unit/scaffold/scaffold_generator.rb diff --git a/lib/generators/tailwindcss/scaffold/scaffold_generator.rb b/lib/generators/tailwindcss/scaffold/scaffold_generator.rb index 39c2da1f..8748210d 100644 --- a/lib/generators/tailwindcss/scaffold/scaffold_generator.rb +++ b/lib/generators/tailwindcss/scaffold/scaffold_generator.rb @@ -1,5 +1,6 @@ require "rails/generators/erb/scaffold/scaffold_generator" require "rails/generators/resource_helpers" +require File.expand_path("../../test_unit/scaffold/scaffold_generator.rb", __dir__) module Tailwindcss module Generators diff --git a/lib/generators/test_unit/scaffold/scaffold_generator.rb b/lib/generators/test_unit/scaffold/scaffold_generator.rb new file mode 100644 index 00000000..b97d74e4 --- /dev/null +++ b/lib/generators/test_unit/scaffold/scaffold_generator.rb @@ -0,0 +1,19 @@ +require "rails/generators/test_unit/scaffold/scaffold_generator" + +module TestUnit # :nodoc: + module Generators # :nodoc: + class ScaffoldGenerator < Base # :nodoc: + def fix_system_test + if turbo_defined? + gsub_file File.join("test/system", class_path, "#{file_name.pluralize}_test.rb"), "click_on \"Destroy this #{human_name.downcase}\", match: :first", "accept_confirm { click_on \"Destroy this #{human_name.downcase}\", match: :first }" + end + end + + private + + def turbo_defined? + defined?(Turbo) + end + end + end +end From 0653d82770e5c3b5196b882117447213bddd1a03 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 19 Mar 2025 15:05:49 -0400 Subject: [PATCH 2/3] Make the system test gsub less finicky --- lib/generators/test_unit/scaffold/scaffold_generator.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/generators/test_unit/scaffold/scaffold_generator.rb b/lib/generators/test_unit/scaffold/scaffold_generator.rb index b97d74e4..ff809b32 100644 --- a/lib/generators/test_unit/scaffold/scaffold_generator.rb +++ b/lib/generators/test_unit/scaffold/scaffold_generator.rb @@ -5,7 +5,9 @@ module Generators # :nodoc: class ScaffoldGenerator < Base # :nodoc: def fix_system_test if turbo_defined? - gsub_file File.join("test/system", class_path, "#{file_name.pluralize}_test.rb"), "click_on \"Destroy this #{human_name.downcase}\", match: :first", "accept_confirm { click_on \"Destroy this #{human_name.downcase}\", match: :first }" + gsub_file File.join("test/system", class_path, "#{file_name.pluralize}_test.rb"), + /(click_on.*Destroy this.*)$/, + "accept_confirm { \\1 }" end end From 37c98c3e95d08c2ddb7f0766222b0840869ef820 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 19 Mar 2025 15:12:46 -0400 Subject: [PATCH 3/3] Add a simple integration test for the scaffolded system test --- test/integration/user_install_test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integration/user_install_test.sh b/test/integration/user_install_test.sh index 6f4ca301..bfd7a87c 100755 --- a/test/integration/user_install_test.sh +++ b/test/integration/user_install_test.sh @@ -63,6 +63,9 @@ fi bin/rails generate scaffold post title:string body:text published:boolean grep -q "Show" app/views/posts/index.html.erb +# TEST: the "accept_confirm" system test change was applied cleanly +grep -q "accept_confirm { click_on \"Destroy this post\"" test/system/posts_test.rb + # TEST: contents of the css file bin/rails tailwindcss:build[verbose] grep -q "py-2" app/assets/builds/tailwind.css