Add config.generators.fallbacks.

This commit is contained in:
José Valim 2010-02-01 10:48:59 +01:00
parent 2092351652
commit a8c5d22c23
3 changed files with 15 additions and 2 deletions

View File

@ -88,11 +88,12 @@ module Rails
end end
class Generators #:nodoc: class Generators #:nodoc:
attr_accessor :aliases, :options, :colorize_logging attr_accessor :aliases, :options, :fallbacks, :colorize_logging
def initialize def initialize
@aliases = Hash.new { |h,k| h[k] = {} } @aliases = Hash.new { |h,k| h[k] = {} }
@options = Hash.new { |h,k| h[k] = {} } @options = Hash.new { |h,k| h[k] = {} }
@fallbacks = {}
@colorize_logging = true @colorize_logging = true
end end

View File

@ -67,6 +67,7 @@ module Rails
no_color! unless config.colorize_logging no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases aliases.deep_merge! config.aliases
options.deep_merge! config.options options.deep_merge! config.options
fallbacks.merge! config.fallbacks
end end
def self.aliases #:nodoc: def self.aliases #:nodoc:

View File

@ -30,6 +30,7 @@ module ApplicationTests
assert_equal(true, c.generators.colorize_logging) assert_equal(true, c.generators.colorize_logging)
assert_equal({}, c.generators.aliases) assert_equal({}, c.generators.aliases)
assert_equal({}, c.generators.options) assert_equal({}, c.generators.options)
assert_equal({}, c.generators.fallbacks)
end end
end end
@ -51,11 +52,20 @@ module ApplicationTests
end end
end end
test "generators aliases and options on initialization" do test "generators set rails fallbacks" do
with_config do |c|
c.generators.fallbacks[:shoulda] = :test_unit
expected = { :shoulda => :test_unit }
assert_equal expected, c.generators.fallbacks
end
end
test "generators aliases, options and fallbacks on initialization" do
add_to_config <<-RUBY add_to_config <<-RUBY
config.generators.rails :aliases => { :test_framework => "-w" } config.generators.rails :aliases => { :test_framework => "-w" }
config.generators.orm :datamapper config.generators.orm :datamapper
config.generators.test_framework :rspec config.generators.test_framework :rspec
config.generators.fallbacks[:shoulda] = :test_unit
RUBY RUBY
# Initialize the application # Initialize the application
@ -65,6 +75,7 @@ module ApplicationTests
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework] assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework] assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
assert_equal :test_unit, Rails::Generators.fallbacks[:shoulda]
end end
test "generators no color on initialization" do test "generators no color on initialization" do