mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added config.generators with tests.
This commit is contained in:
parent
c07746cbdf
commit
2699e9c2dd
2 changed files with 77 additions and 1 deletions
|
@ -249,5 +249,52 @@ module Rails
|
|||
def reload_plugins?
|
||||
@reload_plugins
|
||||
end
|
||||
|
||||
# Holds generators configuration:
|
||||
#
|
||||
# config.generators.orm :datamapper
|
||||
# config.generators.test_framework :rspec
|
||||
# config.generators.template_engine :haml
|
||||
#
|
||||
# A block can also be given for less verbose configuration:
|
||||
#
|
||||
# config.generators do |g|
|
||||
# g.orm :datamapper
|
||||
# g.test_framework :datamapper
|
||||
# g.template_engine :haml
|
||||
# end
|
||||
#
|
||||
# You can also configure/override aliases:
|
||||
#
|
||||
# config.generators.aliases :test_framework => "-w"
|
||||
#
|
||||
def generators
|
||||
@generators ||= Generators.new
|
||||
if block_given?
|
||||
yield @generators
|
||||
else
|
||||
@generators
|
||||
end
|
||||
end
|
||||
|
||||
class Generators #:nodoc:
|
||||
def initialize
|
||||
@aliases, @options = {}, {}
|
||||
end
|
||||
|
||||
def aliases(values=nil)
|
||||
@aliases = values if values
|
||||
@aliases
|
||||
end
|
||||
|
||||
def options(values=nil)
|
||||
@options = values if values
|
||||
@options
|
||||
end
|
||||
|
||||
def method_missing(method, *args, &block)
|
||||
@options[method.to_sym] = args.first
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -278,6 +278,35 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
class InitializerGeneratorsTests < Test::Unit::TestCase
|
||||
def test_generators_empty_aliases_and_options
|
||||
assert_equal({}, Rails::Configuration.new.generators.aliases)
|
||||
assert_equal({}, Rails::Configuration.new.generators.options)
|
||||
end
|
||||
|
||||
def test_generators_set_options
|
||||
config = Rails::Configuration.new
|
||||
config.generators.orm :datamapper
|
||||
config.generators.test_framework :rspec
|
||||
assert_equal({ :orm => :datamapper, :test_framework => :rspec }, config.generators.options)
|
||||
end
|
||||
|
||||
def test_generators_set_aliases
|
||||
config = Rails::Configuration.new
|
||||
config.generators.aliases :test_framework => "-w"
|
||||
assert_equal({ :test_framework => "-w" }, config.generators.aliases)
|
||||
end
|
||||
|
||||
def test_generators_with_block
|
||||
config = Rails::Configuration.new
|
||||
config.generators do |g|
|
||||
g.orm :datamapper
|
||||
g.test_framework :rspec
|
||||
end
|
||||
assert_equal({ :orm => :datamapper, :test_framework => :rspec }, config.generators.options)
|
||||
end
|
||||
end
|
||||
|
||||
class InitializerSetupI18nTests < Test::Unit::TestCase
|
||||
def test_no_config_locales_dir_present_should_return_empty_load_path
|
||||
File.stubs(:exist?).returns(false)
|
||||
|
|
Loading…
Reference in a new issue