diff options
author | Marcel Molina <marcel@vernix.org> | 2005-09-28 00:06:39 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2005-09-28 00:06:39 +0000 |
commit | 8e78e9335b6b6e86d5a55f9d00ea0ab699268cc5 (patch) | |
tree | a2eab5b1b6e41762122c1c18e6af6a730dcfe01b /railties | |
parent | 0b1abc3360706268618dabcb1868fb0406d997aa (diff) | |
download | rails-8e78e9335b6b6e86d5a55f9d00ea0ab699268cc5.tar.gz rails-8e78e9335b6b6e86d5a55f9d00ea0ab699268cc5.tar.bz2 rails-8e78e9335b6b6e86d5a55f9d00ea0ab699268cc5.zip |
Make table_name and controller_name in generators honor AR::Base.pluralize_table_names.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2380 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/rails_generator/base.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb | 2 | ||||
-rw-r--r-- | railties/test/rails_generator_test.rb | 7 |
4 files changed, 12 insertions, 3 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 35fb6dc425..6cefa07542 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make table_name and controller_name in generators honor AR::Base.pluralize_table_names. #2213 [kazuhiko@fdiary.net] + * Clearly label functional and unit tests in rake stats output. #2297 [lasse.koskela@gmail.com] * Make the migration generator only check files ending in *.rb when calculating the next file name #2317 [Chad Fowler] diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb index f7aa2169ca..6a56f96b1c 100644 --- a/railties/lib/rails_generator/base.rb +++ b/railties/lib/rails_generator/base.rb @@ -144,10 +144,9 @@ module Rails # # See Rails::Generator::Base for a discussion of Manifests and Commands. class NamedBase < Base - attr_reader :name, :class_name, :singular_name, :plural_name + attr_reader :name, :class_name, :singular_name, :plural_name, :table_name attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth alias_method :file_name, :singular_name - alias_method :table_name, :plural_name alias_method :actions, :args def initialize(runtime_args, runtime_options = {}) @@ -172,6 +171,7 @@ module Rails @name = name base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name) @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) + @table_name = ActiveRecord::Base.pluralize_table_names ? plural_name : singular_name if @class_nesting.empty? @class_name = @class_name_without_nesting else diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb index 5ffe428fce..0f789efc83 100644 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb @@ -46,7 +46,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase def initialize(runtime_args, runtime_options = {}) super - @controller_name = args.shift || @name.pluralize + @controller_name = args.shift || ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) if @controller_class_nesting.empty? diff --git a/railties/test/rails_generator_test.rb b/railties/test/rails_generator_test.rb index 3f63509384..00cd94596b 100644 --- a/railties/test/rails_generator_test.rb +++ b/railties/test/rails_generator_test.rb @@ -74,6 +74,7 @@ class RailsGeneratorTest < Test::Unit::TestCase end def test_named_generator_attributes + ActiveRecord::Base.pluralize_table_names = true g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz)) assert_equal 'admin/foo', g.name assert_equal %w(admin), g.class_path @@ -85,4 +86,10 @@ class RailsGeneratorTest < Test::Unit::TestCase assert_equal g.plural_name, g.table_name assert_equal %w(bar baz), g.args end + + def test_named_generator_attributes_without_pluralized + ActiveRecord::Base.pluralize_table_names = false + g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz)) + assert_equal g.singular_name, g.table_name + end end |