-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add accept_confirm if turbo is available so system tests don't fail. fixes #519 #520
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is the best option out of the ones you listed? I'd rather not have to maintain a copy of the system tests! I made one small suggestion to try to make the gsub_file less finicky (in case the upstream system tests change).
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 }" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a bit less brittle (in the case where the exact text of the system test changes) by using a more permissive regular expression? Maybe something like
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 }" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I tested this change and it works, so I added a commit doing it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much nicer! thanks!
Yes, I feel the same. I didn't want to maintain a copy of the system test just for this. And looks much nicer with your version of the gsub! |
I also just added a very simple integration test to make sure the gsub applies cleanly. I don't think I'm ready to add a full Rails system test to CI. 😅 |
ed7600b
to
37c98c3
Compare
Generated tests starting failing after we added the data turbo confirm attribute to delete links.
This PR fixes that by monkey patching the test_unit/scaffold generator so after everything is generated it will wrap the
click_on
call with aaccept_confirm
call, only if turbo is defined.will try to add test for this but wanted to confirm if the approach is something everyone would agree on.
Alternatives:
source_paths << File.expand_path("templates", __dir__)
and copy thesystem_test.rb.tt
from rails and add a guard there to check if turbo is available instead of gsubing the file in the generatordata-turbo-confirm
from the template.