1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Marcel Molina 2005-09-28 00:06:39 +00:00
parent 0b1abc3360
commit 8e78e9335b
4 changed files with 12 additions and 3 deletions

View file

@ -1,5 +1,7 @@
*SVN* *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] * 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] * Make the migration generator only check files ending in *.rb when calculating the next file name #2317 [Chad Fowler]

View file

@ -144,10 +144,9 @@ module Rails
# #
# See Rails::Generator::Base for a discussion of Manifests and Commands. # See Rails::Generator::Base for a discussion of Manifests and Commands.
class NamedBase < Base 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 attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth
alias_method :file_name, :singular_name alias_method :file_name, :singular_name
alias_method :table_name, :plural_name
alias_method :actions, :args alias_method :actions, :args
def initialize(runtime_args, runtime_options = {}) def initialize(runtime_args, runtime_options = {})
@ -172,6 +171,7 @@ module Rails
@name = name @name = name
base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@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) @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? if @class_nesting.empty?
@class_name = @class_name_without_nesting @class_name = @class_name_without_nesting
else else

View file

@ -46,7 +46,7 @@ class ScaffoldGenerator < Rails::Generator::NamedBase
def initialize(runtime_args, runtime_options = {}) def initialize(runtime_args, runtime_options = {})
super 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) 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) @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
if @controller_class_nesting.empty? if @controller_class_nesting.empty?

View file

@ -74,6 +74,7 @@ class RailsGeneratorTest < Test::Unit::TestCase
end end
def test_named_generator_attributes def test_named_generator_attributes
ActiveRecord::Base.pluralize_table_names = true
g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz)) g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz))
assert_equal 'admin/foo', g.name assert_equal 'admin/foo', g.name
assert_equal %w(admin), g.class_path 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 g.plural_name, g.table_name
assert_equal %w(bar baz), g.args assert_equal %w(bar baz), g.args
end 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 end