mirror of https://github.com/rails/rails
Generators skip collision check if force option is passed.
This commit is contained in:
parent
cb495ab250
commit
1dd2b73cb2
|
@ -1,3 +1,7 @@
|
|||
* Generators that inherit from NamedBase respect `--force` option
|
||||
|
||||
*Josh Brody*
|
||||
|
||||
* Support using environment variable to set pidfile
|
||||
|
||||
*Ben Thorner*
|
||||
|
|
|
@ -252,6 +252,7 @@ module Rails
|
|||
def class_collisions(*class_names)
|
||||
return unless behavior == :invoke
|
||||
return if options.skip_collision_check?
|
||||
return if options.force?
|
||||
|
||||
class_names.flatten.each do |class_name|
|
||||
class_name = class_name.to_s
|
||||
|
@ -265,7 +266,7 @@ 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 or use --skip-collision-check " \
|
||||
"to skip this check and run this generator again."
|
||||
"or --force to skip this check and run this generator again."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -208,5 +208,15 @@ module ApplicationTests
|
|||
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
|
||||
|
||||
test "force" 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", "--force")
|
||||
assert_no_match(/The name 'Post' is either already used in your application or reserved/, output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue