diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-23 00:52:34 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-23 00:52:34 +0000 |
commit | 4ff4afa57949e6a7a4d3d200531932207f97da8e (patch) | |
tree | 3546444b022426e7324b667fe8662c88ed6b0775 /railties/generators | |
parent | 4ce65f434a29460aebcd2eaa511d85f0ff6bb18a (diff) | |
download | rails-4ff4afa57949e6a7a4d3d200531932207f97da8e.tar.gz rails-4ff4afa57949e6a7a4d3d200531932207f97da8e.tar.bz2 rails-4ff4afa57949e6a7a4d3d200531932207f97da8e.zip |
Added protection for creating a model through the generators with a name of an existing class, like Thread or Date. It'll even offer you a synonym using wordnet.princeton.edu as a look-up. No, I'm not kidding :) [Florian Gross]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@263 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/generators')
4 files changed, 12 insertions, 4 deletions
diff --git a/railties/generators/controller/controller_generator.rb b/railties/generators/controller/controller_generator.rb index 4b53741565..79f9a7e03b 100644 --- a/railties/generators/controller/controller_generator.rb +++ b/railties/generators/controller/controller_generator.rb @@ -19,4 +19,8 @@ class ControllerGenerator < Rails::Generator::Base template "view.rhtml", "app/views/#{file_name}/#{action}.rhtml", binding end end + + def full_class_name + class_name + "Controller" + end end diff --git a/railties/generators/controller/templates/controller.rb b/railties/generators/controller/templates/controller.rb index da71b5f057..0daf04b348 100644 --- a/railties/generators/controller/templates/controller.rb +++ b/railties/generators/controller/templates/controller.rb @@ -1,4 +1,4 @@ -class <%= class_name %>Controller < ApplicationController +class <%= full_class_name %> < ApplicationController <% if options[:scaffold] -%> scaffold :<%= singular_name %> <% end -%> diff --git a/railties/generators/controller/templates/functional_test.rb b/railties/generators/controller/templates/functional_test.rb index c975cb3ce3..df75ad57e9 100644 --- a/railties/generators/controller/templates/functional_test.rb +++ b/railties/generators/controller/templates/functional_test.rb @@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/../test_helper' require '<%= file_name %>_controller' # Re-raise errors caught by the controller. -class <%= class_name %>Controller; def rescue_action(e) raise e end; end +class <%= full_class_name %>; def rescue_action(e) raise e end; end -class <%= class_name %>ControllerTest < Test::Unit::TestCase +class <%= full_class_name %>Test < Test::Unit::TestCase def setup - @controller = <%= class_name %>Controller.new + @controller = <%= full_class_name %>.new @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new end diff --git a/railties/generators/scaffold/scaffold_generator.rb b/railties/generators/scaffold/scaffold_generator.rb index ee556e8a03..55bb835bb7 100644 --- a/railties/generators/scaffold/scaffold_generator.rb +++ b/railties/generators/scaffold/scaffold_generator.rb @@ -34,6 +34,10 @@ class ScaffoldGenerator < Rails::Generator::Base end end + def full_class_name + class_name + "Controller" + end + protected def scaffold_views %w(list show new edit) |