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 system tests to generate scaffold #29418
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @matthewd (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
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.
This is looking really great! I just tried it out and all the tests worked with the scaffold! 😄
I left a few comments for things that need some changes. Thanks for working on this!
|
||
unless options.api? | ||
template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") | ||
end |
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 needs to check depends_on_system_test?
because some users may want to skip system tests when generating the scaffold.
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.
Looks like this method is defined in Rails::Generators::AppBase
. Would it be best to replicate this in TestUnit::Generators::Base
or rely on the system_tests
option set here?
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 what you wrote is correct. I was thinking of the skip code elsewhere in the generators.
["#{name}", "@#{singular_table_name}.#{name}"] | ||
end | ||
end.sort.to_h | ||
end |
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.
The rubocop build is failing for these because the methods should be indented 2 spaces under private
and there should be a space after the bracket here {|k, v| "#{k}: #{v}"}.join(", ")
.
@@ -29,7 +29,7 @@ class <%= controller_class_name %>ControllerTest < ActionDispatch::IntegrationTe | |||
end | |||
|
|||
test "should update <%= singular_table_name %>" do | |||
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_hash} }" %> }, as: :json | |||
patch <%= show_helper %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json |
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.
Why did these need to change?
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.
attributes_hash
formerly referred to a string representation of the attributes (i.e. "{key: value}"
). I needed a real ruby hash to iterate over so I named that method attributes_hash
and renamed this to reflect its type.
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.
Cool thanks for the explanation!
@@ -16,13 +16,10 @@ class ScaffoldGenerator < ResourceGenerator # :nodoc: | |||
def handle_skip | |||
@options = @options.merge(stylesheets: false) unless options[:assets] | |||
@options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet] | |||
@options = @options.merge(system_tests: false) if options[:api] |
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 swapped this out for @options = @options.merge(system_tests: nil) if options[:api]
and it still wasn't available in the options hash in railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb so I left the options.api?
check in. I'm not sure what the purpose of this line is.
Awesome work @dinahshi! Can you squash your commits into 1 and then I'll merge? Thanks so much for working on this. |
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.
There's one issue when we're skipping system tests on the scaffold generator. There's a missing test case since all the tests are passing.
|
||
unless options.api? || options[:system_tests].nil? | ||
template "system_test.rb", File.join("test/system", class_path, "#{file_name.pluralize}_test.rb") | ||
end |
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 just tested this and there's a missing test case. This doesn't work for generating a scaffold and passing the skip system test option.
bin/rails g scaffold Tree title:string --skip-system-test
In that case the system test file would still be generated because we're not checking at all for the skip-system-test
option which is why I ended up changing the config file in the other PR. Because then otherwise we end up checking for 2 options for skipping system tests.
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 tried this on master and it's not currently supported. bin/rails g scaffold Tree title:string --skip-test
also doesn't skip any tests (including model, controller, and system tests). As a result I think adding command line options to non-application generate commands is likely a larger task and should be separate from this change.
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.
You're right, it's not supported on master. I think this PR is fine then and if we want to implement --skip-system-test
for scaffold we can do that in a separate PR.
efd260f
to
d502cd1
Compare
generate scaffold
currently generates a simple system test. This changepopulates the generated system test with index, create, update, and destroy
behaviour. Feature request from @eileencodes
Sample generated test from
bin/rails generate scaffold HighScore game:string score:integer
: