aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorYuji Yaginuma <yuuji.yaginuma@gmail.com>2019-07-18 07:17:47 +0900
committerGitHub <noreply@github.com>2019-07-18 07:17:47 +0900
commitc5a24c8ebba543687c11f893584618a20316fe34 (patch)
tree4e458dfd22e1830d1ff8ff17367ccaf49e4a998f /railties
parent8d967534de4df1a5e487c0ff2f948e138fd883cb (diff)
parent6fec4c3a0aea3ef783372c55aff6d3c1efd89c4e (diff)
downloadrails-c5a24c8ebba543687c11f893584618a20316fe34.tar.gz
rails-c5a24c8ebba543687c11f893584618a20316fe34.tar.bz2
rails-c5a24c8ebba543687c11f893584618a20316fe34.zip
Merge pull request #36603 from y-yagi/add_skip_collision_check_option
Add `skip-collision-check` option to generator
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/base.rb7
-rw-r--r--railties/test/application/generators_test.rb10
2 files changed, 15 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index 0b91e3223e..a153923ce3 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -20,6 +20,8 @@ module Rails
class_option :skip_namespace, type: :boolean, default: false,
desc: "Skip namespace (affects only isolated applications)"
+ class_option :skip_collision_check, type: :boolean, default: false,
+ desc: "Skip collision check"
add_runtime_options!
strict_args_position!
@@ -249,6 +251,7 @@ module Rails
# application or Ruby on Rails.
def class_collisions(*class_names)
return unless behavior == :invoke
+ return if options.skip_collision_check?
class_names.flatten.each do |class_name|
class_name = class_name.to_s
@@ -261,8 +264,8 @@ module Rails
if last && last.const_defined?(last_name.camelize, false)
raise Error, "The name '#{class_name}' is either already used in your application " \
- "or reserved by Ruby on Rails. Please choose an alternative and run " \
- "this generator again."
+ "or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check " \
+ "to skip this check and run this generator again."
end
end
end
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