aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2019-06-29 08:43:16 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2019-07-05 18:55:47 +0900
commit6fec4c3a0aea3ef783372c55aff6d3c1efd89c4e (patch)
tree54b17269751d4f5967fe335f617f1fdcf1cf685b /railties/test
parenta59b2305792dd7012a8abc2e4b1a7d9037e8e208 (diff)
downloadrails-6fec4c3a0aea3ef783372c55aff6d3c1efd89c4e.tar.gz
rails-6fec4c3a0aea3ef783372c55aff6d3c1efd89c4e.tar.bz2
rails-6fec4c3a0aea3ef783372c55aff6d3c1efd89c4e.zip
Add `skip-collision-check` option to generator
Until Rails 5.2, generators can run same name multi times without destroying. But Rails 6.0(with Zeitwerk) can't this. In Rails 6.0, an error occurs due to class name collision check. The check uses `const_defined?`, which assumes that the autoload object is also defined. https://ruby-doc.org/core-2.6.3/Module.html#method-i-const_defined-3F It did not work until Rails 5.2, but Zeitwerk seems to be able to correctly check this against the application's code. However, this is a little inconvenient if want to run the generator again like mistake an attribute name(need to run `destoy` before). In order to solve this, this PR adds an option to skip the collision check. With this option, you can overwrite files just as did until Rails 5.2.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/generators_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index e5e557d204..8ec26db772 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -198,5 +198,15 @@ module ApplicationTests
assert_no_match "active_record:migration", output
end
end
+
+ test "skip collision check" do
+ rails("generate", "model", "post", "title:string")
+
+ output = rails("generate", "model", "post", "title:string", "body:string")
+ assert_match(/The name 'Post' is either already used in your application or reserved/, output)
+
+ output = rails("generate", "model", "post", "title:string", "body:string", "--skip-collision-check")
+ assert_no_match(/The name 'Post' is either already used in your application or reserved/, output)
+ end
end
end