mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36603 from y-yagi/add_skip_collision_check_option
Add `skip-collision-check` option to generator
This commit is contained in:
commit
c5a24c8ebb
2 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue