-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix scaffold template with namespace and --model-name
option
#2534
Fix scaffold template with namespace and --model-name
option
#2534
Conversation
Replace ns_file_name to singular_table_name. rspec#2532
Nice, thank you! What happens if you don't specify In case no specs fail, would you please add some examples to prevent from regression to |
@pirj Thank you for quick response!
Thanks for pointing that out. If I remove describe "POST /create" do
context "with valid parameters" do
it "creates a new Admin::Card" do
expect {
post admin_cards_url, params: { admin_card: valid_attributes }
}.to change(Admin::Card, :count).by(1)
end
# ...
end
end Is this the behavior that you expected?
OK! I'll try it. |
Yes, perfect. Thank you! |
- check if parameter name is not admin_post - check if test contains Post.create instead of Admin::Post.create related: rspec#2534 (comment)
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.
Perfect, thank you!
@pirj describe "POST #create" do
context "with valid params" do
it "creates a new Card" do
expect {
post :create, params: {admin_card: valid_attributes}, session: valid_session
}.to change(Card, :count).by(1)
end
# ...
end
end Should this file be fixed as well?
|
It would be great if you're up for it. |
@pirj OK! I'll try it tomorrow 😄 |
We have to change templates/api_request_spec.rb too, there is the same problem. |
ns_file_name
to singular_table_name
in lib/generators/rspec/scaffold/templates/request_spec.rb
. --model-name
option
change ns_file_name to singular_table_name to support --model-name option. related: rspec#2532
@pirj @PedroAugustoRamalhoDuarte
And also, I added some examples to prevent from regression. Please check🙏 |
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.
Great job! Thanks a lot for taking care of the whole thing.
Thanks for tackling this |
Fix scaffold template with namespace and `--model-name` option
close #2532
Fixed the behavior of scaffold template when namespace and
--model-name
option passed.This is because
ns_file_name
method that is called in scaffold template returnsadmin_product
when namespaced.rspec-rails/lib/generators/rspec/scaffold/scaffold_generator.rb
Lines 79 to 83 in ba2d66a
So, I replaced
ns_file_name
tosingular_table_name
in scaffold templates.Also, I added some tests to ensure that templates works in the old way when the
--model-name
option is not passed.