diff options
Diffstat (limited to 'railties/test/generators/named_base_test.rb')
-rw-r--r-- | railties/test/generators/named_base_test.rb | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 99eb431a49..f327fb1282 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -16,28 +16,68 @@ class NamedBaseTest < Rails::Generators::TestCase tests Rails::Generators::ScaffoldControllerGenerator def test_named_generator_attributes - g = generator ["admin/foo"] - assert_equal 'admin/foo', g.name - assert_equal %w(admin), g.class_path - assert_equal 1, g.class_nesting_depth - assert_equal 'Admin::Foo', g.class_name - assert_equal 'foo', g.singular_name - assert_equal 'foos', g.plural_name - assert_equal g.singular_name, g.file_name - assert_equal "admin_#{g.plural_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin/foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name + end + + def test_named_generator_attributes_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foo', :name + assert_name g, %w(admin), :class_path + assert_name g, 'Admin::Foo', :class_name + assert_name g, 'admin/foo', :file_path + assert_name g, 'foo', :file_name + assert_name g, 'foo', :singular_name + assert_name g, 'foos', :plural_name + assert_name g, 'admin.foo', :i18n_scope + assert_name g, 'admin_foos', :table_name end def test_named_generator_attributes_without_pluralized ActiveRecord::Base.pluralize_table_names = false - g = generator ["admin/foo"] - assert_equal "admin_#{g.singular_name}", g.table_name + g = generator ['admin/foo'] + assert_name g, 'admin_foo', :table_name end def test_scaffold_plural_names - g = generator ["ProductLine"] - assert_equal "ProductLines", g.controller_name - assert_equal "ProductLines", g.controller_class_name - assert_equal "product_lines", g.controller_file_name + g = generator ['admin/foo'] + assert_name g, 'admin/foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope + end + + def test_scaffold_plural_names_as_ruby + g = generator ['Admin::Foo'] + assert_name g, 'Admin::Foos', :controller_name + assert_name g, %w(admin), :controller_class_path + assert_name g, 'Admin::Foos', :controller_class_name + assert_name g, 'admin/foos', :controller_file_path + assert_name g, 'foos', :controller_file_name + assert_name g, 'admin.foos', :controller_i18n_scope end + def test_application_name + g = generator ['Admin::Foo'] + Rails.stubs(:application).returns(Object.new) + assert_name g, "object", :application_name + Rails.stubs(:application).returns(nil) + assert_name g, "application", :application_name + end + + protected + + def assert_name(generator, value, method) + assert_equal value, generator.send(method) + end end |