2009-07-01 16:19:54 -04:00
|
|
|
require 'generators/generators_test_helper'
|
2010-03-23 08:40:19 -04:00
|
|
|
require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
|
2009-07-01 16:19:54 -04:00
|
|
|
|
|
|
|
# Mock out what we need from AR::Base.
|
|
|
|
module ActiveRecord
|
|
|
|
class Base
|
|
|
|
class << self
|
|
|
|
attr_accessor :pluralize_table_names
|
|
|
|
end
|
|
|
|
self.pluralize_table_names = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-18 18:07:11 -05:00
|
|
|
class NamedBaseTest < Rails::Generators::TestCase
|
|
|
|
include GeneratorsTestHelper
|
2010-01-03 10:34:32 -05:00
|
|
|
tests Rails::Generators::ScaffoldControllerGenerator
|
2009-07-01 16:19:54 -04:00
|
|
|
|
2010-03-16 19:08:59 -04:00
|
|
|
def test_named_generator_with_underscore
|
|
|
|
g = generator ['line_item']
|
|
|
|
assert_name g, 'line_item', :name
|
|
|
|
assert_name g, %w(), :class_path
|
|
|
|
assert_name g, 'LineItem', :class_name
|
|
|
|
assert_name g, 'line_item', :file_path
|
|
|
|
assert_name g, 'line_item', :file_name
|
|
|
|
assert_name g, 'Line item', :human_name
|
|
|
|
assert_name g, 'line_item', :singular_name
|
|
|
|
assert_name g, 'line_items', :plural_name
|
|
|
|
assert_name g, 'line_item', :i18n_scope
|
|
|
|
assert_name g, 'line_items', :table_name
|
|
|
|
end
|
|
|
|
|
2009-07-01 16:19:54 -04:00
|
|
|
def test_named_generator_attributes
|
2010-01-25 07:13:29 -05:00
|
|
|
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
|
2010-03-16 19:08:59 -04:00
|
|
|
assert_name g, 'Foo', :human_name
|
2010-01-25 07:13:29 -05:00
|
|
|
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
|
2010-03-16 19:08:59 -04:00
|
|
|
assert_name g, 'Foo', :human_name
|
2010-01-25 07:13:29 -05:00
|
|
|
assert_name g, 'foos', :plural_name
|
|
|
|
assert_name g, 'admin.foo', :i18n_scope
|
|
|
|
assert_name g, 'admin_foos', :table_name
|
2009-07-01 16:19:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_named_generator_attributes_without_pluralized
|
|
|
|
ActiveRecord::Base.pluralize_table_names = false
|
2010-01-25 07:13:29 -05:00
|
|
|
g = generator ['admin/foo']
|
|
|
|
assert_name g, 'admin_foo', :table_name
|
2010-03-16 19:08:59 -04:00
|
|
|
ensure
|
|
|
|
ActiveRecord::Base.pluralize_table_names = true
|
2009-07-01 16:19:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_scaffold_plural_names
|
2010-01-25 07:13:29 -05:00
|
|
|
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
|
2009-07-01 16:19:54 -04:00
|
|
|
end
|
|
|
|
|
2010-01-25 19:06:48 -05:00
|
|
|
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
|
|
|
|
|
2010-01-25 07:13:29 -05:00
|
|
|
protected
|
|
|
|
|
|
|
|
def assert_name(generator, value, method)
|
|
|
|
assert_equal value, generator.send(method)
|
|
|
|
end
|
2009-07-01 16:19:54 -04:00
|
|
|
end
|