diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-11-05 13:37:21 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-11-05 13:46:28 +0900 |
commit | 4dcb630c6eaf7e4d8e450b3e9f19e38ebbf41d8b (patch) | |
tree | f568b4c8622259ea0cca1616595d27789da5d3cb /railties/test/generators/scaffold_generator_test.rb | |
parent | 9ec67362054e874ed905310a79b670941fa397af (diff) | |
download | rails-4dcb630c6eaf7e4d8e450b3e9f19e38ebbf41d8b.tar.gz rails-4dcb630c6eaf7e4d8e450b3e9f19e38ebbf41d8b.tar.bz2 rails-4dcb630c6eaf7e4d8e450b3e9f19e38ebbf41d8b.zip |
Generate the correct path in nested scaffold generator
Currently, namespaced scaffold generator will generate an incorrect path
and the generated file will not work properly.
```
$ ./bin/rails g scaffold admin/user
$ ./bin/rails db:migrate
$ ./bin/rails t test/controllers
# Running:
E
Error:
Admin::UsersControllerTest#test_should_create_admin_user:
NameError: undefined local variable or method `admin_admin_users_url' for #<Admin::UsersControllerTest:0x000055a59f25ff68>
Did you mean? admin_users
test/controllers/admin/users_controller_test.rb:20:in `block (2 levels) in <class:UsersControllerTest>'
test/controllers/admin/users_controller_test.rb:19:in `block in <class:UsersControllerTest>'
bin/rails test test/controllers/admin/users_controller_test.rb:18
```
This is because combine `controller_class_path` and `singular_table_name`
to generate route.
https://github.com/rails/rails/blob/360698aa245b45349d1d1b12e1afb34759515e69/railties/lib/rails/generators/named_base.rb#L172
Normally, if using namspaced generator, table name already contains
namespace. Therefore, adding `controller_class_path` adds extra namespace.
Since it is special only when explicitly specifying `model-name`, it is
modified to change the value only when `model-name`is specified.
Follow up of #30729
Diffstat (limited to 'railties/test/generators/scaffold_generator_test.rb')
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 03322c1c59..b6294c3b94 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -282,7 +282,14 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase /class Admin::RolesTest < ApplicationSystemTestCase/ # Views - %w(index edit new show _form).each do |view| + assert_file "app/views/admin/roles/index.html.erb" do |content| + assert_match("'Show', admin_role", content) + assert_match("'Edit', edit_admin_role_path(admin_role)", content) + assert_match("'Destroy', admin_role", content) + assert_match("'New Admin Role', new_admin_role_path", content) + end + + %w(edit new show _form).each do |view| assert_file "app/views/admin/roles/#{view}.html.erb" end assert_no_file "app/views/layouts/admin/roles.html.erb" |